--------------------- PatchSet 1581 Date: 2001/02/15 21:17:03 Author: adri Branch: eventio Tag: (none) Log: * add syscall stats logging on read/write/accept * initialise and call ncomm_handle_requests() to serve IO. * change poll() in ncomm_handle_requests() to return immediately regardless of pending IO, rather than waiting around. This lets us call it right now so we can actually start migrating stuff over * keep a local and remote sockaddr_in which we update in do_accept(). * delete the use for comm_new_fd() (but not the function yet) * rewrite most of comm_do_accept() to look like comm_accept() - - Set the socket options/flags - Update local and remote sockaddr_in + ports + local IP Members: src/comm_server.c:1.1.2.1->1.1.2.2 src/main.c:1.19->1.19.8.1 src/structs.h:1.24.8.1->1.24.8.2 Index: squid/src/comm_server.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/comm_server.c,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_server.c 15 Feb 2001 15:53:37 -0000 1.1.2.1 +++ squid/src/comm_server.c 15 Feb 2001 21:17:03 -0000 1.1.2.2 @@ -81,7 +81,8 @@ ncomm_handle_events(void) { int comm_index; - int fds = poll(pollfds, pollnfds, -1); + /* We sleep for nothing for the time being */ + int fds = poll(pollfds, pollnfds, 0); for (comm_index=0; comm_index < (int)pollnfds && fds > 0; comm_index++) { short revents = pollfds[comm_index].revents; int fd = pollfds[comm_index].fd; @@ -145,8 +146,10 @@ { /* Read in some data */ const ssize_t len = read(fd, fhr->buf, fhr->size); + statCounter.syscalls.sock.reads++; if (len >= 0) { /* We got some data to deliver to the application */ + fd_table[fd].bytes_read += len; comm_callback(fd, fhr->buf, len, 0, fhr->callback, fhr->data); return 1; } @@ -164,8 +167,10 @@ { /* Read in some data */ const ssize_t len = read(fd, buf, size); + statCounter.syscalls.sock.reads++; if (len >= 0) { /* We immediately got some data to deliver to the application */ + fd_table[fd].bytes_read += len; comm_callback(fd, buf, len, 0, callback, data); return; } @@ -190,14 +195,18 @@ const void *buf = (void *)((char *)fhw->buf + fhw->done); const size_t size = fhw->size - fhw->done; ssize_t len = write(fd, buf, size); + statCounter.syscalls.sock.writes++; if ((size_t)len == size) { /* finished */ - comm_callback(fd, fhw->buf, (ssize_t)fhw->size, 0, fhw->callback, fhw->data); + fd_table[fd].bytes_written += len; + comm_callback(fd, fhw->buf, (ssize_t)fhw->size, 0, fhw->callback, + fhw->data); return 1; } if (len == -1 && !ignoreErrno(errno)) { /* error */ - comm_callback(fd, fhw->buf, fhw->done, errno, fhw->callback, fhw->data); + comm_callback(fd, fhw->buf, fhw->done, errno, fhw->callback, + fhw->data); return 1; } /* try again */ @@ -210,8 +219,10 @@ ncomm_write(int fd, const void *buf, size_t size, COMMCB callback, void *data) { ssize_t len = write(fd, buf, size); + statCounter.syscalls.sock.writes++; if ((size_t)len == size) { /* Finished immediately */ + fd_table[fd].bytes_written += len; comm_callback(fd, (void *)buf, len, 0, callback, data); return; } @@ -245,13 +256,35 @@ { int nfd; struct sockaddr saddr; - socklen_t addrlen = sizeof(saddr); + socklen_t addrlen; + fde *F; - while((nfd = accept(fd, &saddr, &addrlen)) != -1) { - memset(&fd_table[nfd].new, 0, sizeof(fd_table[nfd].new)); - comm_new_fd(nfd); - memcpy(&fd_table[nfd].new.peer, &saddr, sizeof(saddr)); - comm_callback(nfd, &fd_table[nfd].new.peer, addrlen, 0, fhr->callback, fhr->data); + while(1) { + addrlen = sizeof(struct sockaddr); + nfd = accept(fd, &saddr, &addrlen); + statCounter.syscalls.sock.accepts++; + if (nfd < 0) + break; + /* Update the FD state */ + F = &fd_table[nfd]; + + memset(&F->new, 0, sizeof(fd_table[nfd].new)); + fd_open(nfd, FD_SOCKET, "Incoming request"); + + /* Update the socket information */ + addrlen = sizeof(struct sockaddr); + getsockname(nfd, (struct sockaddr *) &F->new.local, &addrlen); + xstrncpy(F->ipaddr, inet_ntoa(F->new.peer.sin_addr), 16); + F->remote_port = htons(F->new.peer.sin_port); + F->local_port = htons(F->new.local.sin_port); + + /* Set the flags */ + commSetCloseOnExec(nfd); + commSetNonBlocking(nfd); + + /* Finally, hand over the socket */ + comm_callback(nfd, &fd_table[nfd].new.peer, addrlen, 0, + fhr->callback, fhr->data); } if (!ignoreErrno(errno)) { perror("accept:"); Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.19 retrieving revision 1.19.8.1 diff -u -r1.19 -r1.19.8.1 --- squid/src/main.c 31 Jan 2001 00:27:46 -0000 1.19 +++ squid/src/main.c 15 Feb 2001 21:17:03 -0000 1.19.8.1 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.19 2001/01/31 00:27:46 hno Exp $ + * $Id: main.c,v 1.19.8.1 2001/02/15 21:17:03 adri Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -635,6 +635,7 @@ #if TEST_ACCESS comm_init(); + ncomm_init(); comm_select_init(); mainInitialize(); test_access(); @@ -670,6 +671,7 @@ /* init comm module */ comm_init(); + ncomm_init(); comm_select_init(); if (opt_no_daemon) { @@ -706,6 +708,7 @@ eventAdd("SquidShutdown", SquidShutdown, NULL, (double) (wait + 1), 1); } eventRun(); + ncomm_handle_events(); if ((loop_delay = eventNextTime()) < 0) loop_delay = 0; #if HAVE_POLL Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.24.8.1 retrieving revision 1.24.8.2 diff -u -r1.24.8.1 -r1.24.8.2 --- squid/src/structs.h 15 Feb 2001 15:53:37 -0000 1.24.8.1 +++ squid/src/structs.h 15 Feb 2001 21:17:03 -0000 1.24.8.2 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.24.8.1 2001/02/15 15:53:37 adri Exp $ + * $Id: structs.h,v 1.24.8.2 2001/02/15 21:17:03 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -756,7 +756,8 @@ struct _fh_read read; struct _fh_write write; int comm_index; - struct sockaddr peer; + struct sockaddr_in peer; + struct sockaddr_in local; } new; };