/* Called to close a given filedescriptor */ void fd_close(int fd) { fde_t *F = &fd_table[fd]; s_assert(F->flags.open); /* All disk fd's MUST go through file_close() ! */ s_assert(F->type != FD_FILE); if(F->type == FD_FILE) { s_assert(F->read_handler == NULL); s_assert(F->write_handler == NULL); } comm_setselect(F->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0); comm_setflush(F->fd, 0, NULL, NULL); if (F->dns_query != NULL) { delete_adns_queries(F->dns_query); MyFree(F->dns_query); F->dns_query = NULL; } F->flags.open = 0; fdlist_update_biggest(fd, 0); number_fd--; memset(F, '\0', sizeof(fde_t)); F->timeout = 0; /* Unlike squid, we're actually closing the FD here! -- adrian */ close(fd); }
/* * comm_checktimeouts() - check the socket timeouts * * All this routine does is call the given callback/cbdata, without closing * down the file descriptor. When close handlers have been implemented, * this will happen. */ void comm_checktimeouts(void *notused) { int fd; PF *hdl; void *data; fde_t *F; for (fd = 0; fd <= highest_fd; fd++) { F = &fd_table[fd]; if(!F->flags.open) continue; if(F->flags.closing) continue; /* check flush functions */ if(F->flush_handler && F->flush_timeout > 0 && F->flush_timeout < CurrentTime) { hdl = F->flush_handler; data = F->flush_data; comm_setflush(F->fd, 0, NULL, NULL); hdl(F->fd, data); } /* check timeouts */ if(F->timeout_handler && F->timeout > 0 && F->timeout < CurrentTime) { /* Call timeout handler */ hdl = F->timeout_handler; data = F->timeout_data; comm_settimeout(F->fd, 0, NULL, NULL); hdl(F->fd, data); } } }
/* * comm_checktimeouts() - check the socket timeouts * * All this routine does is call the given callback/cbdata, without closing * down the file descriptor. When close handlers have been implemented, * this will happen. */ void comm_checktimeouts(void *notused) { int i; fde_t *F; PF *hdl; void *data; for (i = 0; i < FD_HASH_SIZE; i++) for (F = fd_hash[i]; F != NULL; F = fd_next_in_loop) { assert(F->flags.open); fd_next_in_loop = F->hnext; /* check flush functions */ if (F->flush_handler && F->flush_timeout > 0 && F->flush_timeout < CurrentTime) { hdl = F->flush_handler; data = F->flush_data; comm_setflush(F, 0, NULL, NULL); hdl(F, data); } /* check timeouts */ if (F->timeout_handler && F->timeout > 0 && F->timeout < CurrentTime) { /* Call timeout handler */ hdl = F->timeout_handler; data = F->timeout_data; comm_settimeout(F, 0, NULL, NULL); hdl(F, data); } } }