diff options
author | Linus Nordberg <linus@nordberg.se> | 2013-05-15 11:57:09 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2013-05-15 11:57:09 +0200 |
commit | 65b62d83ee72012d1171f1813b8f989f8805497c (patch) | |
tree | d90452346d8a2c8cba610315f483ef50fed0b698 /lib/conn.c | |
parent | fed9094cd8cda69605d0c103acd14308379b6eb0 (diff) |
Don't crash on reading invalid messages.
Also, invoke disconnected callback and close connection in error
cases.
Diffstat (limited to 'lib/conn.c')
-rw-r--r-- | lib/conn.c | 32 |
1 files changed, 19 insertions, 13 deletions
@@ -20,19 +20,6 @@ #include "tcp.h" int -conn_close (struct rs_connection **connp) -{ - int r = 0; - assert (connp); - assert (*connp); - if ((*connp)->is_connected) - r = rs_conn_disconnect (*connp); - if (r == RSE_OK) - *connp = NULL; - return r; -} - -int conn_user_dispatch_p (const struct rs_connection *conn) { assert (conn); @@ -145,6 +132,25 @@ rs_conn_disconnect (struct rs_connection *conn) assert (conn); + if (conn->is_connected) + event_on_disconnect (conn); + + if (conn->bev) + { + bufferevent_free (conn->bev); + conn->bev = NULL; + } + if (conn->rev) + { + event_free (conn->rev); + conn->rev = NULL; + } + if (conn->wev) + { + event_free (conn->wev); + conn->wev = NULL; + } + err = evutil_closesocket (conn->fd); conn->fd = -1; return err; |