Do not try to drain a socket when there is no data waiting
authorFabian Keil <fk@fabiankeil.de>
Tue, 1 Jan 2013 22:11:08 +0000 (22:11 +0000)
committerFabian Keil <fk@fabiankeil.de>
Tue, 1 Jan 2013 22:11:08 +0000 (22:11 +0000)
... at the time drain_and_close_socket() is called.

As Lee noticed it causes problems on Windows, most likely because
read_socket() is blocking which isn't even wrong and could also
happen on other platforms.

jbsockets.c

index c16e75f..d650dba 100644 (file)
@@ -1,4 +1,4 @@
-const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.118 2012/10/21 12:44:58 fabiankeil Exp $";
+const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.119 2012/10/23 10:17:36 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jbsockets.c,v $
@@ -740,6 +740,15 @@ void drain_and_close_socket(jb_socket fd)
       {
          char drainage[500];
 
+         if (!data_is_available(fd, 0))
+         {
+            /*
+             * If there is no data available right now, don't try
+             * to drain the socket as read_socket() could block.
+             */
+            break;
+         }
+
          bytes_drained = read_socket(fd, drainage, sizeof(drainage));
          if (bytes_drained < 0)
          {