From 5e5aa7075cefa4a53bcc10359619a366ad712189 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 31 Oct 1996 08:46:37 +0000 Subject: STEP 9: Eliminate the static buffer in the socket library. svn path=/trunk/; revision=453 --- socket.c | 49 +------------------------------------------------ 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/socket.c b/socket.c index d4dde009..9461eee8 100644 --- a/socket.c +++ b/socket.c @@ -93,53 +93,6 @@ FILE *sockfp; return wrlen; } -static int sbuflen = 0; - -static int SockInternalRead (socket,buf,len) -int socket; -char *buf; -int len; -{ - static char sbuf [INTERNAL_BUFSIZE]; - static char *bp; - - if (sbuflen <= 0) { - /* buffer is empty; refresh. */ - if ((sbuflen = read(socket,sbuf,INTERNAL_BUFSIZE)) < 0) { - if (errno == EINTR) - return -1; - perror("SockInternalRead: read"); - exit(9); - } - else - bp = sbuf; - } - else - ; /* already some data in the buffer */ - - /* can't get more than we have right now. */ - /* XXX -- should probably try to load any unused part of sbuf - so that as much of 'len' as possible can be satisfied */ - if (len > sbuflen) - len = sbuflen; - else - ; /* wants no more than we already have */ - - /* transfer to caller's buffer */ - if (len == 1) { - /* special case: if caller only wants one character, it probably - costs a lot more to call bcopy than to do it ourselves. */ - *buf = *(bp++); - sbuflen--; - } - else { - bcopy(bp,buf,len); - sbuflen -= len; - bp += len; - } - return(len); -} - int SockGets(buf, len, sockfp) char *buf; int len; @@ -149,7 +102,7 @@ FILE *sockfp; while (--len) { - if (SockInternalRead(fileno(sockfp), buf, 1) != 1) + if (read(fileno(sockfp), buf, 1) != 1) return -1; else rdlen++; -- cgit v1.2.3