public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch
@ 2002-04-29  5:39 Jason Tishler
  2002-05-24  9:46 ` [fetchmail]Cygwin " Eric S. Raymond
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Tishler @ 2002-04-29  5:39 UTC (permalink / raw)
  To: fetchmail-friends; +Cc: Cygwin

[-- Attachment #1: Type: text/plain, Size: 1134 bytes --]

Eric,

Attached is a patch (against fetchmail 5.9.11) that works around the
Microsoft Winsock recv/WSARecv(..., MSG_PEEK) problem that I originally
post to fetchmail-friends in:

    http://lists.ccil.org/pipermail/fetchmail-friends/2001-August/000906.html

This patch is essentially the same as the one that I posted in:

    http://www.cygwin.com/ml/cygwin/2001-08/msg00628.html

but cleaned up as follows:

    o Cygwin specific code is guarded by conditional compilation
    o log messages use report() instead of printf()
    o log messages respect the --silent/--verbose options

Would you consider accepting this patch into fetchmail CVS?  Note the
following:

    o Unfortunately, this problem cannot be fixed or worked around in
      the Cygwin DLL itself.
    o I have tested this patch under Red Hat Linux 7.1 without any ill
      effects.
    o I intend to become the Cygwin fetchmail (and procmail) maintainer
      and will be contributing pre-built fetchmail (and procmail)
      tarballs to the standard Cygwin distribution.

BTW, please CC me since I am not subscribed to the fetchmail-friends
list.

Thanks,
Jason

[-- Attachment #2: fetchmail.patch --]
[-- Type: text/plain, Size: 1087 bytes --]

--- socket.c.orig	Mon Apr  1 03:16:35 2002
+++ socket.c	Fri Apr 26 15:45:55 2002
@@ -536,7 +536,7 @@ int SockWrite(int sock, char *buf, int l
 int SockRead(int sock, char *buf, int len)
 {
     char *newline, *bp = buf;
-    int n;
+    int n, n2;
 #ifdef	SSL_ENABLE
     SSL *ssl;
 #endif
@@ -627,8 +627,25 @@ int SockRead(int sock, char *buf, int le
 	if ((newline = memchr(bp, '\n', n)) != NULL)
 	    n = newline - bp + 1;
 #ifndef __BEOS__
-	if ((n = fm_read(sock, bp, n)) == -1)
+	if ((n2 = fm_read(sock, bp, n)) == -1)
 	    return(-1);
+#ifdef __CYGWIN__
+	/*
+	 * Workaround Microsoft Winsock recv/WSARecv(..., MSG_PEEK) bug.
+	 * See http://sources.redhat.com/ml/cygwin/2001-08/msg00628.html
+	 * for more details.
+	 */
+	if (n2 != n) {
+	    int n3;
+	    if (outlevel >= O_VERBOSE)
+		report(stdout, GT_("Cygwin socket read retry\n"));
+	    n3 = fm_read(sock, bp + n2, n - n2);
+	    if (n3 == -1 || n2 + n3 != n) {
+		report(stderr, GT_("Cygwin socket read retry failed!\n"));
+		return(-1);
+	    }
+	}
+#endif /* __CYGWIN__ */
 #endif /* __BEOS__ */
 #endif
 	bp += n;


[-- Attachment #3: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [fetchmail]Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch
  2002-04-29  5:39 Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch Jason Tishler
@ 2002-05-24  9:46 ` Eric S. Raymond
  2002-05-24 10:05   ` Jason Tishler
  2002-05-28 14:11   ` Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch (Take 2) Jason Tishler
  0 siblings, 2 replies; 4+ messages in thread
From: Eric S. Raymond @ 2002-05-24  9:46 UTC (permalink / raw)
  To: fetchmail-friends, Cygwin; +Cc: jason

Jason Tishler <jason@tishler.net>:
> Attached is a patch (against fetchmail 5.9.11) that works around the
> Microsoft Winsock recv/WSARecv(..., MSG_PEEK) problem that I originally
> post to fetchmail-friends in:
> 
>     http://lists.ccil.org/pipermail/fetchmail-friends/2001-August/000906.html
> 
> This patch is essentially the same as the one that I posted in:
> 
>     http://www.cygwin.com/ml/cygwin/2001-08/msg00628.html
> 
> but cleaned up as follows:
> 
>     o Cygwin specific code is guarded by conditional compilation
>     o log messages use report() instead of printf()
>     o log messages respect the --silent/--verbose options
> 
> Would you consider accepting this patch into fetchmail CVS?

