From: Fabian Keil <fk@fabiankeil.de>
Date: Tue, 1 Jan 2013 22:11:08 +0000 (+0000)
Subject: Do not try to drain a socket when there is no data waiting
X-Git-Tag: v_3_0_20~107
X-Git-Url: http://www.privoxy.org/gitweb/@default-cgi@/faq/%22https:/%22javascript:back()/@default-cgi@edit-actions-add-url-form?a=commitdiff_plain;h=f1a1b6181f2803a8e72edf8e262e8817c7519fa4;p=privoxy.git

Do not try to drain a socket when there is no data waiting

... 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.
---

diff --git a/jbsockets.c b/jbsockets.c
index c16e75f2..d650dba1 100644
--- a/jbsockets.c
+++ b/jbsockets.c
@@ -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)
          {