--------------------- PatchSet 4940 Date: 2007/06/26 08:54:43 Author: adri Branch: squid3_adri Tag: (none) Log: Flesh out more of the comm_writev() routine. it'll work if an entire iovec entry is written, it doesn't yet handle partially written iovecs. Its enough to do some testing with. Members: src/comm.cc:1.74.6.2->1.74.6.3 Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.74.6.2 retrieving revision 1.74.6.3 diff -u -r1.74.6.2 -r1.74.6.3 --- squid3/src/comm.cc 26 Jun 2007 07:08:40 -0000 1.74.6.2 +++ squid3/src/comm.cc 26 Jun 2007 08:54:43 -0000 1.74.6.3 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.74.6.2 2007/06/26 07:08:40 adri Exp $ + * $Id: comm.cc,v 1.74.6.3 2007/06/26 08:54:43 adri Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1849,6 +1849,8 @@ comm_io_callback_t *state = (comm_io_callback_t *) data; int len = 0; int nleft; + int i; + int cursize; assert (state == COMMIO_FD_WRITECB(fd)); @@ -1878,7 +1880,7 @@ xfree(state->wv.iov); } else if (ignoreErrno(errno)) { debugs(50, 10, "commHandleWrite: FD " << fd << ": write failure: " << xstrerror() << "."); - commSetSelect(fd, COMM_SELECT_WRITE, commHandleWrite, state, 0); + commSetSelect(fd, COMM_SELECT_WRITE, commHandleWriteV, state, 0); } else { debugs(50, 2, "commHandleWrite: FD " << fd << ": write failure: " << xstrerror() << "."); commio_complete_callback(fd, COMMIO_FD_WRITECB(fd), nleft ? COMM_ERROR : COMM_OK, errno); @@ -1905,6 +1907,29 @@ * to find which iovecs were fully written, then possibly tweak the * head iovec to point part-way into the buffer. */ + + /* + * Loop through each iovec looking for ones that we've definitely + * been able to write + */ + cursize = len; + for (i = 0; i < state->wv.iovcnt ; i++) { + if ( (cursize - state->wv.iov[i].iov_len) < 0) + break; + cursize -= state->wv.iov[i].iov_len; + } + + /* For now, since I'm cheap, assume we've written all of an iovec, we'll + * do the partial stuff later */ + assert(cursize == 0); + + /* Shift the iovec's down and update iovcnt */ + memmove(&state->wv.iov[0], &state->wv.iov[i], sizeof(struct iovec) * (state->wv.iovcnt - i)); + state->wv.iovcnt -= i; + assert(state->wv.iovcnt > 0); + + /* Register for another trip through the loop */ + commSetSelect(fd, COMM_SELECT_WRITE, commHandleWriteV, state, 0); } /* Write to FD. */