req->cp->tcp_is_reading = 0;
comm_point_stop_listening(req->cp);
comm_point_start_listening(req->cp, -1,
- req->cp->tcp_timeout_msec);
+ adjusted_tcp_timeout(req->cp));
} else if(rd) {
req->cp->tcp_is_reading = 1;
comm_point_stop_listening(req->cp);
comm_point_start_listening(req->cp, -1,
- req->cp->tcp_timeout_msec);
+ adjusted_tcp_timeout(req->cp));
/* and also read it (from SSL stack buffers), so
* no event read event is expected since the remainder of
* the TLS frame is sitting in the buffers. */
} else {
comm_point_stop_listening(req->cp);
comm_point_start_listening(req->cp, -1,
- req->cp->tcp_timeout_msec);
+ adjusted_tcp_timeout(req->cp));
comm_point_listen_for_rw(req->cp, 0, 0);
}
}
send_it:
c->tcp_is_reading = 0;
comm_point_stop_listening(c);
- comm_point_start_listening(c, -1, c->tcp_timeout_msec);
+ comm_point_start_listening(c, -1, adjusted_tcp_timeout(c));
return;
}
req->in_worker_handle = 0;
/* switch to listen to write events */
comm_point_stop_listening(req->cp);
comm_point_start_listening(req->cp, -1,
- req->cp->tcp_timeout_msec);
+ adjusted_tcp_timeout(req->cp));
return;
}
/* queue up the answer behind the others already pending */
}
}
+int adjusted_tcp_timeout(struct comm_point* c)
+{
+ if(c->tcp_timeout_msec < TCP_QUERY_TIMEOUT_MINIMUM)
+ return TCP_QUERY_TIMEOUT_MINIMUM;
+ return c->tcp_timeout_msec;
+}
+
/** Use a new tcp handler for new query fd, set to read query */
static void
setup_tcp_handler(struct comm_point* c, int fd, int cur, int max)
c->tcp_timeout_msec /= 500;
else if (handler_usage > 80)
c->tcp_timeout_msec = 0;
- comm_point_start_listening(c, fd,
- c->tcp_timeout_msec < TCP_QUERY_TIMEOUT_MINIMUM
- ? TCP_QUERY_TIMEOUT_MINIMUM
- : c->tcp_timeout_msec);
+ comm_point_start_listening(c, fd, adjusted_tcp_timeout(c));
}
void comm_base_handle_slow_accept(int ATTR_UNUSED(fd),
if( (*c->callback)(c, c->cb_arg, NETEVENT_PKT_WRITTEN,
&c->repinfo) ) {
comm_point_start_listening(c, -1,
- c->tcp_timeout_msec);
+ adjusted_tcp_timeout(c));
}
} else {
- comm_point_start_listening(c, -1, c->tcp_timeout_msec);
+ comm_point_start_listening(c, -1,
+ adjusted_tcp_timeout(c));
}
}
}
comm_point_stop_listening(c);
fptr_ok(fptr_whitelist_comm_point(c->callback));
if( (*c->callback)(c, c->cb_arg, NETEVENT_NOERROR, &c->repinfo) ) {
- comm_point_start_listening(c, -1, c->tcp_timeout_msec);
+ comm_point_start_listening(c, -1,
+ adjusted_tcp_timeout(c));
}
}
}
if(nghttp2_session_want_write(c->h2_session->session)) {
c->tcp_is_reading = 0;
comm_point_stop_listening(c);
- comm_point_start_listening(c, -1, c->tcp_timeout_msec);
+ comm_point_start_listening(c, -1, adjusted_tcp_timeout(c));
} else if(!nghttp2_session_want_read(c->h2_session->session))
return 0; /* connection can be closed */
return 1;
if(nghttp2_session_want_read(c->h2_session->session)) {
c->tcp_is_reading = 1;
comm_point_stop_listening(c);
- comm_point_start_listening(c, -1, c->tcp_timeout_msec);
+ comm_point_start_listening(c, -1, adjusted_tcp_timeout(c));
} else if(!nghttp2_session_want_write(c->h2_session->session))
return 0; /* connection can be closed */
return 1;
repinfo->c->tcp_is_reading = 0;
comm_point_stop_listening(repinfo->c);
comm_point_start_listening(repinfo->c, -1,
- repinfo->c->tcp_timeout_msec);
+ adjusted_tcp_timeout(repinfo->c));
return;
} else {
comm_point_start_listening(repinfo->c, -1,
- repinfo->c->tcp_timeout_msec);
+ adjusted_tcp_timeout(repinfo->c));
}
}
}
*/
void comm_point_listen_for_rw(struct comm_point* c, int rd, int wr);
+/**
+ * For TCP handlers that use c->tcp_timeout_msec, this routine adjusts
+ * it with the minimum. Otherwise, a 0 value advertised without the
+ * minimum applied moves to a 0 in comm_point_start_listening and that
+ * routine treats it as no timeout, listen forever, which is not wanted.
+ * @param c: comm point to use the tcp_timeout_msec of.
+ * @return adjusted tcp_timeout_msec value with the minimum if smaller.
+ */
+int adjusted_tcp_timeout(struct comm_point* c);
+
/**
* Get size of memory used by comm point.
* For TCP handlers this includes subhandlers.