--------------------- PatchSet 5235 Date: 2002/10/05 11:14:26 Author: rbcollins Branch: commloops Tag: (none) Log: tweak/update comm_fill to comm_fill_immediate Members: src/comm.c:1.21.4.18->1.21.4.19 src/comm.h:1.1.2.1->1.1.2.2 Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.21.4.18 retrieving revision 1.21.4.19 diff -u -r1.21.4.18 -r1.21.4.19 --- squid/src/comm.c 5 Oct 2002 10:42:28 -0000 1.21.4.18 +++ squid/src/comm.c 5 Oct 2002 11:14:26 -0000 1.21.4.19 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.21.4.18 2002/10/05 10:42:28 adri Exp $ + * $Id: comm.c,v 1.21.4.19 2002/10/05 11:14:26 rbcollins Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -92,8 +92,9 @@ IOACB *handler; void *handler_data; } accept; - struct { - StoreIOBuffer sb; + struct CommFiller { + StoreIOBuffer requestedData; + size_t amountDone; IOFCB *handler; void *handler_data; } fill; @@ -225,8 +226,7 @@ } static void -comm_add_fill_callback(int fd, StoreIOBuffer sb, size_t retval, comm_err_t errcode, int xerrno, - IOFCB *callback, void *callback_data) +comm_add_fill_callback(int fd, size_t retval, comm_err_t errcode, int xerrno) { CommCallbackData *cio; @@ -239,19 +239,22 @@ cio->fd = fd; cio->xerrno = xerrno; cio->errcode = errcode; - cio->c.f_callback = callback; - cio->callback_data = callback_data; + cio->c.f_callback = fdc_table[fd].fill.handler; + cio->callback_data = fdc_table[fd].fill.handler_data; cio->seqnum = CommCallbackSeqnum; cio->type = COMM_CB_FILL; - cio->retval = retval; - cio->sb = sb; + /* retval not used */ + cio->retval = -1; + cio->sb = fdc_table[fd].fill.requestedData; + cio->sb.length = retval; + /* Clear out fd state */ + fdc_table[fd].fill.handler = fdc_table[fd].fill.handler_data = NULL; /* Add it to the end of the list */ dlinkAddTail(cio, &(cio->h_node), &CommCallbackList); /* and add it to the end of the fd list */ dlinkAddTail(cio, &(cio->fd_node), &(fdc_table[fd].CommCallbackList)); - } @@ -273,8 +276,9 @@ cio->xerrno, cio->callback_data); break; case COMM_CB_FILL: - cio->c.f_callback(cio->fd, cio->sb, cio->retval, cio->errcode, + cio->c.f_callback(cio->fd, cio->sb, cio->errcode, cio->xerrno, cio->callback_data); + break; default: fatal("unknown comm io callback type!"); break; @@ -396,49 +400,43 @@ #endif } - static void comm_fill_read(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data) { - StoreIOBuffer sb; + /* TODO use a reference to the table entry, or use C++ :] */ + StoreIOBuffer *sb; + struct CommFiller *fill; assert(fdc_table[fd].active == 1); - - sb = fdc_table[fd].fill.sb; if (flag != COMM_OK) { /* Error! */ - comm_add_fill_callback(fd, sb, -1, flag, xerrno, fdc_table[fd].fill.handler, - fdc_table[fd].fill.handler_data); - fdc_table[fd].fill.handler = fdc_table[fd].fill.handler_data = NULL; + comm_add_fill_callback(fd, -1, flag, xerrno); return; } /* flag is COMM_OK */ /* We handle EOFs as read lengths of 0! Its eww, but its consistent */ - sb.offset += len; - assert(sb.offset < sb.length); - comm_add_fill_callback(fd, sb, len, COMM_OK, 0, fdc_table[fd].fill.handler, - fdc_table[fd].fill.handler_data); - fdc_table[fd].fill.handler = fdc_table[fd].fill.handler_data = NULL; + fill = &fdc_table[fd].fill; + fill->amountDone += len; + sb = &fdc_table[fd].fill.requestedData; + assert(fill->amountDone <= sb->length); + comm_add_fill_callback(fd, fill->amountDone, COMM_OK, 0); } - /* * Try filling a StoreIOBuffer with some data, and call a callback when successful */ void -comm_fill(int fd, StoreIOBuffer sb, IOFCB *callback, void *data) +comm_fill_immediate(int fd, StoreIOBuffer sb, IOFCB *callback, void *data) { assert(fdc_table[fd].fill.handler == NULL); - /* If we have data, schedule a callback immediately */ - if (sb.offset > 0) { - comm_add_fill_callback(fd, sb, sb.offset, COMM_OK, 0, callback, data); - return; - } + /* prevent confusion */ + assert (sb.offset == 0); /* If we don't have any data, record details and schedule a read */ fdc_table[fd].fill.handler = callback; fdc_table[fd].fill.handler_data = data; - fdc_table[fd].fill.sb = sb; + fdc_table[fd].fill.requestedData = sb; + fdc_table[fd].fill.amountDone = 0; comm_read(fd, sb.data, sb.length, comm_fill_read, NULL); } Index: squid/src/comm.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/comm.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/comm.h 4 Oct 2002 12:43:22 -0000 1.1.2.1 +++ squid/src/comm.h 5 Oct 2002 11:14:26 -0000 1.1.2.2 @@ -2,9 +2,8 @@ #define __COMM_H__ -typedef void IOFCB(int fd, StoreIOBuffer sb, size_t readlen, comm_err_t flag, int xerrno, void *data); -extern void comm_fill(int fd, StoreIOBuffer sb, IOFCB *callback, void *data); - - +typedef void IOFCB(int fd, StoreIOBuffer recievedData, comm_err_t flag, int xerrno, void *data); +/* fill sb with up to length data from fd */ +extern void comm_fill_immediate(int fd, StoreIOBuffer sb, IOFCB *callback, void *data); #endif