[core] POLLRDHUP handling for transparent proxying

personal/stbuehler/fix-fdevent
Glenn Strauss 5 years ago
parent 77d31d8584
commit 769289b954

@ -916,10 +916,17 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven
} else if (revents & FDEVENT_HUP) {
connection_set_state(srv, con, CON_STATE_ERROR);
} else if (revents & FDEVENT_RDHUP) {
int events = fdevent_event_get_interest(srv->ev, con->fd);
events &= ~(FDEVENT_IN|FDEVENT_RDHUP);
con->conf.stream_request_body &= ~(FDEVENT_STREAM_REQUEST_BUFMIN|FDEVENT_STREAM_REQUEST_POLLIN);
con->is_readable = 1; /*(can read 0 for end-of-stream)*/
con->keep_alive = 0;
if (con->request.content_length < -1) { /*(transparent proxy mode; no more data to read)*/
con->request.content_length = con->request_content_queue->bytes_in;
}
if (sock_addr_get_family(&con->dst_addr) == AF_UNIX) {
/* future: will getpeername() on AF_UNIX properly check if still connected? */
fdevent_event_clr(srv->ev, &con->fde_ndx, con->fd, FDEVENT_RDHUP);
con->keep_alive = 0;
fdevent_event_set(srv->ev, &con->fde_ndx, con->fd, events);
} else if (fdevent_is_tcp_half_closed(con->fd)) {
/* Success of fdevent_is_tcp_half_closed() after FDEVENT_RDHUP indicates TCP FIN received,
* but does not distinguish between client shutdown(fd, SHUT_WR) and client close(fd).
@ -928,8 +935,7 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven
* future: might getpeername() to check for TCP RST on half-closed sockets
* (without FDEVENT_RDHUP interest) when checking for write timeouts
* once a second in server.c, though getpeername() on Windows might not indicate this */
fdevent_event_clr(srv->ev, &con->fde_ndx, con->fd, FDEVENT_RDHUP);
con->keep_alive = 0;
fdevent_event_set(srv->ev, &con->fde_ndx, con->fd, events);
} else {
/* Failure of fdevent_is_tcp_half_closed() indicates TCP RST
* (or unable to tell (unsupported OS), though should not

@ -1808,7 +1808,7 @@ static handler_t gw_write_request(server *srv, gw_handler_ctx *hctx) {
/*(disable Nagle algorithm if streaming and content-length unknown)*/
if (AF_UNIX != hctx->host->family) {
connection *con = hctx->remote_conn;
if (-1 == con->request.content_length) {
if (con->request.content_length < 0) {
if (-1 == fdevent_set_tcp_nodelay(hctx->fd, 1)) {
/*(error, but not critical)*/
}

Loading…
Cancel
Save