From f082f0d0617d12854a5fd0dc683d357144e36c5c Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 6 Mar 2011 17:08:41 +0100 Subject: Move event_set_timeout --> tcp_set_connect_timeout. --- lib/tcp.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib/tcp.c') diff --git a/lib/tcp.c b/lib/tcp.c index 2e641f6..acee94b 100644 --- a/lib/tcp.c +++ b/lib/tcp.c @@ -23,6 +23,24 @@ #include #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; +} -- cgit v1.1