Karsten Hopp ffaeff
To: vim_dev@googlegroups.com
Karsten Hopp ffaeff
Subject: Patch 7.3.060
Karsten Hopp ffaeff
Fcc: outbox
Karsten Hopp ffaeff
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp ffaeff
Mime-Version: 1.0
Karsten Hopp ffaeff
Content-Type: text/plain; charset=UTF-8
Karsten Hopp ffaeff
Content-Transfer-Encoding: 8bit
Karsten Hopp ffaeff
------------
Karsten Hopp ffaeff
Karsten Hopp ffaeff
Patch 7.3.060
Karsten Hopp ffaeff
Problem:    Netbeans: crash when socket is disconnected unexpectedly.
Karsten Hopp ffaeff
Solution:   Don't cleanup when a read fails, put a message in the queue and
Karsten Hopp ffaeff
	    disconnect later. (Xavier de Gaye)
Karsten Hopp ffaeff
Files:	    src/netbeans.c
Karsten Hopp ffaeff
Karsten Hopp ffaeff
Karsten Hopp ffaeff
*** ../vim-7.3.059/src/netbeans.c	2010-11-16 15:04:51.000000000 +0100
Karsten Hopp ffaeff
--- src/netbeans.c	2010-11-16 15:48:36.000000000 +0100
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 135,148 ****
Karsten Hopp ffaeff
  static int needupdate = 0;
Karsten Hopp ffaeff
  static int inAtomic = 0;
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
      static void
Karsten Hopp ffaeff
! netbeans_close(void)
Karsten Hopp ffaeff
  {
Karsten Hopp ffaeff
-     if (!NETBEANS_OPEN)
Karsten Hopp ffaeff
- 	return;
Karsten Hopp ffaeff
- 
Karsten Hopp ffaeff
-     netbeans_send_disconnect();
Karsten Hopp ffaeff
- 
Karsten Hopp ffaeff
  #ifdef FEAT_GUI_X11
Karsten Hopp ffaeff
      if (inputHandler != (XtInputId)NULL)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
--- 135,146 ----
Karsten Hopp ffaeff
  static int needupdate = 0;
Karsten Hopp ffaeff
  static int inAtomic = 0;
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
+ /*
Karsten Hopp ffaeff
+  * Close the socket and remove the input handlers.
Karsten Hopp ffaeff
+  */
Karsten Hopp ffaeff
      static void
Karsten Hopp ffaeff
! nb_close_socket(void)
Karsten Hopp ffaeff
  {
Karsten Hopp ffaeff
  #ifdef FEAT_GUI_X11
Karsten Hopp ffaeff
      if (inputHandler != (XtInputId)NULL)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 167,179 ****
Karsten Hopp ffaeff
  # endif
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
  #ifdef FEAT_BEVAL
Karsten Hopp ffaeff
      bevalServers &= ~BEVAL_NETBEANS;
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
-     sock_close(nbsock);
Karsten Hopp ffaeff
-     nbsock = -1;
Karsten Hopp ffaeff
- 
Karsten Hopp ffaeff
      needupdate = 0;
Karsten Hopp ffaeff
      inAtomic = 0;
Karsten Hopp ffaeff
      nb_free();
Karsten Hopp ffaeff
--- 165,191 ----
Karsten Hopp ffaeff
  # endif
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
+     sock_close(nbsock);
Karsten Hopp ffaeff
+     nbsock = -1;
Karsten Hopp ffaeff
+ }
Karsten Hopp ffaeff
+ 
Karsten Hopp ffaeff
+ /*
Karsten Hopp ffaeff
+  * Close the connection and cleanup.
Karsten Hopp ffaeff
+  * May be called when nb_close_socket() was called earlier.
Karsten Hopp ffaeff
+  */
Karsten Hopp ffaeff
+     static void
Karsten Hopp ffaeff
+ netbeans_close(void)
Karsten Hopp ffaeff
+ {
Karsten Hopp ffaeff
+     if (NETBEANS_OPEN)
Karsten Hopp ffaeff
+     {
Karsten Hopp ffaeff
+ 	netbeans_send_disconnect();
Karsten Hopp ffaeff
+ 	nb_close_socket();
Karsten Hopp ffaeff
+     }
Karsten Hopp ffaeff
+ 
Karsten Hopp ffaeff
  #ifdef FEAT_BEVAL
Karsten Hopp ffaeff
      bevalServers &= ~BEVAL_NETBEANS;
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
      needupdate = 0;
Karsten Hopp ffaeff
      inAtomic = 0;
Karsten Hopp ffaeff
      nb_free();
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 632,640 ****
Karsten Hopp ffaeff
      char_u	*p;
Karsten Hopp ffaeff
      queue_T	*node;
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
-     if (!NETBEANS_OPEN)
Karsten Hopp ffaeff
- 	return;
Karsten Hopp ffaeff
- 
Karsten Hopp ffaeff
      while (head.next != NULL && head.next != &head)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
  	node = head.next;
Karsten Hopp ffaeff
--- 644,649 ----
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 720,725 ****
Karsten Hopp ffaeff
--- 729,736 ----
Karsten Hopp ffaeff
  }
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
+ #define DETACH_MSG "DETACH\n"
Karsten Hopp ffaeff
+ 
Karsten Hopp ffaeff
      void
Karsten Hopp ffaeff
  netbeans_read()
Karsten Hopp ffaeff
  {
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 780,801 ****
Karsten Hopp ffaeff
  	    break;	/* did read everything that's available */
Karsten Hopp ffaeff
      }
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
      if (readlen <= 0)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
! 	/* read error or didn't read anything */
Karsten Hopp ffaeff
! 	netbeans_close();
Karsten Hopp ffaeff
! 	nbdebug(("messageFromNetbeans: Error in read() from socket\n"));
Karsten Hopp ffaeff
  	if (len < 0)
Karsten Hopp ffaeff
  	{
Karsten Hopp ffaeff
  	    nbdebug(("read from Netbeans socket\n"));
Karsten Hopp ffaeff
  	    PERROR(_("read from Netbeans socket"));
Karsten Hopp ffaeff
  	}
Karsten Hopp ffaeff
- 	return; /* don't try to parse it */
Karsten Hopp ffaeff
      }
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
  #if defined(NB_HAS_GUI) && defined(FEAT_GUI_GTK)
