--- /dev/null
+/*
+ * $Id: ConnectionDetail.h,v 1.1 2003/02/14 13:59:50 robertc Exp $
+ *
+ * DEBUG: section 5 Socket Functions
+ * AUTHOR: Robert Collins
+ *
+ * SQUID Web Proxy Cache http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ * Squid is the result of efforts by numerous individuals from
+ * the Internet community; see the CONTRIBUTORS file for full
+ * details. Many organizations have provided support for Squid's
+ * development; see the SPONSORS file for full details. Squid is
+ * Copyrighted (C) 2001 by the Regents of the University of
+ * California; see the COPYRIGHT file for full details. Squid
+ * incorporates software developed and/or copyrighted by other
+ * sources; see the CREDITS file for full details.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ *
+ * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ */
+
+#ifndef _SQUIDCONNECTIONDETAIL_H_
+#define _SQUIDCONNECTIONDETAIL_H_
+
+class ConnectionDetail {
+ public:
+ struct sockaddr_in me;
+ struct sockaddr_in peer;
+};
+
+#endif
#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.am,v 1.58 2003/02/13 08:07:47 robertc Exp $
+# $Id: Makefile.am,v 1.59 2003/02/14 13:59:50 robertc Exp $
#
# Uncomment and customize the following to suit your needs:
#
comm_poll.cc \
comm_kqueue.cc \
Config.h \
+ ConnectionDetail.h \
debug.cc \
Debug.h \
defines.h \
/*
- * $Id: client_side.cc,v 1.619 2003/02/12 06:11:00 robertc Exp $
+ * $Id: client_side.cc,v 1.620 2003/02/14 13:59:49 robertc Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
#include "fde.h"
#include "client_side_request.h"
#include "ACLChecklist.h"
+#include "ConnectionDetail.h"
#if LINGERING_CLOSE
#define comm_close comm_lingering_close
/* Handle a new connection on HTTP socket. */
void
-httpAccept(int sock, int newfd, struct sockaddr_in *me, struct sockaddr_in *peer,
+httpAccept(int sock, int newfd, ConnectionDetail *details,
comm_err_t flag, int xerrno, void *data)
{
int *N = &incoming_sockets_accepted;
}
debug(33, 4) ("httpAccept: FD %d: accepted\n", newfd);
- connState = connStateCreate(peer, me, newfd);
+ connState = connStateCreate(&details->peer, &details->me, newfd);
comm_add_close_handler(newfd, connStateFree, connState);
if (Config.onoff.log_fqdn)
- fqdncache_gethostbyaddr(peer->sin_addr, FQDN_LOOKUP_IF_MISS);
+ fqdncache_gethostbyaddr(details->peer.sin_addr, FQDN_LOOKUP_IF_MISS);
commSetTimeout(newfd, Config.Timeout.request, requestTimeout, connState);
#if USE_IDENT
ACLChecklist identChecklist;
- identChecklist.src_addr = peer->sin_addr;
- identChecklist.my_addr = me->sin_addr;
- identChecklist.my_port = ntohs(me->sin_port);
+ identChecklist.src_addr = details->peer.sin_addr;
+ identChecklist.my_addr = details->me.sin_addr;
+ identChecklist.my_port = ntohs(details->me.sin_port);
if (aclCheckFast(Config.accessList.identLookup, &identChecklist))
- identStart(me, peer, clientIdentDone, connState);
+ identStart(&details->me, &details->peer, clientIdentDone, connState);
#endif
clientReadSomeData(connState);
commSetDefer(newfd, clientReadDefer, connState);
- clientdbEstablished(peer->sin_addr, 1);
+ clientdbEstablished(details->peer.sin_addr, 1);
assert(N);
(*N)++;
}
/*
- * $Id: comm.cc,v 1.364 2003/02/12 06:11:02 robertc Exp $
+ * $Id: comm.cc,v 1.365 2003/02/14 13:59:49 robertc Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
#include "StoreIOBuffer.h"
#include "comm.h"
#include "fde.h"
+#include "ConnectionDetail.h"
#if defined(_SQUID_CYGWIN_)
#include <sys/ioctl.h>
static PF comm_accept_try;
+class AcceptFD {
+ public:
+ int check_delay;
+ IOACB *handler;
+ void *handler_data;
+};
+
struct _fdc_t {
int active;
int fd;
} write;
struct {
/* how often (in msec) to re-check if we're out of fds on an accept() */
- int check_delay;
- struct sockaddr_in me;
- struct sockaddr_in pn;
- IOACB *handler;
- void *handler_data;
+ struct sockaddr_in & me() {return connDetails.me;}
+ struct sockaddr_in & pn() {return connDetails.peer;}
+ AcceptFD accept;
+ ConnectionDetail connDetails;
} accept;
struct CommFiller {
StoreIOBuffer requestedData;
comm_err_t errcode;
int xerrno;
int seqnum;
- struct sockaddr_in me;
- struct sockaddr_in pn;
+ ConnectionDetail details;
StoreIOBuffer sb;
};
typedef struct _CommCallbackData CommCallbackData;
}
+
static void
-comm_addacceptcallback(int fd, int newfd, IOACB *callback, struct sockaddr_in *pn,
- struct sockaddr_in *me, comm_err_t errcode, int xerrno, void *callback_data)
+comm_addacceptcallback(int fd, int newfd, IOACB *callback, ConnectionDetail details, comm_err_t errcode, int xerrno, void *callback_data)
{
CommCallbackData *cio;
cio->seqnum = CommCallbackSeqnum;
cio->type = COMM_CB_ACCEPT;
cio->newfd = newfd;
- cio->pn = *pn;
- cio->me = *me;
+ cio->details = details;
/* Add it to the end of the list */
dlinkAddTail(cio, &(cio->h_node), &CommCallbackList);
cio->callback_data);
break;
case COMM_CB_ACCEPT:
- cio->c.a_callback(cio->fd, cio->newfd, &cio->me, &cio->pn, cio->errcode,
+ cio->c.a_callback(cio->fd, cio->newfd, &cio->details, cio->errcode,
cio->xerrno, cio->callback_data);
break;
case COMM_CB_FILL:
{
assert(fdc_table[fd].active == 1);
assert(mdelay != 0);
- fdc_table[fd].accept.check_delay = mdelay;
+ fdc_table[fd].accept.accept.check_delay = mdelay;
}
/*
last_warn = squid_curtime;
}
eventAdd("comm_accept_check_event", comm_accept_check_event, &fdc_table[fd],
- 1000.0 / (double)(fdc_table[fd].accept.check_delay), 1);
+ 1000.0 / (double)(fdc_table[fd].accept.accept.check_delay), 1);
}
/* Wait for an incoming connection on FD. FD should be a socket returned
* from comm_listen. */
-int
-comm_old_accept(int fd, struct sockaddr_in *pn, struct sockaddr_in *me)
+static int
+comm_old_accept(int fd, ConnectionDetail &details)
{
- int sock;
- struct sockaddr_in P;
- struct sockaddr_in M;
- socklen_t Slen;
- fde *F = NULL;
- Slen = sizeof(P);
- statCounter.syscalls.sock.accepts++;
PROF_start(comm_accept);
- if ((sock = accept(fd, (struct sockaddr *) &P, &Slen)) < 0) {
+ statCounter.syscalls.sock.accepts++;
+ int sock;
+ socklen_t Slen = sizeof(details.peer);
+ if ((sock = accept(fd, (struct sockaddr *) &details.peer, &Slen)) < 0) {
PROF_stop(comm_accept);
if (ignoreErrno(errno)) {
debug(50, 5) ("comm_old_accept: FD %d: %s\n", fd, xstrerror());
return COMM_ERROR;
}
}
- if (pn)
- *pn = P;
- Slen = sizeof(M);
- memset(&M, '\0', Slen);
- getsockname(sock, (struct sockaddr *) &M, &Slen);
- if (me)
- *me = M;
+ Slen = sizeof(details.me);
+ memset(&details.me, '\0', Slen);
+ getsockname(sock, (struct sockaddr *) &details.me, &Slen);
commSetCloseOnExec(sock);
/* fdstat update */
fd_open(sock, FD_SOCKET, "HTTP Request");
fdd_table[sock].close_file = NULL;
fdd_table[sock].close_line = 0;
fdc_table[sock].active = 1;
- F = &fd_table[sock];
- xstrncpy(F->ipaddr, inet_ntoa(P.sin_addr), 16);
- F->remote_port = htons(P.sin_port);
- F->local_port = htons(M.sin_port);
+ fde *F = &fd_table[sock];
+ xstrncpy(F->ipaddr, inet_ntoa(details.peer.sin_addr), 16);
+ F->remote_port = htons(details.peer.sin_port);
+ F->local_port = htons(details.me.sin_port);
commSetNonBlocking(sock);
PROF_stop(comm_accept);
return sock;
COMM_ERR_CLOSING, 0, fdc_table[fd].read.handler_data);
fdc_table[fd].read.handler = NULL;
}
- if (fdc_table[fd].accept.handler) {
- fdc_table[fd].accept.handler(fd, -1, NULL, NULL, COMM_ERR_CLOSING,
- 0, fdc_table[fd].accept.handler_data);
- fdc_table[fd].accept.handler = NULL;
+ if (fdc_table[fd].accept.accept.handler) {
+ fdc_table[fd].accept.accept.handler(fd, -1, NULL, COMM_ERR_CLOSING,
+ 0, fdc_table[fd].accept.accept.handler_data);
+ fdc_table[fd].accept.accept.handler = NULL;
}
if (fdc_table[fd].fill.handler) {
fdc_table[fd].fill.handler(fd, fdc_table[fd].fill.requestedData, COMM_ERR_CLOSING, 0,
if (fdNFree() < RESERVED_FD) {
debug(5, 3) ("comm_accept_try: we're out of fds - deferring io!\n");
eventAdd("comm_accept_check_event", comm_accept_check_event, &fdc_table[fd],
- 1000.0 / (double)(fdc_table[fd].accept.check_delay), 1);
+ 1000.0 / (double)(fdc_table[fd].accept.accept.check_delay), 1);
return;
}
/* Accept a new connection */
- newfd = comm_old_accept(fd, &Fc->accept.pn, &Fc->accept.me);
+ newfd = comm_old_accept(fd, Fc->accept.connDetails);
/* Check for errors */
if (newfd < 0) {
if (newfd == COMM_NOMESSAGE) {
return;
}
/* A non-recoverable error - register an error callback */
- comm_addacceptcallback(fd, -1, Fc->accept.handler, &Fc->accept.pn,
- &Fc->accept.me, COMM_ERROR, errno, Fc->accept.handler_data);
- Fc->accept.handler = NULL;
- Fc->accept.handler_data = NULL;
+ comm_addacceptcallback(fd, -1, Fc->accept.accept.handler, Fc->accept.connDetails, COMM_ERROR, errno, Fc->accept.accept.handler_data);
+ Fc->accept.accept.handler = NULL;
+ Fc->accept.accept.handler_data = NULL;
return;
}
/* Try the callback! */
- hdl = Fc->accept.handler;
- Fc->accept.handler = NULL;
- hdl(fd, newfd, &Fc->accept.pn, &Fc->accept.me, COMM_OK, 0, Fc->accept.handler_data);
+ hdl = Fc->accept.accept.handler;
+ Fc->accept.accept.handler = NULL;
+ hdl(fd, newfd, &Fc->accept.connDetails, COMM_OK, 0, Fc->accept.accept.handler_data);
/* If we weren't re-registed, don't bother trying again! */
- if (Fc->accept.handler == NULL)
+ if (Fc->accept.accept.handler == NULL)
return;
}
}
assert(fdc_table[fd].active == 1);
/* make sure we're not pending! */
- assert(fdc_table[fd].accept.handler == NULL);
+ assert(fdc_table[fd].accept.accept.handler == NULL);
/* Record our details */
Fc = &fdc_table[fd];
- Fc->accept.handler = handler;
- Fc->accept.handler_data = handler_data;
+ Fc->accept.accept.handler = handler;
+ Fc->accept.accept.handler_data = handler_data;
/* Kick off the accept */
#if OPTIMISTIC_IO
/* fill sb with up to length data from fd */
extern void comm_fill_immediate(int fd, StoreIOBuffer sb, IOFCB *callback, void *data);
+class ConnectionDetail;
+typedef void IOACB(int fd, int nfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data);
+extern void comm_accept(int fd, IOACB *handler, void *handler_data);
+
extern int comm_has_pending_read_callback(int fd);
extern bool comm_has_pending_read(int fd);
extern void comm_read_cancel(int fd, IOCB *callback, void *data);
/*
- * $Id: ftp.cc,v 1.340 2003/02/05 10:36:51 robertc Exp $
+ * $Id: ftp.cc,v 1.341 2003/02/14 13:59:50 robertc Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
#if DELAY_POOLS
#include "DelayPools.h"
#endif
+#include "ConnectionDetail.h"
static const char *const crlf = "\r\n";
static char cbuf[1024];
/* "read" handler to accept data connection */
static void
-ftpAcceptDataConnection(int fd, int newfd, struct sockaddr_in *me, struct sockaddr_in *my_peer,
+ftpAcceptDataConnection(int fd, int newfd, ConnectionDetail *details,
comm_err_t flag, int xerrno, void *data)
{
FtpStateData *ftpState = (FtpStateData *)data;
}
if (Config.Ftp.sanitycheck) {
- char *ipaddr = inet_ntoa(my_peer->sin_addr);
+ char *ipaddr = inet_ntoa(details->peer.sin_addr);
if (strcmp(fd_table[ftpState->ctrl.fd].ipaddr, ipaddr) != 0) {
- debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(my_peer->sin_port), fd_table[ftpState->ctrl.fd].ipaddr);
+ debug(9, 1) ("FTP data connection from unexpected server (%s:%d), expecting %s\n", ipaddr, (int) ntohs(details->peer.sin_port), fd_table[ftpState->ctrl.fd].ipaddr);
comm_close(newfd);
comm_accept(ftpState->data.fd, ftpAcceptDataConnection, ftpState);
return;
comm_close(ftpState->data.fd);
debug(9, 3) ("ftpAcceptDataConnection: Connected data socket on FD %d\n", newfd);
ftpState->data.fd = newfd;
- ftpState->data.port = ntohs(my_peer->sin_port);
- ftpState->data.host = xstrdup(inet_ntoa(my_peer->sin_addr));
+ ftpState->data.port = ntohs(details->peer.sin_port);
+ ftpState->data.host = xstrdup(inet_ntoa(details->peer.sin_addr));
commSetTimeout(ftpState->ctrl.fd, -1, NULL, NULL);
commSetTimeout(ftpState->data.fd, Config.Timeout.read, ftpTimeout,
ftpState);
/*
- * $Id: protos.h,v 1.464 2003/02/12 06:11:04 robertc Exp $
+ * $Id: protos.h,v 1.465 2003/02/14 13:59:50 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
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);
SQUIDCEXTERN int commSetNonBlocking(int fd);
SQUIDCEXTERN int commUnsetNonBlocking(int fd);
SQUIDCEXTERN void commSetCloseOnExec(int fd);
-extern int comm_old_accept(int fd, struct sockaddr_in *, struct sockaddr_in *);
extern void _comm_close(int fd, char *file, int line);
#define comm_close(fd) (_comm_close((fd), __FILE__, __LINE__))
SQUIDCEXTERN void comm_reset_close(int fd);
/*
- * $Id: typedefs.h,v 1.150 2003/02/12 06:11:05 robertc Exp $
+ * $Id: typedefs.h,v 1.151 2003/02/14 13:59:50 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
typedef void CWCB(int fd, char *, size_t size, comm_err_t flag, void *data);
typedef void CNCB(int fd, comm_err_t status, void *);
typedef void IOCB(int fd, char *, size_t size, comm_err_t flag, int xerrno, void *data);
-typedef void IOACB(int fd, int nfd, struct sockaddr_in *me, struct sockaddr_in
- *pn, comm_err_t flag, int xerrno, void *data);
typedef void FREE(void *);
typedef void CBDUNL(void *);