Skip to content

Commit

Permalink
lib: connection - Add vfunc called when the connection becomes ready …
Browse files Browse the repository at this point in the history
…after handshake.
  • Loading branch information
stephanbosch committed Feb 3, 2019
1 parent e017100 commit 1d886f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib/connection.c
Expand Up @@ -16,6 +16,13 @@
#include <unistd.h>
#include <libgen.h>

static void connection_handshake_ready(struct connection *conn)
{
conn->handshake_received = TRUE;
if (conn->v.handshake_ready != NULL)
conn->v.handshake_ready(conn);
}

static void connection_closed(struct connection *conn,
enum connection_disconnect_reason reason)
{
Expand Down Expand Up @@ -48,7 +55,7 @@ void connection_input_default(struct connection *conn)
} else if (ret == 0) {
return;
} else {
conn->handshake_received = TRUE;
connection_handshake_ready(conn);
}
}

Expand All @@ -75,7 +82,7 @@ void connection_input_default(struct connection *conn)
conn->v.handshake_line != NULL) {
ret = conn->v.handshake_line(conn, line);
if (ret > 0)
conn->handshake_received = TRUE;
connection_handshake_ready(conn);
else if (ret == 0)
/* continue reading */
ret = 1;
Expand Down Expand Up @@ -170,13 +177,13 @@ int connection_input_line_default(struct connection *conn, const char *line)
if ((ret = conn->v.handshake_args(conn, args)) == 0)
ret = 1; /* continue reading */
else if (ret > 0)
conn->handshake_received = TRUE;
connection_handshake_ready(conn);
else
conn->disconnect_reason = CONNECTION_DISCONNECT_HANDSHAKE_FAILED;
return ret;
} else if (!conn->handshake_received) {
/* we don't do handshakes */
conn->handshake_received = TRUE;
connection_handshake_ready(conn);
}

/* version must be handled though, by something */
Expand Down
3 changes: 3 additions & 0 deletions src/lib/connection.h
Expand Up @@ -59,6 +59,9 @@ struct connection_vfuncs {
int (*handshake_line)(struct connection *conn, const char *line);
int (*handshake_args)(struct connection *conn, const char *const *args);

/* Called when the connection handshake is ready. */
void (*handshake_ready)(struct connection *conn);

/* Called when input_idle_timeout_secs is reached, defaults to disconnect */
void (*idle_timeout)(struct connection *conn);
/* Called when client_connect_timeout_msecs is reached, defaults to disconnect */
Expand Down

0 comments on commit 1d886f0

Please sign in to comment.