Skip to content

Commit

Permalink
lib: connection: Add connection_input_halt() and connection_input_res…
Browse files Browse the repository at this point in the history
…ume().

These are convenience functions that remove and add conn->io respectively.
  • Loading branch information
stephanbosch authored and villesavolainen committed Mar 12, 2018
1 parent 99ef56d commit f1d116e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/lib/connection.c
Expand Up @@ -120,6 +120,26 @@ int connection_input_line_default(struct connection *conn, const char *line)
return conn->list->v.input_args(conn, args);
}

void connection_input_halt(struct connection *conn)
{
io_remove(&conn->io);
}

void connection_input_resume(struct connection *conn)
{
const struct connection_settings *set = &conn->list->set;

if (conn->io != NULL)
return;
if (conn->from_streams || set->input_max_size != 0) {
conn->io = io_add_istream_to(conn->ioloop, conn->input,
*conn->list->v.input, conn);
} else {
conn->io = io_add_to(conn->ioloop, conn->fd_in, IO_READ,
*conn->list->v.input, conn);
}
}

static void connection_init_streams(struct connection *conn)
{
const struct connection_settings *set = &conn->list->set;
Expand All @@ -139,11 +159,6 @@ static void connection_init_streams(struct connection *conn)
conn->input = i_stream_create_fd(conn->fd_in,
set->input_max_size);
i_stream_set_name(conn->input, conn->name);
conn->io = io_add_istream_to(conn->ioloop, conn->input,
*conn->list->v.input, conn);
} else {
conn->io = io_add_to(conn->ioloop, conn->fd_in, IO_READ,
*conn->list->v.input, conn);
}
if (set->output_max_size != 0) {
if (conn->unix_socket)
Expand All @@ -158,6 +173,7 @@ static void connection_init_streams(struct connection *conn)
}
i_stream_switch_ioloop_to(conn->input, conn->ioloop);
o_stream_switch_ioloop_to(conn->output, conn->ioloop);
connection_input_resume(conn);
if (set->input_idle_timeout_secs != 0) {
conn->to = timeout_add_to(conn->ioloop,
set->input_idle_timeout_secs*1000,
Expand All @@ -175,9 +191,8 @@ void connection_streams_changed(struct connection *conn)
const struct connection_settings *set = &conn->list->set;

if (set->input_max_size != 0 && conn->io != NULL) {
io_remove(&conn->io);
conn->io = io_add_istream_to(conn->ioloop, conn->input,
*conn->list->v.input, conn);
connection_input_halt(conn);
connection_input_resume(conn);
}
}

Expand Down Expand Up @@ -265,6 +280,7 @@ void connection_init_from_streams(struct connection_list *list,
connection_init(list, conn);

conn->name = i_strdup(name);
conn->from_streams = TRUE;
conn->fd_in = i_stream_get_fd(input);
conn->fd_out = o_stream_get_fd(output);

Expand All @@ -284,7 +300,7 @@ void connection_init_from_streams(struct connection_list *list,
o_stream_set_no_error_handling(conn->output, TRUE);
o_stream_set_name(conn->output, conn->name);

conn->io = io_add_istream(conn->input, *list->v.input, conn);
connection_input_resume(conn);

if (list->v.client_connected != NULL)
list->v.client_connected(conn, TRUE);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/connection.h
Expand Up @@ -102,6 +102,7 @@ struct connection {

bool version_received:1;
bool unix_socket:1;
bool from_streams:1;
};

struct connection_list {
Expand Down Expand Up @@ -131,6 +132,8 @@ int connection_client_connect(struct connection *conn);
void connection_disconnect(struct connection *conn);
void connection_deinit(struct connection *conn);

void connection_input_halt(struct connection *conn);
void connection_input_resume(struct connection *conn);
void connection_streams_changed(struct connection *conn);

/* Returns -1 = disconnected, 0 = nothing new, 1 = something new.
Expand Down

0 comments on commit f1d116e

Please sign in to comment.