Taken, thanks.
-- 
		<a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [fetchmail]Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch
  2002-05-24  9:46 ` [fetchmail]Cygwin " Eric S. Raymond
@ 2002-05-24 10:05   ` Jason Tishler
  2002-05-28 14:11   ` Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch (Take 2) Jason Tishler
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Tishler @ 2002-05-24 10:05 UTC (permalink / raw)
  To: fetchmail-friends, Cygwin

Eric,

On Fri, May 24, 2002 at 03:29:41AM -0400, Eric S. Raymond wrote:
> Jason Tishler <jason@tishler.net>:
> > Would you consider accepting this patch into fetchmail CVS?
> 
> Taken, thanks.

You are welcome.  I appreciate your willingness to accommodate Cygwin.

Thanks,
Jason

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch (Take 2)
  2002-05-24  9:46 ` [fetchmail]Cygwin " Eric S. Raymond
  2002-05-24 10:05   ` Jason Tishler
@ 2002-05-28 14:11   ` Jason Tishler
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Tishler @ 2002-05-28 14:11 UTC (permalink / raw)
  To: fetchmail-friends, Cygwin

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

Eric,

On Fri, May 24, 2002 at 03:29:41AM -0400, Eric S. Raymond wrote:
> Jason Tishler <jason@tishler.net>:
> > Would you consider accepting this patch into fetchmail CVS?
> 
> Taken, thanks.

Attached is (two versions of) "take 2" of my patch that applies the
Winsock recv/WSARecv(..., MSG_PEEK) workaround to socket.c -- this time
to both the non-SSL *and* SSL #ifdef code sections.  The first patch,
socket.c-2.diff, assumes that my previous patch has been applied.
The second one, socket.c-3.diff, is against the original 5.9.11 source.
Please choose the one that is most convenient for you to use.

I apologize for the gyrations, but I didn't realize the need to patch
SockRead() for both the non-SSL and SSL cases.  If interested, see the
following Cygwin mailing list thread for the details:

    http://cygwin.com/ml/cygwin/2002-05/msg01554.html

Note that I have re-factored my patch to handle both cases in a way which
I think is less intrusive than my first attempt.  Would you consider
accepting this new version into fetchmail CVS?

Thanks,
Jason

