From: wessels <> Date: Thu, 12 Sep 1996 04:26:23 +0000 (+0000) Subject: fix up RWStateCallbackAndFree(). Now NULL out fd_table[fd].rwstate X-Git-Tag: SQUID_3_0_PRE1~5842 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a56a3abebcf14ed6ce35c87be4cbf7208db9ea4e;p=thirdparty%2Fsquid.git fix up RWStateCallbackAndFree(). Now NULL out fd_table[fd].rwstate in RWStateCallbackAndFree() to prevent doub-calls. --- diff --git a/src/comm.cc b/src/comm.cc index a08476c73b..4fc87af2eb 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -145,7 +145,7 @@ static int examine_select _PARAMS((fd_set *, fd_set *, fd_set *)); 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 @@ -154,12 +154,13 @@ static void commSetTcpRcvbuf _PARAMS((int, int)); 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) { @@ -497,7 +498,7 @@ void comm_close(fd) 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 */ @@ -515,7 +516,7 @@ int comm_cleanup_fd_entry(fd) 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; } @@ -1246,10 +1247,11 @@ static int commHandleRead(fd, state) } 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; } } @@ -1257,8 +1259,7 @@ static int commHandleRead(fd, state) /* 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, @@ -1287,10 +1288,9 @@ void comm_read(fd, buf, size, timeout, immed, handler, handler_data) 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; @@ -1300,6 +1300,7 @@ void comm_read(fd, buf, size, timeout, immed, handler, handler_data) 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, @@ -1325,8 +1326,7 @@ static void commHandleWrite(fd, state) /* 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) { @@ -1339,8 +1339,7 @@ static void commHandleWrite(fd, state) } 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 */ @@ -1352,8 +1351,7 @@ static void commHandleWrite(fd, state) (PF) commHandleWrite, state); } else { - fd_table[fd].rwstate = NULL; - RWStateCallbackAndFree(fd, state, COMM_OK); + RWStateCallbackAndFree(fd, COMM_OK); } } } @@ -1378,7 +1376,7 @@ void comm_write(fd, buf, size, timeout, handler, handler_data, free) 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; @@ -1389,8 +1387,9 @@ void comm_write(fd, buf, size, timeout, handler, handler_data, free) 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); }