All pastes #487518 Raw Edit

Mine

public text v1 · immutable
·published 2007-05-14 14:42 UTC
rendered paste body
Index: connection.c
===================================================================
RCS file: /cvsroot/bluez/utils/network/connection.c,v
retrieving revision 1.34
diff -u -3 -p -u -r1.34 connection.c
--- connection.c        14 May 2007 12:28:55 -0000      1.34
+++ connection.c        14 May 2007 14:42:10 -0000
@@ -176,9 +176,11 @@ static gboolean bnep_connect_cb(GIOChann
                        (GIOFunc) bnep_watchdog_cb, nc);
        return FALSE;
 failed:
-       nc->state = DISCONNECTED;
-       err_connection_failed(nc->conn, nc->msg, "bnep failed");
-       g_io_channel_close(chan);
+       if (nc->state != DISCONNECTED) {
+               nc->state = DISCONNECTED;
+               err_connection_failed(nc->conn, nc->msg, "bnep failed");
+               g_io_channel_close(chan);
+       }
        return FALSE;
 }
 
@@ -465,7 +467,7 @@ static DBusHandlerResult connection_conn
        }
 
        nc->msg = dbus_message_ref(msg);
-       if(l2cap_connect(nc)) {
+       if(l2cap_connect(nc) < 0) {
                error("Connect failed. %s(%d)", strerror(errno), errno);
                goto fail;
        }
@@ -481,6 +483,25 @@ fail:
        return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static DBusHandlerResult connection_cancel(DBusConnection *conn,
+                                               DBusMessage *msg, void *data)
+{
+       struct network_conn *nc = data;
+       DBusMessage *reply;
+
+       if (nc->state != CONNECTING) {
+               err_failed(conn, msg, "Device has no pending connect");
+               return DBUS_HANDLER_RESULT_HANDLED;
+       }
+
+       close(nc->sk);
+       nc->state = DISCONNECTED;
+
+       reply = dbus_message_new_method_return(msg);
+
+       return send_message_and_unref(conn, reply);
+}
+
 static DBusHandlerResult connection_disconnect(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -598,6 +619,7 @@ static DBusMethodVTable connection_metho
        { "GetDescription",     get_description,        "",     "s"     },
        { "GetInterface",       get_interface,          "",     "s"     },
        { "Connect",            connection_connect,     "",     "s"     },
+       { "CancelConnect",      connection_cancel,      "",     ""      },
        { "Disconnect",         connection_disconnect,  "",     ""      },
        { "IsConnected",        is_connected,           "",     "b"     },
        { "GetInfo",            get_info,               "",     "{sv}", },