--------------------- PatchSet 6515 Date: 2008/01/15 19:28:44 Author: chtsanti Branch: async-calls Tag: (none) Log: Convert the comm_accept calls to use CommCalls The ftpAcceptDataConnection function now is a method of FtpStateDataConnection Class Members: src/ftp.cc:1.89.4.9->1.89.4.10 Index: squid3/src/ftp.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ftp.cc,v retrieving revision 1.89.4.9 retrieving revision 1.89.4.10 diff -u -r1.89.4.9 -r1.89.4.10 --- squid3/src/ftp.cc 29 Dec 2007 15:24:40 -0000 1.89.4.9 +++ squid3/src/ftp.cc 15 Jan 2008 19:28:44 -0000 1.89.4.10 @@ -1,5 +1,5 @@ /* - * $Id: ftp.cc,v 1.89.4.9 2007/12/29 15:24:40 chtsanti Exp $ + * $Id: ftp.cc,v 1.89.4.10 2008/01/15 19:28:44 chtsanti Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -213,6 +213,8 @@ void ftpSocketClosed(const CommCloseCbParams &io); void ftpReadControlReply(const CommIoCbParams &io); void ftpWriteCommandCallback(const CommIoCbParams &io); + void ftpAcceptDataConnection(const CommAcceptCbParams &io); + static HttpReply *ftpAuthRequired(HttpRequest * request, const char *realm); static wordlist *ftpParseControlReply(char *, size_t, int *, size_t *); @@ -2661,63 +2663,63 @@ } /* "read" handler to accept data connection */ -static void -ftpAcceptDataConnection(int fd, int newfd, ConnectionDetail *details, - comm_err_t flag, int xerrno, void *data) +void FtpStateData::ftpAcceptDataConnection(const CommAcceptCbParams &io) { char ntoapeer[MAX_IPSTRLEN]; - FtpStateData *ftpState = (FtpStateData *)data; debugs(9, 3, "ftpAcceptDataConnection"); - if (flag == COMM_ERR_CLOSING) + if (io.flag == COMM_ERR_CLOSING) return; - if (EBIT_TEST(ftpState->entry->flags, ENTRY_ABORTED)) { - ftpState->abortTransaction("entry aborted when accepting data conn"); + if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { + abortTransaction("entry aborted when accepting data conn"); return; } if (Config.Ftp.sanitycheck) { - details->peer.NtoA(ntoapeer,MAX_IPSTRLEN); + io.details.peer.NtoA(ntoapeer,MAX_IPSTRLEN); - if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ntoapeer) != 0) { + if (strcmp(fd_table[ctrl.fd].ipaddr, ntoapeer) != 0) { debugs(9, 1, "FTP data connection from unexpected server (" << - details->peer << "), expecting " << fd_table[ftpState->ctrl.fd].ipaddr); + io.details.peer << "), expecting " << fd_table[ctrl.fd].ipaddr); - comm_close(newfd); - comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); + comm_close(io.nfd); + typedef CommCbMemFunT acceptDialer; + AsyncCall::Pointer acceptCall = asyncCall(11, 5, "FtpStateData::ftpAcceptDataConnection", + acceptDialer(this, &FtpStateData::ftpAcceptDataConnection)); + comm_accept(data.fd, acceptCall); return; } } - if (flag != COMM_OK) { - debugs(9, 1, "ftpHandleDataAccept: comm_accept(" << newfd << "): " << xstrerr(xerrno)); + if (io.flag != COMM_OK) { + debugs(9, 1, "ftpHandleDataAccept: comm_accept(" << io.nfd << "): " << xstrerr(io.xerrno)); /* XXX Need to set error message */ - ftpFail(ftpState); + ftpFail(this); return; } /* Replace the Listen socket with the accepted data socket */ - comm_close(ftpState->data.fd); + comm_close(data.fd); - debugs(9, 3, "ftpAcceptDataConnection: Connected data socket on FD " << newfd); + debugs(9, 3, "ftpAcceptDataConnection: Connected data socket on FD " << io.nfd); - ftpState->data.fd = newfd; + data.fd = io.nfd; - ftpState->data.port = details->peer.GetPort(); + data.port = io.details.peer.GetPort(); - details->peer.NtoA(ftpState->data.host,SQUIDHOSTNAMELEN); + io.details.peer.NtoA(data.host,SQUIDHOSTNAMELEN); - commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); + commSetTimeout(ctrl.fd, -1, NULL, NULL); - commSetTimeout(ftpState->data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, ftpState); + commSetTimeout(data.fd, Config.Timeout.read, FtpStateData::ftpTimeout, this); /* XXX We should have a flag to track connect state... * host NULL -> not connected, port == local port * host set -> connected, port == remote port */ /* Restart state (SENT_NLST/LIST/RETR) */ - FTP_SM_FUNCS[ftpState->state] (ftpState); + FTP_SM_FUNCS[state] (this); } static void @@ -2799,7 +2801,11 @@ } else if (code == 150) { /* Accept data channel */ debugs(9, 3, "ftpReadStor: accepting data channel"); - comm_accept(data.fd, ftpAcceptDataConnection, this); + typedef CommCbMemFunT acceptDialer; + AsyncCall::Pointer acceptCall = asyncCall(11, 5, "FtpStateData::ftpAcceptDataConnection", + acceptDialer(this, &FtpStateData::ftpAcceptDataConnection)); + + comm_accept(data.fd, acceptCall); } else { debugs(9, 3, "ftpReadStor: Unexpected reply code "<< std::setfill('0') << std::setw(3) << code); ftpFail(this); @@ -2919,7 +2925,11 @@ return; } else if (code == 150) { /* Accept data channel */ - comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); + typedef CommCbMemFunT acceptDialer; + AsyncCall::Pointer acceptCall = asyncCall(11, 5, "FtpStateData::ftpAcceptDataConnection", + acceptDialer(ftpState, &FtpStateData::ftpAcceptDataConnection)); + + comm_accept(ftpState->data.fd, acceptCall); /* * Cancel the timeout on the Control socket and establish one * on the data socket @@ -2967,7 +2977,10 @@ commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL); } else if (code == 150) { /* Accept data channel */ - comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState); + typedef CommCbMemFunT acceptDialer; + AsyncCall::Pointer acceptCall = asyncCall(11, 5, "FtpStateData::ftpAcceptDataConnection", + acceptDialer(ftpState, &FtpStateData::ftpAcceptDataConnection)); + comm_accept(ftpState->data.fd, acceptCall); /* * Cancel the timeout on the Control socket and establish one * on the data socket