Skip to content

Commit

Permalink
lib-http: client: Added settings to configure the connection's socket…
Browse files Browse the repository at this point in the history
… kernel buffer sizes.

This is mainly useful for use in the lib-http test suite.
  • Loading branch information
stephanbosch committed May 26, 2016
1 parent 8848174 commit c972eaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib-http/http-client-connection.c
Expand Up @@ -1184,6 +1184,7 @@ http_client_connection_connected(struct connection *_conn, bool success)
{
struct http_client_connection *conn =
(struct http_client_connection *)_conn;
const struct http_client_settings *set = &conn->client->set;
const char *error;

if (!success) {
Expand All @@ -1192,6 +1193,18 @@ http_client_connection_connected(struct connection *_conn, bool success)
} else {
conn->connected_timestamp = ioloop_timeval;
http_client_connection_debug(conn, "Connected");

if (set->socket_send_buffer_size > 0) {
if (net_set_send_buffer_size(_conn->fd_out,
set->socket_send_buffer_size) < 0)
i_error("net_set_send_buffer_size() failed: %m");
}
if (set->socket_recv_buffer_size > 0) {
if (net_set_recv_buffer_size(_conn->fd_in,
set->socket_recv_buffer_size) < 0)
i_error("net_set_recv_buffer_size() failed: %m");
}

if (http_client_peer_addr_is_https(&conn->peer->addr)) {
if (http_client_connection_ssl_init(conn, &error) < 0) {
http_client_peer_connection_failure(conn->peer, error);
Expand Down
2 changes: 2 additions & 0 deletions src/lib-http/http-client.c
Expand Up @@ -145,6 +145,8 @@ struct http_client *http_client_init(const struct http_client_settings *set)
client->set.connect_timeout_msecs = set->connect_timeout_msecs;
client->set.soft_connect_timeout_msecs = set->soft_connect_timeout_msecs;
client->set.max_auto_retry_delay = set->max_auto_retry_delay;
client->set.socket_send_buffer_size = set->socket_send_buffer_size;
client->set.socket_recv_buffer_size = set->socket_recv_buffer_size;
client->set.debug = set->debug;

i_array_init(&client->delayed_failing_requests, 1);
Expand Down
6 changes: 6 additions & 0 deletions src/lib-http/http-client.h
Expand Up @@ -109,6 +109,12 @@ struct http_client_settings {
is not automatically retried and the response is returned */
unsigned int max_auto_retry_delay;

/* the kernel send/receive buffer sizes used for the connection sockets.
Configuring this is mainly useful for the test suite. The kernel
defaults are used when these settings are 0. */
size_t socket_send_buffer_size;
size_t socket_recv_buffer_size;

/* enable logging debug messages */
bool debug;
};
Expand Down

0 comments on commit c972eaa

Please sign in to comment.