[-- Attachment #2: socket.c-2.diff --]
[-- Type: text/plain, Size: 2658 bytes --]

--- ../fetchmail-5.9.11-1/socket.c	2002-05-16 15:14:28.000000000 -0400
+++ socket.c	2002-05-28 12:51:29.000000000 -0400
@@ -40,7 +40,7 @@
 #include "fetchmail.h"
 #include "i18n.h"
 
-/* Defines to allow BeOS to play nice... */
+/* Defines to allow BeOS and Cygwin to play nice... */
 #ifdef __BEOS__
 static char peeked;
 #define fm_close(a)  closesocket(a)
@@ -51,7 +51,12 @@ static char peeked;
 #define fm_close(a)  close(a)
 #define fm_write(a,b,c)  write(a,b,c)
 #define fm_peek(a,b,c)   recv(a,b,c, MSG_PEEK)
+#ifdef __CYGWIN__
+#define fm_read(a,b,c)   cygwin_read(a,b,c)
+static ssize_t cygwin_read(int sock, void *buf, size_t count);
+#else /* ! __CYGWIN__ */
 #define fm_read(a,b,c)   read(a,b,c)
+#endif /* __CYGWIN__ */
 #endif
 
 /* We need to define h_errno only if it is not already */
@@ -536,7 +541,7 @@ int SockWrite(int sock, char *buf, int l
 int SockRead(int sock, char *buf, int len)
 {
     char *newline, *bp = buf;
-    int n, n2;
+    int n;
 #ifdef	SSL_ENABLE
     SSL *ssl;
 #endif
@@ -627,25 +632,8 @@ int SockRead(int sock, char *buf, int le
 	if ((newline = memchr(bp, '\n', n)) != NULL)
 	    n = newline - bp + 1;
 #ifndef __BEOS__
-	if ((n2 = fm_read(sock, bp, n)) == -1)
+	if ((n = fm_read(sock, bp, n)) == -1)
 	    return(-1);
-#ifdef __CYGWIN__
-	/*
-	 * Workaround Microsoft Winsock recv/WSARecv(..., MSG_PEEK) bug.
-	 * See http://sources.redhat.com/ml/cygwin/2001-08/msg00628.html
-	 * for more details.
-	 */
-	if (n2 != n) {
-	    int n3;
-	    if (outlevel >= O_VERBOSE)
-		report(stdout, GT_("Cygwin socket read retry\n"));
-	    n3 = fm_read(sock, bp + n2, n - n2);
-	    if (n3 == -1 || n2 + n3 != n) {
-		report(stderr, GT_("Cygwin socket read retry failed!\n"));
-		return(-1);
-	    }
-	}
-#endif /* __CYGWIN__ */
 #endif /* __BEOS__ */
 #endif
 	bp += n;
@@ -1015,6 +1003,33 @@ int SockClose(int sock)
     return(fm_close(sock));	/* this is guarded */
 }
 
+#ifdef __CYGWIN__
+/*
+ * Workaround Microsoft Winsock recv/WSARecv(..., MSG_PEEK) bug.
+ * See http://sources.redhat.com/ml/cygwin/2001-08/msg00628.html
+ * for more details.
+ */
+static ssize_t cygwin_read(int sock, void *buf, size_t count)
+{
+    char *bp = buf;
+    int n = 0;
+
+    if ((n = read(sock, bp, count)) == -1)
+	return(-1);
+
+    if (n != count) {
+	int n2 = 0;
+	if (outlevel >= O_VERBOSE)
+	    report(stdout, GT_("Cygwin socket read retry\n"));
+	n2 = read(sock, bp + n, count - n);
+	if (n2 == -1 || n + n2 != count) {
+	    report(stderr, GT_("Cygwin socket read retry failed!\n"));
+	    return(-1);
+	}
+    }
+}
+#endif /* __CYGWIN__ */
+
 #ifdef MAIN
 /*
  * Use the chargen service to test input buffering directly.

[-- Attachment #3: socket.c-3.diff --]
[-- Type: text/plain, Size: 1636 bytes --]

--- socket.c.orig	2002-05-28 12:55:36.000000000 -0400
+++ socket.c	2002-05-28 12:51:29.000000000 -0400
@@ -40,7 +40,7 @@
 #include "fetchmail.h"
 #include "i18n.h"
 
-/* Defines to allow BeOS to play nice... */
+/* Defines to allow BeOS and Cygwin to play nice... */
 #ifdef __BEOS__
 static char peeked;
 #define fm_close(a)  closesocket(a)
@@ -51,7 +51,12 @@ static char peeked;
 #define fm_close(a)  close(a)
 #define fm_write(a,b,c)  write(a,b,c)
 #define fm_peek(a,b,c)   recv(a,b,c, MSG_PEEK)
+#ifdef __CYGWIN__
+#define fm_read(a,b,c)   cygwin_read(a,b,c)
+static ssize_t cygwin_read(int sock, void *buf, size_t count);
+#else /* ! __CYGWIN__ */
 #define fm_read(a,b,c)   read(a,b,c)
+#endif /* __CYGWIN__ */
 #endif
 
 /* We need to define h_errno only if it is not already */
@@ -998,6 +1003,33 @@ int SockClose(int sock)
     return(fm_close(sock));	/* this is guarded */
 }
 
+#ifdef __CYGWIN__
+/*
+ * Workaround Microsoft Winsock recv/WSARecv(..., MSG_PEEK) bug.
+ * See http://sources.redhat.com/ml/cygwin/2001-08/msg00628.html
+ * for more details.
+ */
+static ssize_t cygwin_read(int sock, void *buf, size_t count)
+{
+    char *bp = buf;
+    int n = 0;
+
+    if ((n = read(sock, bp, count)) == -1)
+	return(-1);
+
+    if (n != count) {
+	int n2 = 0;
+	if (outlevel >= O_VERBOSE)
+	    report(stdout, GT_("Cygwin socket read retry\n"));
+	n2 = read(sock, bp + n, count - n);
+	if (n2 == -1 || n + n2 != count) {
+	    report(stderr, GT_("Cygwin socket read retry failed!\n"));
+	    return(-1);
+	}
+    }
+}
+#endif /* __CYGWIN__ */
+
 #ifdef MAIN
 /*
  * Use the chargen service to test input buffering directly.


[-- Attachment #4: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-05-28 17:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-29  5:39 Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch Jason Tishler
2002-05-24  9:46 ` [fetchmail]Cygwin " Eric S. Raymond
2002-05-24 10:05   ` Jason Tishler
2002-05-28 14:11   ` Cygwin Winsock recv/WSARecv(..., MSG_PEEK) patch (Take 2) Jason Tishler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).