--------------------- PatchSet 5203 Date: 2002/10/03 08:51:04 Author: adri Branch: commloops Tag: (none) Log: Complete the initial conversion of httpAccept(). So far, it seems to work. However, under load.. :) Members: src/client_side.c:1.52.4.4->1.52.4.5 src/comm.c:1.21.4.11->1.21.4.12 src/protos.h:1.49.4.8->1.49.4.9 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.52.4.4 retrieving revision 1.52.4.5 diff -u -r1.52.4.4 -r1.52.4.5 --- squid/src/client_side.c 3 Oct 2002 07:29:21 -0000 1.52.4.4 +++ squid/src/client_side.c 3 Oct 2002 08:51:04 -0000 1.52.4.5 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.52.4.4 2002/10/03 07:29:21 adri Exp $ + * $Id: client_side.c,v 1.52.4.5 2002/10/03 08:51:04 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -170,7 +170,7 @@ static void connNoteUseOfBuffer(ConnStateData * conn, int byteCount); static int connKeepReadingIncompleteRequest(ConnStateData * conn); static void connCancelIncompleteRequests(ConnStateData * conn); -static ConnStateData *connStateCreate(struct sockaddr_in peer, struct sockaddr_in me, int fd); +static ConnStateData *connStateCreate(struct sockaddr_in *peer, struct sockaddr_in *me, int fd); static clientStreamNode * getClientReplyContext(clientSocketContext * context); static int connAreAllContextsForThisConnection(ConnStateData * connState); static void connFreeAllContexts(ConnStateData * connState); @@ -1679,13 +1679,13 @@ } ConnStateData * -connStateCreate(struct sockaddr_in peer, struct sockaddr_in me, int fd) +connStateCreate(struct sockaddr_in *peer, struct sockaddr_in *me, int fd) { ConnStateData *result = cbdataAlloc(ConnStateData); - result->peer = peer; - result->log_addr = peer.sin_addr; + memcpy(&result->peer, peer, sizeof(struct sockaddr_in)); + memcpy(&result->log_addr, &peer->sin_addr, sizeof(result->log_addr)); result->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; - result->me = me; + memcpy(&result->me, me, sizeof(struct sockaddr_in)); result->fd = fd; result->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ, &result->in.allocatedSize); return result; @@ -1693,46 +1693,39 @@ /* Handle a new connection on HTTP socket. */ void -httpAccept(int sock, void *data) +httpAccept(int sock, int newfd, struct sockaddr_in *me, struct sockaddr_in *peer, + comm_err_t flag, int xerrno, void *data) { int *N = &incoming_sockets_accepted; - int fd = -1; ConnStateData *connState = NULL; - struct sockaddr_in peer; - struct sockaddr_in me; - int max = INCOMING_HTTP_MAX; #if USE_IDENT static aclCheck_t identChecklist; #endif - commSetSelect(sock, COMM_SELECT_READ, httpAccept, NULL, 0); - while (max-- && !httpAcceptDefer(sock, NULL)) { - memset(&peer, '\0', sizeof(struct sockaddr_in)); - memset(&me, '\0', sizeof(struct sockaddr_in)); - if ((fd = comm_old_accept(sock, &peer, &me)) < 0) { - if (!ignoreErrno(errno)) - debug(50, 1) ("httpAccept: FD %d: accept failure: %s\n", - sock, xstrerror()); - break; - } - debug(33, 4) ("httpAccept: FD %d: accepted\n", fd); - connState = connStateCreate(peer, me, fd); - comm_add_close_handler(fd, connStateFree, connState); + /* kick off another one for later */ + comm_accept(sock, httpAccept, NULL); + + /* XXX we're not considering httpAcceptDefer yet! */ + + do { + debug(33, 4) ("httpAccept: FD %d: accepted\n", newfd); + connState = connStateCreate(peer, me, newfd); + comm_add_close_handler(newfd, connStateFree, connState); if (Config.onoff.log_fqdn) - fqdncache_gethostbyaddr(peer.sin_addr, FQDN_LOOKUP_IF_MISS); - commSetTimeout(fd, Config.Timeout.request, requestTimeout, connState); + fqdncache_gethostbyaddr(peer->sin_addr, FQDN_LOOKUP_IF_MISS); + commSetTimeout(newfd, Config.Timeout.request, requestTimeout, connState); #if USE_IDENT - identChecklist.src_addr = peer.sin_addr; - identChecklist.my_addr = me.sin_addr; - identChecklist.my_port = ntohs(me.sin_port); + identChecklist.src_addr = peer->sin_addr; + identChecklist.my_addr = me->sin_addr; + identChecklist.my_port = ntohs(me->sin_port); if (aclCheckFast(Config.accessList.identLookup, &identChecklist)) - identStart(&me, &peer, clientIdentDone, connState); + identStart(me, peer, clientIdentDone, connState); #endif - commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, connState, 0); - commSetDefer(fd, clientReadDefer, connState); - clientdbEstablished(peer.sin_addr, 1); + commSetSelect(newfd, COMM_SELECT_READ, clientReadRequest, connState, 0); + commSetDefer(newfd, clientReadDefer, connState); + clientdbEstablished(peer->sin_addr, 1); assert(N); (*N)++; - } + } while (0); } #if USE_SSL @@ -1908,8 +1901,8 @@ leave_suid(); if (fd < 0) continue; - comm_old_listen(fd); - commSetSelect(fd, COMM_SELECT_READ, httpAccept, NULL, 0); + comm_listen(fd); + comm_accept(fd, httpAccept, NULL); /* * We need to set a defer handler here so that we don't * peg the CPU with select() when we hit the FD limit. Index: squid/src/comm.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm.c,v retrieving revision 1.21.4.11 retrieving revision 1.21.4.12 diff -u -r1.21.4.11 -r1.21.4.12 --- squid/src/comm.c 3 Oct 2002 08:04:36 -0000 1.21.4.11 +++ squid/src/comm.c 3 Oct 2002 08:51:04 -0000 1.21.4.12 @@ -1,6 +1,6 @@ /* - * $Id: comm.c,v 1.21.4.11 2002/10/03 08:04:36 adri Exp $ + * $Id: comm.c,v 1.21.4.12 2002/10/03 08:51:04 adri Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -218,6 +218,8 @@ fatal("write comm hasn't been implemented yet!"); break; case COMM_CB_ACCEPT: + cio->c.a_callback(cio->fd, cio->newfd, &cio->me, &cio->pn, cio->errcode, + cio->xerrno, cio->callback_data); break; default: fatal("unknown comm io callback type!"); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.49.4.8 retrieving revision 1.49.4.9 diff -u -r1.49.4.8 -r1.49.4.9 --- squid/src/protos.h 3 Oct 2002 08:04:36 -0000 1.49.4.8 +++ squid/src/protos.h 3 Oct 2002 08:51:04 -0000 1.49.4.9 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.49.4.8 2002/10/03 08:04:36 adri Exp $ + * $Id: protos.h,v 1.49.4.9 2002/10/03 08:51:04 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -156,6 +156,8 @@ extern void comm_calliocallback(void); extern void comm_read(int fd, char *buf, int len, IOCB *handler, void *data); +extern void comm_accept(int fd, IOACB *handler, void *handler_data); +extern int comm_listen(int fd); extern int commSetNonBlocking(int fd); extern int commUnsetNonBlocking(int fd); extern void commSetCloseOnExec(int fd); @@ -545,7 +547,6 @@ extern int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int); extern PF icpHandleUdp; extern PF icpUdpSendQueue; -extern PF httpAccept; #ifdef SQUID_SNMP extern PF snmpHandleUdp;