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