Karsten Hopp ffaeff
      if (NB_HAS_GUI && gtk_main_level() > 0)
Karsten Hopp ffaeff
!         gtk_main_quit();
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  }
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
--- 791,822 ----
Karsten Hopp ffaeff
  	    break;	/* did read everything that's available */
Karsten Hopp ffaeff
      }
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
+     /* Reading a socket disconnection (readlen == 0), or a socket error. */
Karsten Hopp ffaeff
      if (readlen <= 0)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
! 	/* Queue a "DETACH" netbeans message in the command queue in order to
Karsten Hopp ffaeff
! 	 * terminate the netbeans session later. Do not end the session here
Karsten Hopp ffaeff
! 	 * directly as we may be running in the context of a call to
Karsten Hopp ffaeff
! 	 * netbeans_parse_messages():
Karsten Hopp ffaeff
! 	 *	netbeans_parse_messages
Karsten Hopp ffaeff
! 	 *	    -> autocmd triggered while processing the netbeans cmd
Karsten Hopp ffaeff
! 	 *		-> ui_breakcheck
Karsten Hopp ffaeff
! 	 *		    -> gui event loop or select loop
Karsten Hopp ffaeff
! 	 *			-> netbeans_read()
Karsten Hopp ffaeff
! 	 */
Karsten Hopp ffaeff
! 	save((char_u *)DETACH_MSG, strlen(DETACH_MSG));
Karsten Hopp ffaeff
! 	nb_close_socket();
Karsten Hopp ffaeff
! 
Karsten Hopp ffaeff
  	if (len < 0)
Karsten Hopp ffaeff
  	{
Karsten Hopp ffaeff
  	    nbdebug(("read from Netbeans socket\n"));
Karsten Hopp ffaeff
  	    PERROR(_("read from Netbeans socket"));
Karsten Hopp ffaeff
  	}
Karsten Hopp ffaeff
      }
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
  #if defined(NB_HAS_GUI) && defined(FEAT_GUI_GTK)
Karsten Hopp ffaeff
      if (NB_HAS_GUI && gtk_main_level() > 0)
Karsten Hopp ffaeff
! 	gtk_main_quit();
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
  }
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 1164,1169 ****
Karsten Hopp ffaeff
--- 1185,1194 ----
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
      nbdebug(("REP %d: <none>\n", cmdno));
Karsten Hopp ffaeff
  
Karsten Hopp ffaeff
+     /* Avoid printing an annoying error message. */
Karsten Hopp ffaeff
+     if (!NETBEANS_OPEN)
Karsten Hopp ffaeff
+ 	return;
Karsten Hopp ffaeff
+ 
Karsten Hopp ffaeff
      sprintf(reply, "%d\n", cmdno);
Karsten Hopp ffaeff
      nb_send(reply, "nb_reply_nil");
Karsten Hopp ffaeff
  }
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 2753,2763 ****
Karsten Hopp ffaeff
  {
Karsten Hopp ffaeff
  #ifdef FEAT_GUI
Karsten Hopp ffaeff
  # if !defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK)  \
Karsten Hopp ffaeff
!                 && !defined(FEAT_GUI_W32)
Karsten Hopp ffaeff
      if (gui.in_use)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
!         EMSG(_("E838: netbeans is not supported with this GUI"));
Karsten Hopp ffaeff
!         return;
Karsten Hopp ffaeff
      }
Karsten Hopp ffaeff
  # endif
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
--- 2778,2788 ----
Karsten Hopp ffaeff
  {
Karsten Hopp ffaeff
  #ifdef FEAT_GUI
Karsten Hopp ffaeff
  # if !defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK)  \
Karsten Hopp ffaeff
! 		&& !defined(FEAT_GUI_W32)
Karsten Hopp ffaeff
      if (gui.in_use)
Karsten Hopp ffaeff
      {
Karsten Hopp ffaeff
! 	EMSG(_("E838: netbeans is not supported with this GUI"));
Karsten Hopp ffaeff
! 	return;
Karsten Hopp ffaeff
      }
Karsten Hopp ffaeff
  # endif
Karsten Hopp ffaeff
  #endif
Karsten Hopp ffaeff
*** ../vim-7.3.059/src/version.c	2010-11-16 15:04:51.000000000 +0100
Karsten Hopp ffaeff
--- src/version.c	2010-11-16 15:22:39.000000000 +0100
Karsten Hopp ffaeff
***************
Karsten Hopp ffaeff
*** 716,717 ****
Karsten Hopp ffaeff
--- 716,719 ----
Karsten Hopp ffaeff
  {   /* Add new patch number below this line */
Karsten Hopp ffaeff
+ /**/
Karsten Hopp ffaeff
+     60,
Karsten Hopp ffaeff
  /**/
Karsten Hopp ffaeff
Karsten Hopp ffaeff
-- 
Karsten Hopp ffaeff
   Another bucket of what can only be described as human ordure hits ARTHUR.
Karsten Hopp ffaeff
ARTHUR: ... Right!  (to the KNIGHTS) That settles it!
Karsten Hopp ffaeff
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp ffaeff
Karsten Hopp ffaeff
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp ffaeff
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp ffaeff
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp ffaeff
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///