/*
- * $Id: comm.cc,v 1.174 1997/07/14 05:57:53 wessels Exp $
+ * $Id: comm.cc,v 1.175 1997/07/14 19:24:35 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
{
struct sockaddr_in addr;
int addr_len = 0;
- fde *fde = &fd_table[fd];
+ fde *F = &fd_table[fd];
/* If the fd is closed already, just return */
- if (!fde->open) {
+ if (!F->open) {
debug(5, 0) ("comm_local_port: FD %d has been closed.\n", fd);
return 0;
}
- if (fde->local_port)
- return fde->local_port;
+ if (F->local_port)
+ return F->local_port;
addr_len = sizeof(addr);
if (getsockname(fd, (struct sockaddr *) &addr, &addr_len)) {
debug(50, 1) ("comm_local_port: Failed to retrieve TCP/UDP port number for socket: FD %d: %s\n", fd, xstrerror());
return 0;
}
debug(5, 6) ("comm_local_port: FD %d: sockaddr %u.\n", fd, addr.sin_addr.s_addr);
- fde->local_port = ntohs(addr.sin_port);
- return fde->local_port;
+ F->local_port = ntohs(addr.sin_port);
+ return F->local_port;
}
static int
const char *note)
{
int new_socket;
- fde *fde = NULL;
+ fde *F = NULL;
int tcp_rcv_bufsz = Config.tcpRcvBufsz;
/* Create socket for accepting new connections. */
/* update fdstat */
debug(5, 5) ("comm_open: FD %d is a new socket\n", new_socket);
fd_open(new_socket, FD_SOCKET, note);
- fde = &fd_table[new_socket];
+ F = &fd_table[new_socket];
if (!BIT_TEST(flags, COMM_NOCLOEXEC))
commSetCloseOnExec(new_socket);
if (port > (u_short) 0) {
if (addr.s_addr != no_addr.s_addr)
if (commBind(new_socket, addr, port) != COMM_OK)
return COMM_ERROR;
- fde->local_port = port;
+ F->local_port = port;
if (BIT_TEST(flags, COMM_NONBLOCKING))
if (commSetNonBlocking(new_socket) == COMM_ERROR)
int
commSetTimeout(int fd, int timeout, PF * handler, void *data)
{
- fde *fde;
+ fde *F;
debug(5, 3) ("commSetTimeout: FD %d timeout %d\n", fd, timeout);
assert(fd >= 0);
assert(fd < Squid_MaxFD);
- fde = &fd_table[fd];
+ F = &fd_table[fd];
if (timeout < 0) {
- fde->timeout_handler = NULL;
- fde->timeout_data = NULL;
- return fde->timeout = 0;
+ F->timeout_handler = NULL;
+ F->timeout_data = NULL;
+ return F->timeout = 0;
}
if (shutdown_pending || reconfigure_pending) {
/* don't increase the timeout if something pending */
- if (fde->timeout > 0 && (int) (fde->timeout - squid_curtime) < timeout)
- return fde->timeout;
+ if (F->timeout > 0 && (int) (F->timeout - squid_curtime) < timeout)
+ return F->timeout;
}
- assert(handler || fde->timeout_handler);
+ assert(handler || F->timeout_handler);
if (handler || data) {
- fde->timeout_handler = handler;
- fde->timeout_data = data;
+ F->timeout_handler = handler;
+ F->timeout_data = data;
}
- return fde->timeout = squid_curtime + (time_t) timeout;
+ return F->timeout = squid_curtime + (time_t) timeout;
}
int
comm_connect_addr(int sock, const struct sockaddr_in *address)
{
int status = COMM_OK;
- fde *fde = &fd_table[sock];
+ fde *F = &fd_table[sock];
int len;
int x;
assert(ntohs(address->sin_port) != 0);
return COMM_ERROR;
}
}
- xstrncpy(fde->ipaddr, inet_ntoa(address->sin_addr), 16);
- fde->remote_port = ntohs(address->sin_port);
+ xstrncpy(F->ipaddr, inet_ntoa(address->sin_addr), 16);
+ F->remote_port = ntohs(address->sin_port);
if (status == COMM_OK) {
debug(5, 10) ("comm_connect_addr: FD %d connected to %s:%d\n",
- sock, fde->ipaddr, fde->remote_port);
+ sock, F->ipaddr, F->remote_port);
} else if (status == COMM_INPROGRESS) {
debug(5, 10) ("comm_connect_addr: FD %d connection pending\n", sock);
}
struct sockaddr_in P;
struct sockaddr_in M;
int Slen;
- fde *fde = NULL;
+ fde *F = NULL;
Slen = sizeof(P);
while ((sock = accept(fd, (struct sockaddr *) &P, &Slen)) < 0) {
commSetCloseOnExec(sock);
/* fdstat update */
fd_open(sock, FD_SOCKET, "HTTP Request");
- fde = &fd_table[sock];
- strcpy(fde->ipaddr, inet_ntoa(P.sin_addr));
- fde->remote_port = htons(P.sin_port);
- fde->local_port = htons(M.sin_port);
+ F = &fd_table[sock];
+ strcpy(F->ipaddr, inet_ntoa(P.sin_addr));
+ F->remote_port = htons(P.sin_port);
+ F->local_port = htons(M.sin_port);
commSetNonBlocking(sock);
return sock;
}
void
commCallCloseHandlers(int fd)
{
- fde *fde = &fd_table[fd];
+ fde *F = &fd_table[fd];
close_handler *ch;
debug(5, 5) ("commCallCloseHandlers: FD %d\n", fd);
- while ((ch = fde->close_handler) != NULL) {
- fde->close_handler = ch->next;
+ while ((ch = F->close_handler) != NULL) {
+ F->close_handler = ch->next;
ch->handler(fd, ch->data);
safe_free(ch);
}
void
comm_close(int fd)
{
- fde *fde = NULL;
+ fde *F = NULL;
debug(5, 5) ("comm_close: FD %d\n", fd);
assert(fd >= 0);
assert(fd < Squid_MaxFD);
- fde = &fd_table[fd];
- if (!fde->open)
+ F = &fd_table[fd];
+ if (!F->open) {
+ debug(5,1)("comm_close: FD %d is not open!\n", fd);
return;
- assert(fde->type != FD_FILE);
- memset(fde, '\0', sizeof(fde));
+ }
+ assert(F->type != FD_FILE);
+ memset(F, '\0', sizeof(fde));
CommWriteStateCallbackAndFree(fd, COMM_ERROR);
commCallCloseHandlers(fd);
fd_close(fd); /* update fdstat */
continue;
if (revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
hdl = fd_table[fd].read_handler;
- fd_table[fd].read_handler = 0;
+ fd_table[fd].read_handler = NULL;
hdl(fd, fd_table[fd].read_data);
}
if (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
hdl = fd_table[fd].write_handler;
- fd_table[fd].write_handler = 0;
+ fd_table[fd].write_handler = NULL;
hdl(fd, fd_table[fd].write_data);
}
}
fd = fds[i];
if (FD_ISSET(fd, &read_mask)) {
hdl = fd_table[fd].read_handler;
- fd_table[fd].read_handler = 0;
+ fd_table[fd].read_handler = NULL;
hdl(fd, fd_table[fd].read_data);
}
if (FD_ISSET(fd, &write_mask)) {
hdl = fd_table[fd].write_handler;
- fd_table[fd].write_handler = 0;
+ fd_table[fd].write_handler = NULL;
hdl(fd, fd_table[fd].write_data);
}
}
debug(5, 2) ("comm_poll: Still waiting on %d FDs\n", nfds);
if (nfds == 0)
return COMM_SHUTDOWN;
- poll_time = sec > 0 ? 100 : 0;
+ poll_time = sec > 0 ? 1000 : 0;
#if USE_ASYNC_IO
aioCheckCallbacks();
#endif
if (revents & (POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
debug(5, 6) ("comm_poll: FD %d ready for reading\n", fd);
if ((hdl = fd_table[fd].read_handler)) {
- fd_table[fd].read_handler = 0;
+ fd_table[fd].read_handler = NULL;
hdl(fd, fd_table[fd].read_data);
}
}
if (revents & (POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
debug(5, 5) ("comm_poll: FD %d ready for writing\n", fd);
if ((hdl = fd_table[fd].write_handler)) {
- fd_table[fd].write_handler = 0;
+ fd_table[fd].write_handler = NULL;
hdl(fd, fd_table[fd].write_data);
}
}
if (revents & POLLNVAL) {
close_handler *ch;
close_handler *next;
- fde *fde = &fd_table[fd];
+ fde *F = &fd_table[fd];
debug(5, 0) ("WARNING: FD %d has handlers, but it's invalid.\n", fd);
debug(5, 0) ("FD %d is a %s\n", fd, fdstatTypeStr[fd_table[fd].type]);
debug(5, 0) ("--> %s\n", fd_table[fd].desc);
debug(5, 0) ("tmout:%p read:%p write:%p\n",
- fde->timeout_handler,
- fde->read_handler,
- fde->write_handler);
- for (ch = fde->close_handler; ch; ch = ch->next)
+ F->timeout_handler,
+ F->read_handler,
+ F->write_handler);
+ assert(0);
+ for (ch = F->close_handler; ch; ch = ch->next)
debug(5, 0) (" close handler: %p\n", ch->handler);
- if (fde->close_handler) {
- for (ch = fde->close_handler; ch; ch = next) {
+ if (F->close_handler) {
+ for (ch = F->close_handler; ch; ch = next) {
next = ch->next;
ch->handler(fd, ch->data);
safe_free(ch);
}
- } else if (fde->timeout_handler) {
+ } else if (F->timeout_handler) {
debug(5, 0) ("comm_poll: Calling Timeout Handler\n");
- fde->timeout_handler(fd, fde->timeout_data);
+ F->timeout_handler(fd, F->timeout_data);
}
- fde->close_handler = NULL;
- fde->timeout_handler = NULL;
- fde->read_handler = NULL;
- fde->write_handler = NULL;
+ F->close_handler = NULL;
+ F->timeout_handler = NULL;
+ F->read_handler = NULL;
+ F->write_handler = NULL;
}
lastinc = polledinc;
}
debug(5, 6) ("comm_select: FD %d ready for reading\n", fd);
if (fd_table[fd].read_handler) {
hdl = fd_table[fd].read_handler;
- fd_table[fd].read_handler = 0;
+ fd_table[fd].read_handler = NULL;
hdl(fd, fd_table[fd].read_data);
}
}
debug(5, 5) ("comm_select: FD %d ready for writing\n", fd);
if (fd_table[fd].write_handler) {
hdl = fd_table[fd].write_handler;
- fd_table[fd].write_handler = 0;
+ fd_table[fd].write_handler = NULL;
hdl(fd, fd_table[fd].write_data);
}
}
void
commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout)
{
- fde *fde;
+ fde *F;
assert(fd >= 0);
- fde = &fd_table[fd];
+ F = &fd_table[fd];
debug(5, 5) ("commSetSelect: FD %d, type=%d, handler=%p, data=%p\n", fd, type, handler, client_data);
if (type & COMM_SELECT_READ) {
- fde->read_handler = handler;
- fde->read_data = client_data;
+ F->read_handler = handler;
+ F->read_data = client_data;
}
if (type & COMM_SELECT_WRITE) {
- fde->write_handler = handler;
- fde->write_data = client_data;
+ F->write_handler = handler;
+ F->write_data = client_data;
}
if (timeout)
- fde->timeout = squid_curtime + timeout;
+ F->timeout = squid_curtime + timeout;
}
void
struct timeval tv;
close_handler *ch = NULL;
close_handler *next = NULL;
- fde *fde = NULL;
+ fde *F = NULL;
debug(5, 0) ("examine_select: Examining open file descriptors...\n");
for (fd = 0; fd < Squid_MaxFD; fd++) {
debug(5, 5) ("FD %d is valid.\n", fd);
continue;
}
- fde = &fd_table[fd];
+ F = &fd_table[fd];
debug(5, 0) ("FD %d: %s\n", fd, xstrerror());
debug(5, 0) ("WARNING: FD %d has handlers, but it's invalid.\n", fd);
debug(5, 0) ("FD %d is a %s called '%s'\n",
fd,
fdstatTypeStr[fd_table[fd].type],
- fde->desc);
+ F->desc);
debug(5, 0) ("tmout:%p read:%p write:%p\n",
- fde->timeout_handler,
- fde->read_handler,
- fde->write_handler);
- for (ch = fde->close_handler; ch; ch = ch->next)
+ F->timeout_handler,
+ F->read_handler,
+ F->write_handler);
+ for (ch = F->close_handler; ch; ch = ch->next)
debug(5, 0) (" close handler: %p\n", ch->handler);
- if (fde->close_handler) {
- for (ch = fde->close_handler; ch; ch = next) {
+ if (F->close_handler) {
+ for (ch = F->close_handler; ch; ch = next) {
next = ch->next;
ch->handler(fd, ch->data);
safe_free(ch);
}
- } else if (fde->timeout_handler) {
+ } else if (F->timeout_handler) {
debug(5, 0) ("examine_select: Calling Timeout Handler\n");
- fde->timeout_handler(fd, fde->timeout_data);
+ F->timeout_handler(fd, F->timeout_data);
}
- fde->close_handler = NULL;
- fde->timeout_handler = NULL;
- fde->read_handler = NULL;
- fde->write_handler = NULL;
+ F->close_handler = NULL;
+ F->timeout_handler = NULL;
+ F->read_handler = NULL;
+ F->write_handler = NULL;
FD_CLR(fd, readfds);
FD_CLR(fd, writefds);
}
checkTimeouts(void)
{
int fd;
- fde *fde = NULL;
+ fde *F = NULL;
PF *callback;
for (fd = 0; fd <= Biggest_FD; fd++) {
- fde = &fd_table[fd];
- if (fde->open != FD_OPEN)
+ F = &fd_table[fd];
+ if (F->open != FD_OPEN)
continue;
- if (fde->timeout == 0)
+ if (F->timeout == 0)
continue;
- if (fde->timeout > squid_curtime)
+ if (F->timeout > squid_curtime)
continue;
debug(5, 5) ("checkTimeouts: FD %d Expired\n", fd);
- if (fde->timeout_handler) {
+ if (F->timeout_handler) {
debug(5, 5) ("checkTimeouts: FD %d: Call timeout handler\n", fd);
- callback = fde->timeout_handler;
- fde->timeout_handler = NULL;
- callback(fd, fde->timeout_data);
+ callback = F->timeout_handler;
+ F->timeout_handler = NULL;
+ callback(fd, F->timeout_data);
} else {
debug(5, 5) ("checkTimeouts: FD %d: Forcing comm_close()\n", fd);
comm_close(fd);
/*
- * $Id: disk.cc,v 1.76 1997/07/07 05:29:43 wessels Exp $
+ * $Id: disk.cc,v 1.77 1997/07/14 19:24:36 wessels Exp $
*
* DEBUG: section 6 Disk I/O Routines
* AUTHOR: Harvest Derived
file_open_complete(void *data, int fd, int errcode)
{
open_ctrl_t *ctrlp = (open_ctrl_t *) data;
- fde *fde;
+ fde *F;
if (fd < 0) {
errno = errcode;
debug(50, 0) ("file_open: error opening file %s: %s\n", ctrlp->path,
debug(6, 5) ("file_open: FD %d\n", fd);
commSetCloseOnExec(fd);
fd_open(fd, FD_FILE, ctrlp->path);
- fde = &fd_table[fd];
+ F = &fd_table[fd];
if (ctrlp->callback)
(ctrlp->callback) (ctrlp->callback_data, fd);
xfree(ctrlp->path);
void
file_close(int fd)
{
- fde *fde = &fd_table[fd];
+ fde *F = &fd_table[fd];
assert(fd >= 0);
- assert(fde->open);
- if (BIT_TEST(fde->flags, FD_WRITE_DAEMON)) {
- BIT_SET(fde->flags, FD_CLOSE_REQUEST);
+ assert(F->open);
+ if (BIT_TEST(F->flags, FD_WRITE_DAEMON)) {
+ BIT_SET(F->flags, FD_CLOSE_REQUEST);
return;
}
- if (BIT_TEST(fde->flags, FD_WRITE_PENDING)) {
- BIT_SET(fde->flags, FD_CLOSE_REQUEST);
+ if (BIT_TEST(F->flags, FD_WRITE_PENDING)) {
+ BIT_SET(F->flags, FD_CLOSE_REQUEST);
return;
}
fd_close(fd);
disk_ctrl_t *ctrlp;
dwrite_q *q = NULL;
dwrite_q *wq = NULL;
- fde *fde = &fd_table[fd];
- struct _fde_disk *fdd = &fde->disk;
+ fde *F = &fd_table[fd];
+ struct _fde_disk *fdd = &F->disk;
if (!fdd->write_q)
return;
/* We need to combine subsequent write requests after the first */
{
disk_ctrl_t *ctrlp = data;
int fd = ctrlp->fd;
- fde *fde = &fd_table[fd];
- struct _fde_disk *fdd = &fde->disk;
+ fde *F = &fd_table[fd];
+ struct _fde_disk *fdd = &F->disk;
dwrite_q *q = fdd->write_q;
int status = DISK_OK;
errno = errcode;
if (fdd->write_q == NULL) {
/* no more data */
fdd->write_q_tail = NULL;
- BIT_RESET(fde->flags, FD_WRITE_PENDING);
- BIT_RESET(fde->flags, FD_WRITE_DAEMON);
+ BIT_RESET(F->flags, FD_WRITE_PENDING);
+ BIT_RESET(F->flags, FD_WRITE_DAEMON);
} else {
/* another block is queued */
commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0);
- BIT_SET(fde->flags, FD_WRITE_DAEMON);
+ BIT_SET(F->flags, FD_WRITE_DAEMON);
}
if (fdd->wrt_handle)
fdd->wrt_handle(fd, status, len, fdd->wrt_handle_data);
- if (BIT_TEST(fde->flags, FD_CLOSE_REQUEST))
+ if (BIT_TEST(F->flags, FD_CLOSE_REQUEST))
file_close(fd);
}
FREE * free_func)
{
dwrite_q *wq = NULL;
- fde *fde;
+ fde *F;
if (fd < 0)
fatal_dump("file_write: bad FD");
- fde = &fd_table[fd];
- if (!fde->open) {
+ F = &fd_table[fd];
+ if (!F->open) {
debug_trap("file_write: FILE_NOT_OPEN");
return DISK_ERROR;
}
wq->cur_offset = 0;
wq->next = NULL;
wq->free = free_func;
- fde->disk.wrt_handle = handle;
- fde->disk.wrt_handle_data = handle_data;
+ F->disk.wrt_handle = handle;
+ F->disk.wrt_handle_data = handle_data;
/* add to queue */
- BIT_SET(fde->flags, FD_WRITE_PENDING);
- if (!(fde->disk.write_q)) {
+ BIT_SET(F->flags, FD_WRITE_PENDING);
+ if (!(F->disk.write_q)) {
/* empty queue */
- fde->disk.write_q = fde->disk.write_q_tail = wq;
+ F->disk.write_q = F->disk.write_q_tail = wq;
} else {
- fde->disk.write_q_tail->next = wq;
- fde->disk.write_q_tail = wq;
+ F->disk.write_q_tail->next = wq;
+ F->disk.write_q_tail = wq;
}
- if (!BIT_TEST(fde->flags, FD_WRITE_DAEMON)) {
+ if (!BIT_TEST(F->flags, FD_WRITE_DAEMON)) {
#if USE_ASYNC_IO
diskHandleWrite(fd, NULL);
#else
commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0);
#endif
- BIT_SET(fde->flags, FD_WRITE_DAEMON);
+ BIT_SET(F->flags, FD_WRITE_DAEMON);
}
return DISK_OK;
}