--------------------- PatchSet 5317 Date: 2002/10/09 08:09:26 Author: adri Branch: commloops Tag: (none) Log: Convert to new IO framework. Members: src/wais.c:1.8.22.1->1.8.22.2 Index: squid/src/wais.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wais.c,v retrieving revision 1.8.22.1 retrieving revision 1.8.22.2 diff -u -r1.8.22.1 -r1.8.22.2 --- squid/src/wais.c 13 Sep 2002 05:38:35 -0000 1.8.22.1 +++ squid/src/wais.c 9 Oct 2002 08:09:26 -0000 1.8.22.2 @@ -1,6 +1,6 @@ /* - * $Id: wais.c,v 1.8.22.1 2002/09/13 05:38:35 adri Exp $ + * $Id: wais.c,v 1.8.22.2 2002/10/09 08:09:26 adri Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -43,11 +43,12 @@ char url[MAX_URL]; request_t *request; FwdState *fwd; + char buf[BUFSIZ]; } WaisStateData; static PF waisStateFree; static PF waisTimeout; -static PF waisReadReply; +static IOCB waisReadReply; static CWCB waisSendComplete; static PF waisSendRequest; @@ -81,12 +82,10 @@ /* This will be called when data is ready to be read from fd. Read until * error or connection closed. */ static void -waisReadReply(int fd, void *data) +waisReadReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data) { WaisStateData *waisState = data; - LOCAL_ARRAY(char, buf, 4096); StoreEntry *entry = waisState->entry; - int len; int clen; int bin; size_t read_sz; @@ -98,36 +97,32 @@ return; } errno = 0; - read_sz = 4096; -#if DELAY_POOLS - read_sz = delayBytesWanted(delay_id, 1, read_sz); -#endif - statCounter.syscalls.sock.reads++; - len = FD_READ_METHOD(fd, buf, read_sz); - if (len > 0) { - fd_bytes(fd, len, FD_READ); + read_sz = BUFSIZ; + if (flag == COMM_OK && len > 0) { #if DELAY_POOLS delayBytesIn(delay_id, len); #endif kb_incr(&statCounter.server.all.kbytes_in, len); kb_incr(&statCounter.server.other.kbytes_in, len); } - debug(24, 5) ("waisReadReply: FD %d read len:%d\n", fd, len); - if (len > 0) { +#if DELAY_POOLS + read_sz = delayBytesWanted(delay_id, 1, read_sz); +#endif + debug(24, 5) ("waisReadReply: FD %d read len:%d\n", fd, (int)len); + if (flag == COMM_OK && len > 0) { commSetTimeout(fd, Config.Timeout.read, NULL, NULL); IOStats.Wais.reads++; for (clen = len - 1, bin = 0; clen; bin++) clen >>= 1; IOStats.Wais.read_hist[bin]++; } - if (len < 0) { + if (flag != COMM_OK || len < 0) { debug(50, 1) ("waisReadReply: FD %d: read failure: %s.\n", fd, xstrerror()); - if (ignoreErrno(errno)) { + if (ignoreErrno(xerrno)) { /* reinstall handlers */ /* XXX This may loop forever */ - commSetSelect(fd, COMM_SELECT_READ, - waisReadReply, waisState, 0); + comm_read(fd, waisState->buf, read_sz, waisReadReply, waisState); } else { ErrorState *err; EBIT_CLR(entry->flags, ENTRY_CACHABLE); @@ -138,24 +133,21 @@ errorAppendEntry(entry, err); comm_close(fd); } - } else if (len == 0 && entry->mem_obj->inmem_hi == 0) { + } else if (flag == COMM_OK && len == 0 && entry->mem_obj->inmem_hi == 0) { ErrorState *err; err = errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_SERVICE_UNAVAILABLE); err->xerrno = errno; err->request = requestLink(waisState->request); errorAppendEntry(entry, err); comm_close(fd); - } else if (len == 0) { + } else if (flag == COMM_OK && len == 0) { /* Connection closed; retrieval done. */ entry->expires = squid_curtime; fwdComplete(waisState->fwd); comm_close(fd); } else { storeAppend(entry, buf, len); - commSetSelect(fd, - COMM_SELECT_READ, - waisReadReply, - waisState, 0); + comm_read(fd, waisState->buf, read_sz, waisReadReply, waisState); } } @@ -184,10 +176,7 @@ comm_close(fd); } else { /* Schedule read reply. */ - commSetSelect(fd, - COMM_SELECT_READ, - waisReadReply, - waisState, 0); + comm_read(fd, waisState->buf, BUFSIZ, waisReadReply, waisState); commSetDefer(fd, fwdCheckDeferRead, entry); } }