aboutsummaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2002-06-07 04:44:27 +0000
committerEric S. Raymond <esr@thyrsus.com>2002-06-07 04:44:27 +0000
commit354fa788cda62c39386d4282b99348256958093e (patch)
tree9ac7b657bd3139f0134d9137ff3543877ff8b544 /socket.c
parent420635f35f6261d709bbfeed50d9d6daab205366 (diff)
downloadfetchmail-354fa788cda62c39386d4282b99348256958093e.tar.gz
fetchmail-354fa788cda62c39386d4282b99348256958093e.tar.bz2
fetchmail-354fa788cda62c39386d4282b99348256958093e.zip
Cygwin fixes.
svn path=/trunk/; revision=3635
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/socket.c b/socket.c
index 2d356ece..4c32898f 100644
--- a/socket.c
+++ b/socket.c
@@ -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 len)
int SockRead(int sock, char *buf, int len)
{
char *newline, *bp = buf;
- int n, n2;
+ int n;
#ifdef SSL_ENABLE
SSL *ssl;
#endif
@@ -608,46 +613,24 @@ int SockRead(int sock, char *buf, int len)
out of the loop now */
newline = bp;
}
- } else {
- if ((n = fm_peek(sock, bp, len)) <= 0)
- return(-1);
- if ((newline = memchr(bp, '\n', n)) != NULL)
- n = newline - bp + 1;
- if ((n = fm_read(sock, bp, n)) == -1)
- return(-1);
}
-#else
+ else
+#endif /* SSL_ENABLE */
+ {
#ifdef __BEOS__
- if ((n = fm_read(sock, bp, 1)) <= 0)
+ if ((n = fm_read(sock, bp, 1)) <= 0)
#else
- if ((n = fm_peek(sock, bp, len)) <= 0)
+ if ((n = fm_peek(sock, bp, len)) <= 0)
#endif
- return (-1);
- if ((newline = memchr(bp, '\n', n)) != NULL)
- n = newline - bp + 1;
+ return (-1);
+ if ((newline = memchr(bp, '\n', n)) != NULL)
+ n = newline - bp + 1;
#ifndef __BEOS__
- 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"));
+ if ((n = fm_read(sock, bp, n)) == -1)
return(-1);
- }
- }
-#endif /* __CYGWIN__ */
#endif /* __BEOS__ */
-#endif
+ }
bp += n;
len -= n;
} while
@@ -1015,6 +998,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.