--------------------- PatchSet 7100 Date: 2005/10/12 07:39:16 Author: adri Branch: tidyup_deferred_reads Tag: (none) Log: Bring the WAIS code into the kicked IO framework Members: src/wais.c:1.8.70.1->1.8.70.2 Index: squid/src/wais.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/wais.c,v retrieving revision 1.8.70.1 retrieving revision 1.8.70.2 diff -u -r1.8.70.1 -r1.8.70.2 --- squid/src/wais.c 27 Sep 2005 04:57:14 -0000 1.8.70.1 +++ squid/src/wais.c 12 Oct 2005 07:39:16 -0000 1.8.70.2 @@ -1,6 +1,6 @@ /* - * $Id: wais.c,v 1.8.70.1 2005/09/27 04:57:14 adri Exp $ + * $Id: wais.c,v 1.8.70.2 2005/10/12 07:39:16 adri Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -43,6 +43,8 @@ char url[MAX_URL]; request_t *request; FwdState *fwd; + int pending_read; + store_kick_type_t pending_kick; } WaisStateData; static PF waisStateFree; @@ -76,6 +78,45 @@ comm_close(fd); } + +static void +waisScheduleRead(WaisStateData *waisState) +{ + waisState->pending_read = 1; + commSetSelect(waisState->fd, COMM_SELECT_READ, waisReadReply, waisState, 0); +} + +static void +waisClearRead(WaisStateData *waisState) +{ + waisState->pending_read = 0; + commSetSelect(waisState->fd, COMM_SELECT_READ, NULL, NULL, 0); +} + +static void +waisReadKick(StoreEntry *e, void *data, store_kick_type_t type) +{ + WaisStateData *waisState = data; + + waisState->pending_kick = type; + if (type == STKICK_RUN || type == STKICK_FETCH) { + waisScheduleRead(data); + } else if (type == STKICK_WAIT) { + waisClearRead(data); + } else { + fatal("waisReadKick: unknown kick type!\n"); + } +} + +static void +waisMaybeScheduleRead(WaisStateData *waisState) +{ + if (waisState->pending_kick == STKICK_RUN || + waisState->pending_kick == STKICK_FETCH) { + waisScheduleRead(waisState); + } +} + /* This will be called when data is ready to be read from fd. Read until * error or connection closed. */ static void @@ -95,6 +136,7 @@ comm_close(fd); return; } + waisState->pending_read = 0; errno = 0; read_sz = 4096; #if DELAY_POOLS @@ -124,8 +166,7 @@ if (ignoreErrno(errno)) { /* reinstall handlers */ /* XXX This may loop forever */ - commSetSelect(fd, COMM_SELECT_READ, - waisReadReply, waisState, 0); + waisScheduleRead(waisState); } else { ErrorState *err; err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR); @@ -143,10 +184,7 @@ comm_close(fd); } else { storeAppend(entry, buf, len); - commSetSelect(fd, - COMM_SELECT_READ, - waisReadReply, - waisState, 0); + waisMaybeScheduleRead(waisState); } } @@ -174,11 +212,7 @@ comm_close(fd); } else { /* Schedule read reply. */ - commSetSelect(fd, - COMM_SELECT_READ, - waisReadReply, - waisState, 0); - commSetDefer(fd, fwdCheckDeferRead, entry); + waisScheduleRead(waisState); } } @@ -225,6 +259,9 @@ waisState->request_hdr = &request->header; waisState->fd = fd; waisState->entry = entry; + waisState->pending_kick = STKICK_RUN; + waisState->pending_read = 0; + storeServerSetCallback(fwd->entry, waisReadKick, waisState); xstrncpy(waisState->url, url, MAX_URL); waisState->request = requestLink(request); waisState->fwd = fwd;