diff options
author | Linus Nordberg <linus@nordu.net> | 2011-03-06 17:08:41 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2011-03-06 17:08:41 +0100 |
commit | f082f0d0617d12854a5fd0dc683d357144e36c5c (patch) | |
tree | 71f49620ab48fbba4b82a0a153f2597e3ff0de2b /lib/tcp.c | |
parent | 43d0740f143ba737a1fc5ace3a323ffa8b09e7ae (diff) |
Move event_set_timeout --> tcp_set_connect_timeout.
Diffstat (limited to 'lib/tcp.c')
-rw-r--r-- | lib/tcp.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -23,6 +23,24 @@ #include <event2/buffer.h> #endif +static void +_conn_timeout_cb (int fd, short event, void *data) +{ + struct rs_connection *conn; + + assert (data); + conn = (struct rs_connection *) data; + + if (event & EV_TIMEOUT) + { + rs_debug (("%s: connection timeout on %p (fd %d) connecting to %p\n", + __func__, conn, conn->fd, conn->active_peer)); + conn->is_connecting = 0; + rs_err_conn_push_fl (conn, RSE_TIMEOUT_IO, __FILE__, __LINE__, NULL); + event_loopbreak (conn); + } +} + static int _close_conn (struct rs_connection **connp) { @@ -274,3 +292,19 @@ tcp_write_cb (struct bufferevent *bev, void *ctx) pkt->conn->callbacks.sent_cb (pkt->conn->user_data); } +int +tcp_set_connect_timeout (struct rs_connection *conn) +{ + struct timeval tv; + + if (!conn->tev) + conn->tev = evtimer_new (conn->evb, _conn_timeout_cb, conn); + if (!conn->tev) + return rs_err_conn_push_fl (conn, RSE_EVENT, __FILE__, __LINE__, + "evtimer_new"); + tv.tv_sec = conn->realm->timeout; + tv.tv_usec = 0; + evtimer_add (conn->tev, &tv); + + return RSE_OK; +} |