/*
- * $Id: comm.cc,v 1.61 1996/08/30 22:36:21 wessels Exp $
+ * $Id: comm.cc,v 1.62 1996/09/11 22:26:23 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
static void commSetNoLinger _PARAMS((int));
static void comm_select_incoming _PARAMS((void));
static int commBind _PARAMS((int s, struct in_addr, u_short port));
-static void RWStateCallbackAndFree _PARAMS((int fd, RWStateData *, int code));
+static void RWStateCallbackAndFree _PARAMS((int fd, int code));
#ifdef TCP_NODELAY
static void commSetTcpNoDelay _PARAMS((int));
#endif
static int *fd_lifetime = NULL;
static struct timeval zero_tv;
-static void RWStateCallbackAndFree(fd, RWState, code)
+static void RWStateCallbackAndFree(fd, code)
int fd;
- RWStateData *RWState;
int code;
{
+ RWStateData *RWState = fd_table[fd].rwstate;
rw_complete_handler *callback = NULL;
+ fd_table[fd].rwstate = NULL;
if (RWState == NULL)
return;
if (RWState->free) {
fatal_dump(NULL);
}
conn->openned = 0;
- RWStateCallbackAndFree(fd, conn->rwstate, COMM_ERROR);
+ RWStateCallbackAndFree(fd, COMM_ERROR);
comm_set_fd_lifetime(fd, -1); /* invalidate the lifetime */
fdstat_close(fd); /* update fdstat */
while ((ch = conn->close_handler)) { /* Call close handlers */
int fd;
{
FD_ENTRY *conn = &fd_table[fd];
- RWStateCallbackAndFree(fd, conn->rwstate, COMM_ERROR);
+ RWStateCallbackAndFree(fd, COMM_ERROR);
memset(conn, 0, sizeof(FD_ENTRY));
return 0;
}
} else {
/* Len == 0 means connection closed; otherwise would not have been
* called by comm_select(). */
- debug(5, len == 0 ? 2 : 1, "commHandleRead: FD %d: read failure: %s\n",
- fd, len == 0 ? "connection closed" : xstrerror());
- fd_table[fd].rwstate = NULL; /* handler may issue new read */
- RWStateCallbackAndFree(fd, state, COMM_ERROR);
+ debug(5, len == 0 ? 2 : 1,
+ "commHandleRead: FD %d: read failure: %s\n",
+ fd,
+ len == 0 ? "connection closed" : xstrerror());
+ RWStateCallbackAndFree(fd, COMM_ERROR);
return COMM_ERROR;
}
}
/* Call handler if we have read enough */
if (state->offset >= state->size || state->handle_immed) {
- fd_table[fd].rwstate = NULL; /* handler may issue new read */
- RWStateCallbackAndFree(fd, state, COMM_OK);
+ RWStateCallbackAndFree(fd, COMM_OK);
} else {
/* Reschedule until we are done */
comm_set_select_handler(fd,
if (fd_table[fd].rwstate) {
debug(5, 1, "comm_read: WARNING! FD %d: A comm_read/comm_write is already active.\n", fd);
- RWStateCallbackAndFree(fd, fd_table[fd].rwstate, COMM_ERROR);
+ RWStateCallbackAndFree(fd, COMM_ERROR);
}
state = xcalloc(1, sizeof(RWStateData));
- fd_table[fd].rwstate = state;
state->buf = buf;
state->size = size;
state->offset = 0;
state->time = squid_curtime;
state->handler_data = handler_data;
state->free = NULL;
+ fd_table[fd].rwstate = state;
comm_set_select_handler(fd,
COMM_SELECT_READ,
(PF) commHandleRead,
/* We're done */
if (nleft != 0)
debug(5, 2, "commHandleWrite: FD %d: write failure: connection closed with %d bytes remaining.\n", fd, nleft);
- fd_table[fd].rwstate = NULL;
- RWStateCallbackAndFree(fd, state, nleft ? COMM_ERROR : COMM_OK);
+ RWStateCallbackAndFree(fd, nleft ? COMM_ERROR : COMM_OK);
} else if (len < 0) {
/* An error */
if (errno == EWOULDBLOCK || errno == EAGAIN) {
} else {
debug(5, 2, "commHandleWrite: FD %d: write failure: %s.\n",
fd, xstrerror());
- fd_table[fd].rwstate = NULL;
- RWStateCallbackAndFree(fd, state, COMM_ERROR);
+ RWStateCallbackAndFree(fd, COMM_ERROR);
}
} else {
/* A successful write, continue */
(PF) commHandleWrite,
state);
} else {
- fd_table[fd].rwstate = NULL;
- RWStateCallbackAndFree(fd, state, COMM_OK);
+ RWStateCallbackAndFree(fd, COMM_OK);
}
}
}
if (fd_table[fd].rwstate) {
debug(5, 1, "comm_write: WARNING! FD %d: A comm_read/comm_write is already active.\n", fd);
- RWStateCallbackAndFree(fd, fd_table[fd].rwstate, COMM_ERROR);
+ RWStateCallbackAndFree(fd, COMM_ERROR);
}
state = xcalloc(1, sizeof(RWStateData));
state->buf = buf;
state->time = squid_curtime;
state->handler_data = handler_data;
state->free = free;
+ fd_table[fd].rwstate = state;
comm_set_select_handler(fd,
COMM_SELECT_WRITE,
(PF) commHandleWrite,
- fd_table[fd].rwstate = state);
+ fd_table[fd].rwstate);
}