fix timeout not being applied to outgoing connections
the fix in 0b9a74c290
was incomplete, as it
applied the socket timeout only to the socket received from accept(), but
not to sockets created for outgoing connections.
This commit is contained in:
parent
d3d8943fe4
commit
79d0b0fa79
11
src/reqs.c
11
src/reqs.c
@ -1517,6 +1517,9 @@ static void handle_connection_failure(struct conn_s *connptr, int got_headers)
|
|||||||
* when we start the relay portion. This makes most of the original
|
* when we start the relay portion. This makes most of the original
|
||||||
* tinyproxy code, which was confusing, redundant. Hail progress.
|
* tinyproxy code, which was confusing, redundant. Hail progress.
|
||||||
* - rjkaes
|
* - rjkaes
|
||||||
|
|
||||||
|
* this function is called directly from child_thread() with the newly
|
||||||
|
* received fd from accept().
|
||||||
*/
|
*/
|
||||||
void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
||||||
{
|
{
|
||||||
@ -1528,7 +1531,6 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
int got_headers = 0, fd = connptr->client_fd;
|
int got_headers = 0, fd = connptr->client_fd;
|
||||||
size_t i;
|
size_t i;
|
||||||
struct request_s *request = NULL;
|
struct request_s *request = NULL;
|
||||||
struct timeval tv;
|
|
||||||
orderedmap hashofheaders = NULL;
|
orderedmap hashofheaders = NULL;
|
||||||
|
|
||||||
char sock_ipaddr[IP_LENGTH];
|
char sock_ipaddr[IP_LENGTH];
|
||||||
@ -1550,12 +1552,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tv.tv_usec = 0;
|
set_socket_timeout(fd);
|
||||||
tv.tv_sec = config->idletimeout;
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*) &tv, sizeof(tv));
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
tv.tv_sec = config->idletimeout;
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*) &tv, sizeof(tv));
|
|
||||||
|
|
||||||
if (connection_loops (addr)) {
|
if (connection_loops (addr)) {
|
||||||
log_message (LOG_CONN,
|
log_message (LOG_CONN,
|
||||||
|
12
src/sock.c
12
src/sock.c
@ -108,6 +108,16 @@ bind_socket_list (int sockfd, sblist *addresses, int family)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_socket_timeout(int fd) {
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
tv.tv_sec = config->idletimeout;
|
||||||
|
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (void*) &tv, sizeof(tv));
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
tv.tv_sec = config->idletimeout;
|
||||||
|
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void*) &tv, sizeof(tv));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open a connection to a remote host. It's been re-written to use
|
* Open a connection to a remote host. It's been re-written to use
|
||||||
* the getaddrinfo() library function, which allows for a protocol
|
* the getaddrinfo() library function, which allows for a protocol
|
||||||
@ -163,6 +173,8 @@ int opensock (const char *host, int port, const char *bind_to)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_socket_timeout(sockfd);
|
||||||
|
|
||||||
if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0) {
|
if (connect (sockfd, res->ai_addr, res->ai_addrlen) == 0) {
|
||||||
union sockaddr_union *p = (void*) res->ai_addr, u;
|
union sockaddr_union *p = (void*) res->ai_addr, u;
|
||||||
int af = res->ai_addr->sa_family;
|
int af = res->ai_addr->sa_family;
|
||||||
|
@ -56,6 +56,8 @@ extern int listen_sock (const char *addr, uint16_t port, sblist* listen_fds);
|
|||||||
extern int socket_nonblocking (int sock);
|
extern int socket_nonblocking (int sock);
|
||||||
extern int socket_blocking (int sock);
|
extern int socket_blocking (int sock);
|
||||||
|
|
||||||
|
extern void set_socket_timeout(int fd);
|
||||||
|
|
||||||
extern int getsock_ip (int fd, char *ipaddr);
|
extern int getsock_ip (int fd, char *ipaddr);
|
||||||
extern void getpeer_information (union sockaddr_union *addr, char *ipaddr, size_t ipaddr_len);
|
extern void getpeer_information (union sockaddr_union *addr, char *ipaddr, size_t ipaddr_len);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user