/*
- * $Id: comm.cc,v 1.41 1996/07/20 03:16:49 wessels Exp $
+ * $Id: comm.cc,v 1.42 1996/07/20 03:37:43 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 RWStateFree _PARAMS((int fd, RWStateData *, int code));
+static void RWStateCallbackAndFree _PARAMS((int fd, RWStateData *, int code));
#ifdef TCP_NODELAY
static void commSetTcpNoDelay _PARAMS((int));
#endif
static int *fd_lifetime = NULL;
static struct timeval zero_tv;
-static void RWStateFree(fd, RWState, code)
+static void RWStateCallbackAndFree(fd, RWState, code)
int fd;
RWStateData *RWState;
int code;
fatal_dump(NULL);
}
conn->openned = 0;
- RWStateFree(fd, conn->rstate, COMM_ERROR);
- RWStateFree(fd, conn->wstate, COMM_ERROR);
+ RWStateCallbackAndFree(fd, conn->rwstate, 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];
- RWStateFree(fd, conn->rstate, COMM_ERROR);
- RWStateFree(fd, conn->wstate, COMM_ERROR);
+ RWStateCallbackAndFree(fd, conn->rwstate, COMM_ERROR);
memset(conn, 0, sizeof(FD_ENTRY));
return 0;
}
* 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].rstate = NULL; /* The handler may issue a new read */
- RWStateFree(fd, state, COMM_ERROR);
+ fd_table[fd].rwstate = NULL; /* handler may issue new read */
+ RWStateCallbackAndFree(fd, state, COMM_ERROR);
return COMM_ERROR;
}
}
/* Call handler if we have read enough */
if (state->offset >= state->size || state->handle_immed) {
- fd_table[fd].rstate = NULL; /* The handler may issue a new read */
- RWStateFree(fd, state, COMM_OK);
+ fd_table[fd].rwstate = NULL; /* handler may issue new read */
+ RWStateCallbackAndFree(fd, state, COMM_OK);
} else {
/* Reschedule until we are done */
comm_set_select_handler(fd,
debug(5, 5, "comm_read: FD %d: sz %d: tout %d: hndl %p: data %p.\n",
fd, size, timeout, handler, handler_data);
- if (fd_table[fd].rstate) {
- debug(5, 1, "comm_read: WARNING! FD %d: A comm_read is already active.\n", fd);
- safe_free(fd_table[fd].rstate);
+ 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);
}
state = xcalloc(1, sizeof(RWStateData));
- fd_table[fd].rstate = state;
+ fd_table[fd].rwstate = state;
state->buf = buf;
state->size = size;
state->offset = 0;
/* 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].wstate = NULL;
- RWStateFree(fd, state, nleft ? COMM_ERROR : COMM_OK);
+ fd_table[fd].rwstate = NULL;
+ RWStateCallbackAndFree(fd, state, 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].wstate = NULL;
- RWStateFree(fd, state, COMM_ERROR);
+ fd_table[fd].rwstate = NULL;
+ RWStateCallbackAndFree(fd, state, COMM_ERROR);
}
} else {
/* A successful write, continue */
(PF) commHandleWrite,
state);
} else {
- fd_table[fd].wstate = NULL;
- RWStateFree(fd, state, COMM_OK);
+ fd_table[fd].rwstate = NULL;
+ RWStateCallbackAndFree(fd, state, COMM_OK);
}
}
}
debug(5, 5, "comm_write: FD %d: sz %d: tout %d: hndl %p: data %p.\n",
fd, size, timeout, handler, handler_data);
- if (fd_table[fd].wstate) {
- debug(5, 1, "comm_write: WARNING! FD %d: A comm_write is already active.\n", fd);
- RWStateFree(fd, fd_table[fd].wstate, COMM_ERROR);
+ 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);
}
state = xcalloc(1, sizeof(RWStateData));
state->buf = buf;
comm_set_select_handler(fd,
COMM_SELECT_WRITE,
(PF) commHandleWrite,
- fd_table[fd].wstate = state);
+ fd_table[fd].rwstate = state);
}