summaryrefslogtreecommitdiff
path: root/lib/conn.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-05-15 11:57:09 +0200
committerLinus Nordberg <linus@nordberg.se>2013-05-15 11:57:09 +0200
commit65b62d83ee72012d1171f1813b8f989f8805497c (patch)
treed90452346d8a2c8cba610315f483ef50fed0b698 /lib/conn.c
parentfed9094cd8cda69605d0c103acd14308379b6eb0 (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.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/conn.c b/lib/conn.c
index f89ac70..499c330 100644
--- a/lib/conn.c
+++ b/lib/conn.c
@@ -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;