MEDIUM: stream-int: implement a very simplistic idle connection manager

Idle connections are not monitored right now. So if a server closes after
a response without advertising it, it won't be detected until a next
request wants to use the connection. This is a bit problematic because
it unnecessarily maintains file descriptors and sockets in an idle
state.

This patch implements a very simple idle connection manager for the stream
interface. It presents itself as an I/O callback. The HTTP engine enables
it when it recycles a connection. If a close or an error is detected on the
underlying socket, it tries to drain as much data as possible from the socket,
detect the close and responds with a close as well, then detaches from the
stream interface.
This commit is contained in:
Willy Tarreau
2013-12-17 00:00:28 +01:00
parent 4bfa4228dc
commit 2737562e43
3 changed files with 68 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ void stream_sock_read0(struct stream_interface *si);
extern struct si_ops si_embedded_ops;
extern struct si_ops si_conn_ops;
extern struct data_cb si_conn_cb;
extern struct data_cb si_idle_conn_cb;
struct appctx *stream_int_register_handler(struct stream_interface *si, struct si_applet *app);
void stream_int_unregister_handler(struct stream_interface *si);
@@ -138,6 +139,21 @@ static inline void si_detach(struct stream_interface *si)
si->ops = &si_embedded_ops;
}
/* Turn a possibly existing connection endpoint of stream interface <si> to
* idle mode, which means that the connection will be polled for incoming events
* and might be killed by the underlying I/O handler.
*/
static inline void si_idle_conn(struct stream_interface *si)
{
struct connection *conn = objt_conn(si->end);
if (!conn)
return;
conn_attach(conn, si, &si_idle_conn_cb);
conn_data_want_recv(conn);
}
/* Attach connection <conn> to the stream interface <si>. The stream interface
* is configured to work with a connection and the connection it configured
* with a stream interface data layer.