--------------------- PatchSet 5213 Date: 2002/10/04 08:25:03 Author: adri Branch: commloops Tag: (none) Log: Move over the ftp read stuff (control and data) to the new comm_read routine. Currently, writes seem to require the clientBody* magic which I haven't converted over. Once I've converted over client_side.c to use comm_read, I'll revisit this. It _seems_ to work. I'm not sure why the memset's were in there.. Members: src/comm.c:1.21.4.13->1.21.4.14 src/ftp.c:1.20.10.5->1.20.10.6 Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.21.4.13 retrieving revision 1.21.4.14 diff -u -r1.21.4.13 -r1.21.4.14 --- squid/src/comm.c 3 Oct 2002 12:36:39 -0000 1.21.4.13 +++ squid/src/comm.c 4 Oct 2002 08:25:03 -0000 1.21.4.14 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.21.4.13 2002/10/03 12:36:39 adri Exp $ + * $Id: comm.c,v 1.21.4.14 2002/10/04 08:25:03 adri Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -119,17 +119,17 @@ }; typedef struct _CommCallbackData CommCallbackData; -struct _fdd_t { +struct _fd_debug_t { char *close_file; int close_line; }; -typedef struct _fdd_t fdd_t; +typedef struct _fd_debug_t fd_debug_t; static MemPool *comm_write_pool = NULL; static MemPool *conn_close_pool = NULL; static MemPool *comm_callback_pool = NULL; -static fdc_t *fdc_table = NULL; -static fdd_t *fd_debug_table = NULL; +fdc_t *fdc_table = NULL; +fd_debug_t *fdd_table = NULL; dlink_list CommCallbackList; static int CommCallbackSeqnum = 1; @@ -480,8 +480,8 @@ /* update fdstat */ debug(5, 5) ("comm_open: FD %d is a new socket\n", new_socket); fd_open(new_socket, FD_SOCKET, note); - fd_debug_table[new_socket].close_file = NULL; - fd_debug_table[new_socket].close_line = NULL; + fdd_table[new_socket].close_file = NULL; + fdd_table[new_socket].close_line = NULL; assert(fdc_table[new_socket].active == 0); fdc_table[new_socket].active = 1; F = &fd_table[new_socket]; @@ -828,8 +828,8 @@ commSetCloseOnExec(sock); /* fdstat update */ fd_open(sock, FD_SOCKET, "HTTP Request"); - fd_debug_table[sock].close_file = NULL; - fd_debug_table[sock].close_line = NULL; + fdd_table[sock].close_file = NULL; + fdd_table[sock].close_line = NULL; fdc_table[sock].active = 1; F = &fd_table[sock]; xstrncpy(F->ipaddr, inet_ntoa(P.sin_addr), 16); @@ -928,8 +928,8 @@ assert(fd >= 0); assert(fd < Squid_MaxFD); F = &fd_table[fd]; - fd_debug_table[fd].close_file = file; - fd_debug_table[fd].close_line = line; + fdd_table[fd].close_file = file; + fdd_table[fd].close_line = line; if (F->flags.closing) return; @@ -1149,7 +1149,7 @@ comm_init(void) { fd_table = xcalloc(Squid_MaxFD, sizeof(fde)); - fd_debug_table = xcalloc(Squid_MaxFD, sizeof(fdd_t)); + fdd_table = xcalloc(Squid_MaxFD, sizeof(fd_debug_t)); fdc_table = xcalloc(Squid_MaxFD, sizeof(fdc_t)); /* XXX account fd_table */ /* Keep a few file descriptors free so that we don't run out of FD's Index: squid/src/ftp.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ftp.c,v retrieving revision 1.20.10.5 retrieving revision 1.20.10.6 diff -u -r1.20.10.5 -r1.20.10.6 --- squid/src/ftp.c 3 Oct 2002 12:39:00 -0000 1.20.10.5 +++ squid/src/ftp.c 4 Oct 2002 08:25:03 -0000 1.20.10.6 @@ -1,6 +1,6 @@ /* - * $Id: ftp.c,v 1.20.10.5 2002/10/03 12:39:00 adri Exp $ + * $Id: ftp.c,v 1.20.10.6 2002/10/04 08:25:03 adri Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -145,12 +145,12 @@ /* Local functions */ static CNCB ftpPasvCallback; -static PF ftpDataRead; +static IOCB ftpDataRead; static PF ftpDataWrite; static CWCB ftpDataWriteCallback; static PF ftpStateFree; static PF ftpTimeout; -static PF ftpReadControlReply; +static IOCB ftpReadControlReply; static CWCB ftpWriteCommandCallback; static void ftpLoginParser(const char *, FtpStateData *, int escaped); static wordlist *ftpParseControlReply(char *, size_t, int *, int *); @@ -870,11 +870,11 @@ ftpScheduleReadControlReply(ftpState, 1); } + static void -ftpDataRead(int fd, void *data) +ftpDataRead(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data) { FtpStateData *ftpState = data; - int len; int j; int bin; StoreEntry *entry = ftpState->entry; @@ -888,16 +888,8 @@ comm_close(ftpState->ctrl.fd); return; } - errno = 0; - read_sz = ftpState->data.size - ftpState->data.offset; -#if DELAY_POOLS - read_sz = delayBytesWanted(delay_id, 1, read_sz); -#endif - memset(ftpState->data.buf + ftpState->data.offset, '\0', read_sz); - statCounter.syscalls.sock.reads++; - len = FD_READ_METHOD(fd, ftpState->data.buf + ftpState->data.offset, read_sz); - if (len > 0) { - fd_bytes(fd, len, FD_READ); + + if (flag == COMM_OK && len > 0) { #if DELAY_POOLS delayBytesIn(delay_id, len); #endif @@ -905,8 +897,8 @@ kb_incr(&statCounter.server.ftp.kbytes_in, len); ftpState->data.offset += len; } - debug(9, 5) ("ftpDataRead: FD %d, Read %d bytes\n", fd, len); - if (len > 0) { + debug(9, 5) ("ftpDataRead: FD %d, Read %d bytes\n", fd, (int)len); + if (flag == COMM_OK && len > 0) { IOStats.Ftp.reads++; for (j = len - 1, bin = 0; j; bin++) j >>= 1; @@ -915,14 +907,15 @@ if (ftpState->flags.isdir && !ftpState->flags.html_header_sent && len >= 0) { ftpListingStart(ftpState); } - if (len < 0) { + if (flag != COMM_OK || len < 0) { debug(50, ignoreErrno(errno) ? 3 : 1) ("ftpDataRead: read error: %s\n", xstrerror()); if (ignoreErrno(errno)) { - commSetSelect(fd, - COMM_SELECT_READ, - ftpDataRead, - data, - Config.Timeout.read); + /* XXX what about Config.Timeout.read? */ + read_sz = ftpState->data.size - ftpState->data.offset; +#if DELAY_POOLS + read_sz = delayBytesWanted(delay_id, 1, read_sz); +#endif + comm_read(fd, ftpState->data.buf + ftpState->data.offset, read_sz, ftpDataRead, data); } else { ftpFailed(ftpState, ERR_READ_ERROR); /* ftpFailed closes ctrl.fd and frees ftpState */ @@ -937,11 +930,12 @@ storeAppend(entry, ftpState->data.buf, len); ftpState->data.offset = 0; } - commSetSelect(fd, - COMM_SELECT_READ, - ftpDataRead, - data, - Config.Timeout.read); + /* XXX what about Config.Timeout.read? */ + read_sz = ftpState->data.size - ftpState->data.offset; +#if DELAY_POOLS + read_sz = delayBytesWanted(delay_id, 1, read_sz); +#endif + comm_read(fd, ftpState->data.buf + ftpState->data.offset, read_sz, ftpDataRead, data); } } @@ -1220,11 +1214,9 @@ /* We've already read some reply data */ ftpHandleControlReply(ftpState); } else { - commSetSelect(ftpState->ctrl.fd, - COMM_SELECT_READ, - ftpReadControlReply, - ftpState, - Config.Timeout.read); + /* XXX What about Config.Timeout.read? */ + comm_read(ftpState->ctrl.fd, ftpState->ctrl.buf + ftpState->ctrl.offset, + ftpState->ctrl.size - ftpState->ctrl.offset, ftpReadControlReply, ftpState); /* * Cancel the timeout on the Data socket (if any) and * establish one on the control socket. @@ -1237,28 +1229,23 @@ } static void -ftpReadControlReply(int fd, void *data) +ftpReadControlReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data) { FtpStateData *ftpState = data; StoreEntry *entry = ftpState->entry; - int len; debug(9, 5) ("ftpReadControlReply\n"); if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { comm_close(ftpState->ctrl.fd); return; } assert(ftpState->ctrl.offset < ftpState->ctrl.size); - statCounter.syscalls.sock.reads++; - len = FD_READ_METHOD(fd, - ftpState->ctrl.buf + ftpState->ctrl.offset, - ftpState->ctrl.size - ftpState->ctrl.offset); - if (len > 0) { + if (flag == COMM_OK && len > 0) { fd_bytes(fd, len, FD_READ); kb_incr(&statCounter.server.all.kbytes_in, len); kb_incr(&statCounter.server.ftp.kbytes_in, len); } - debug(9, 5) ("ftpReadControlReply: FD %d, Read %d bytes\n", fd, len); - if (len < 0) { + debug(9, 5) ("ftpReadControlReply: FD %d, Read %d bytes\n", fd, (int)len); + if (flag != COMM_OK || len < 0) { debug(50, ignoreErrno(errno) ? 3 : 1) ("ftpReadControlReply: read error: %s\n", xstrerror()); if (ignoreErrno(errno)) { ftpScheduleReadControlReply(ftpState, 0); @@ -2089,11 +2076,9 @@ if (code == 125 || (code == 150 && ftpState->data.host)) { /* Begin data transfer */ ftpAppendSuccessHeader(ftpState); - commSetSelect(ftpState->data.fd, - COMM_SELECT_READ, - ftpDataRead, - ftpState, - Config.Timeout.read); + /* XXX what about Config.Timeout.read? */ + assert(ftpState->data.offset == 0); + comm_read(ftpState->data.fd, ftpState->data.buf, ftpState->data.size, ftpDataRead, ftpState); commSetDefer(ftpState->data.fd, fwdCheckDeferRead, ftpState->entry); ftpState->state = READING_DATA; /* @@ -2134,16 +2119,19 @@ ftpReadRetr(FtpStateData * ftpState) { int code = ftpState->ctrl.replycode; + int read_sz; debug(9, 3) ("This is ftpReadRetr\n"); if (code == 125 || (code == 150 && ftpState->data.host)) { /* Begin data transfer */ debug(9, 3) ("ftpReadRetr: reading data channel\n"); ftpAppendSuccessHeader(ftpState); - commSetSelect(ftpState->data.fd, - COMM_SELECT_READ, - ftpDataRead, - ftpState, - Config.Timeout.read); + /* XXX what about Config.Timeout.read? */ + read_sz = ftpState->data.size - ftpState->data.offset; +#if DELAY_POOLS + read_sz = delayBytesWanted(delay_id, 1, read_sz); +#endif + comm_read(ftpState->data.fd, ftpState->data.buf + ftpState->data.offset, + read_sz, ftpDataRead, ftpState); commSetDefer(ftpState->data.fd, fwdCheckDeferRead, ftpState->entry); ftpState->state = READING_DATA; /*