diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-10-31 06:29:49 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-10-31 06:29:49 +0000 |
commit | a2278043c64feb80565c1a6bf6456c687f5a5923 (patch) | |
tree | e3d0624b23dd944f88fefb3e2de4b2f0d8359515 /socket.c | |
parent | b3c486c6c25027081cdc4015cd7b2e5d6f05ab8d (diff) | |
download | fetchmail-a2278043c64feb80565c1a6bf6456c687f5a5923.tar.gz fetchmail-a2278043c64feb80565c1a6bf6456c687f5a5923.tar.bz2 fetchmail-a2278043c64feb80565c1a6bf6456c687f5a5923.zip |
STEP 3: File pointer arguments in SockGets()/SockPuts().
svn path=/trunk/; revision=446
Diffstat (limited to 'socket.c')
-rw-r--r-- | socket.c | 73 |
1 files changed, 7 insertions, 66 deletions
@@ -77,15 +77,15 @@ int clientPort; return sock; } -int SockPuts(socket,buf) -int socket; +int SockPuts(buf, sockfp) char *buf; +FILE *sockfp; { int rc; - if ((rc = SockWrite(socket, buf, strlen(buf))) != 0) + if ((rc = SockWrite(fileno(sockfp), buf, strlen(buf))) != 0) return rc; - return SockWrite(socket, "\r\n", 2); + return SockWrite(fileno(sockfp), "\r\n", 2); } int SockWrite(socket,buf,len) @@ -172,16 +172,16 @@ int len; return 0; } -int SockGets(socket,buf,len) -int socket; +int SockGets(buf, len, sockfp) char *buf; int len; +FILE *sockfp; { int rdlen = 0; while (--len) { - if (SockInternalRead(socket, buf, 1) != 1) + if (SockInternalRead(fileno(sockfp), buf, 1) != 1) return -1; else rdlen++; @@ -194,65 +194,6 @@ int len; return rdlen; } -/* SockDataWaiting: Return a non-zero value if this socket is waiting - for data. */ -int SockDataWaiting(int socket) -{ - int flags; - char sbuf[INTERNAL_BUFSIZE]; - int n; - flags = fcntl(socket,F_GETFL,0); - - /* set it to non-block */ - if (fcntl(socket,F_SETFL,flags | O_NONBLOCK) == -1) - return -1; - - n = recv(socket,sbuf,INTERNAL_BUFSIZE,MSG_PEEK); - - /* reset it to block (or, whatever it was). */ - fcntl(socket,F_SETFL,flags); - - if (n == -1) - { - /* No data to read. */ - if (errno == EWOULDBLOCK) - return(0); - else - return(-1); - } - else - return(n); -} - - -/* SockClearHeader: call this procedure in order to kill off any - forthcoming Header info from the socket that we no longer want. - */ -int SockClearHeader(socket) -int socket; -{ - char *bufp; - static char sbuf[INTERNAL_BUFSIZE]; - int res; - - if ((res = SockDataWaiting(socket)) <= 0) - return res; - - while (1) - { - if (SockGets(socket,sbuf,INTERNAL_BUFSIZE) < 0) - return 0; - bufp = sbuf; - if (*bufp == '.') { - bufp++; - if (*bufp == 0) - break; - } - } - sbuflen = 0; - return 0; -} - #if defined(HAVE_STDARG_H) int SockPrintf(int socket, char* format, ...) { |