diff -N -c -r -X exclude_files squid-1.0.beta5/src/connect.c squid-1.0.beta5.henrik/src/connect.c *** squid-1.0.beta5/src/connect.c Tue Apr 30 12:52:55 1996 --- squid-1.0.beta5.henrik/src/connect.c Tue Apr 30 14:31:47 1996 *************** *** 19,24 **** --- 19,27 ---- int remote; int client; time_t timeout; + int closed; + int (*real_close_handler)(); /* The ICP close handler */ + void *real_close_data; /* The ICP data */ } ConnectData; static char conn_established[] = "HTTP/1.0 200 Connection established\r\n\r\n"; *************** *** 31,47 **** static void connectConnected _PARAMS((int fd, ConnectData * data)); static void connectConnInProgress _PARAMS((int fd, ConnectData * data)); ! /* This will be called when socket lifetime is expired. */ static void connectLifetimeExpire(fd, data) int fd; ConnectData *data; { debug(26, 4, "connectLifeTimeExpire: FD %d: \n", fd, data->entry->url); comm_close(fd); } ! /* This will be called when data is ready to be read from fd. Read until ! * error or connection closed. */ static void connectReadRemote(fd, data) int fd; ConnectData *data; --- 34,52 ---- static void connectConnected _PARAMS((int fd, ConnectData * data)); static void connectConnInProgress _PARAMS((int fd, ConnectData * data)); ! /* This will be called when remote socket lifetime is expired. */ static void connectLifetimeExpire(fd, data) int fd; ConnectData *data; { debug(26, 4, "connectLifeTimeExpire: FD %d: \n", fd, data->entry->url); + if (fd==data->remote) + squid_error_entry(data->entry, ERR_LIFETIME_EXP, NULL); comm_close(fd); } ! /* This will be called when data is ready to be read from remote fd. Read until ! * error or connection closed. This has to detect client side closes */ static void connectReadRemote(fd, data) int fd; ConnectData *data; *************** *** 134,140 **** } } ! /* This will be called when connect completes. Write request. */ static void connectSendRemote(fd, data) int fd; ConnectData *data; --- 139,147 ---- } } ! /* This will be called when there is data to write to the remote end ! * when all data is written, continue to read from the client ! */ static void connectSendRemote(fd, data) int fd; ConnectData *data; *************** *** 147,157 **** if (len < 0) { debug(26, 2, "connectSendRemote: FD %d: write failure: %s.\n", fd, xstrerror()); comm_close(fd); return; } if ((data->offset += len) >= data->len) { ! /* Done writing */ comm_set_select_handler(data->client, COMM_SELECT_READ, (PF) connectReadClient, --- 154,165 ---- if (len < 0) { debug(26, 2, "connectSendRemote: FD %d: write failure: %s.\n", fd, xstrerror()); + squid_error_entry(data->entry, ERR_CONNECT_FAIL, xstrerror()); comm_close(fd); return; } if ((data->offset += len) >= data->len) { ! /* Schedule client to read more data */ comm_set_select_handler(data->client, COMM_SELECT_READ, (PF) connectReadClient, *************** *** 165,170 **** --- 173,180 ---- } } + /* Read data from client. When data is read, schedule connectSendRemote to + * send the data to the remote */ static void connectReadClient(fd, data) int fd; ConnectData *data; *************** *** 197,210 **** (void *) data); } static void connectReadTimeout(fd, data) int fd; ConnectData *data; { ! squid_error_entry(data->entry, ERR_READ_TIMEOUT, NULL); comm_close(fd); } static void connectConnected(fd, data) int fd; ConnectData *data; --- 207,223 ---- (void *) data); } + /* Read timeout on client or remote fd */ static void connectReadTimeout(fd, data) int fd; ConnectData *data; { ! if(fd==data->remote) ! squid_error_entry(data->entry, ERR_READ_TIMEOUT, NULL); comm_close(fd); } + /* We are connected to the remote */ static void connectConnected(fd, data) int fd; ConnectData *data; *************** *** 222,244 **** (PF) connectReadClient, (void *) data); } ! static int connectStateFree(fd, connectState) int fd; ConnectData *connectState; { if (connectState == NULL) return 1; ! comm_set_select_handler(connectState->client, ! COMM_SELECT_READ, ! NULL, ! NULL); memset(connectState, '\0', sizeof(ConnectData)); safe_free(connectState); return 0; } void connectConnInProgress(fd, data) int fd; ConnectData *data; --- 235,296 ---- (PF) connectReadClient, (void *) data); } ! /* Free state info (when both ends are closed) */ static int connectStateFree(fd, connectState) int fd; ConnectData *connectState; { + + debug(26,4,"connectStateFree: FD %d data=%p\n", fd, connectState); + if (connectState == NULL) return 1; ! if (fd == connectState->client) ! connectState->client=-1; ! else if (fd == connectState->remote) { ! connectState->remote=-1; ! comm_set_select_handler(connectState->client, ! COMM_SELECT_READ, ! NULL, ! NULL); ! } else ! fatal_dump("connectStateFree called on invalid file descriptor\n"); ! ! connectState->closed=1; ! ! if ((connectState->client!=-1) || (connectState->remote!=-1)) ! return 0; ! ! debug(26,7,"connectStateFree: freeing data=%p\n", connectState); ! memset(connectState, '\0', sizeof(ConnectData)); safe_free(connectState); return 0; } + /* Client is closed */ + static int connectClientClosed(fd, connectState) + int fd; + ConnectData *connectState; + { + if (!connectState) + return 1; + + /* Call the ICP close handler */ + connectState->real_close_handler(fd,connectState->real_close_data); + + /* Close remote end */ + if(connectState->remote!=-1) { + storeReleaseRequest(connectState->entry); + comm_close(connectState->remote); + } + + /* And free state info */ + return connectStateFree(fd,connectState); + } + + void connectConnInProgress(fd, data) int fd; ConnectData *data; *************** *** 305,310 **** --- 357,369 ---- data->client = fd; data->timeout = getReadTimeout(); data->remote = sock; + /* Install close handlers */ + data->real_close_handler = fd_table[fd].close_handler; + data->real_close_data = fd_table[fd].close_data; + comm_set_select_handler(fd, + COMM_SELECT_CLOSE, + connectClientClosed, + (void *) data); comm_set_select_handler(sock, COMM_SELECT_CLOSE, connectStateFree, diff -N -c -r -X exclude_files squid-1.0.beta5/src/store.h squid-1.0.beta5.henrik/src/store.h *** squid-1.0.beta5/src/store.h Fri Apr 26 00:06:13 1996 --- squid-1.0.beta5.henrik/src/store.h Tue Apr 30 15:45:03 1996 *************** *** 165,171 **** extern void storeSanityCheck _PARAMS(()); extern void storeComplete _PARAMS((StoreEntry *)); extern int storeInit _PARAMS(()); - extern int storeReleaseEntry _PARAMS((StoreEntry *)); extern int storeClientWaiting _PARAMS((StoreEntry *)); extern int storeAbort _PARAMS((StoreEntry *, char *)); extern void storeAppend _PARAMS((StoreEntry *, char *, int)); --- 165,170 ----