diff options
author | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-03-26 19:20:49 +0000 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.dentz@openbossa.org> | 2007-03-26 19:20:49 +0000 |
commit | 85a868434ea4de849a15673aa4f132f10d2ab94c (patch) | |
tree | e9021b5e7c9c6f4c2d1d88846117a21024d16fdd /network/connection.c | |
parent | 1e3f6fcf0d53335e6fd8456c11357c5b13d51006 (diff) |
Add connection watchdog.
Diffstat (limited to 'network/connection.c')
-rw-r--r-- | network/connection.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/network/connection.c b/network/connection.c index af3d4090..8f83c68e 100644 --- a/network/connection.c +++ b/network/connection.c @@ -64,6 +64,20 @@ struct __service_16 { uint16_t src; } __attribute__ ((packed)); +static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond, + gpointer data) +{ + struct network_conn *nc = data; + DBusMessage *signal; + + signal = dbus_message_new_signal(nc->path, + NETWORK_CONNECTION_INTERFACE, "Disconnected"); + + send_message_and_unref(nc->conn, signal); + info("%s disconnected", nc->dev); + return (nc->up = FALSE); +} + static gboolean bnep_connect_cb(GIOChannel *chan, GIOCondition cond, gpointer data) { @@ -136,7 +150,9 @@ static gboolean bnep_connect_cb(GIOChannel *chan, GIOCondition cond, nc->up = TRUE; info("%s connected", nc->dev); - g_io_channel_unref(chan); + /* Start watchdog */ + g_io_add_watch(chan, G_IO_ERR | G_IO_HUP | G_IO_NVAL, + (GIOFunc) bnep_watchdog_cb, nc); return FALSE; failed: err_connection_failed(nc->conn, nc->msg, "bnep failed"); @@ -337,7 +353,6 @@ static DBusHandlerResult connection_connect(DBusConnection *conn, DBusMessage *msg, void *data) { struct network_conn *nc = data; - int sk; DBusError derr; dbus_error_init(&derr); @@ -381,14 +396,7 @@ static DBusHandlerResult connection_disconnect(DBusConnection *conn, close(nc->sk); ba2str(&nc->dst, addr); - if (!bnep_kill_connection(addr)) { - signal = dbus_message_new_signal(nc->path, - NETWORK_CONNECTION_INTERFACE, "Disconnected"); - - send_message_and_unref(nc->conn, signal); - info("%s disconnected", nc->dev); - nc->up = FALSE; - } + bnep_kill_connection(addr); reply = dbus_message_new_method_return(msg); if (!reply) |