summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorUlisses Furquim <ulissesf@gmail.com>2006-09-04 17:16:42 +0000
committerUlisses Furquim <ulissesf@gmail.com>2006-09-04 17:16:42 +0000
commit287671bee4169d7c247b680b59ffe09300e9ae9c (patch)
tree46c6fc13aa19c13b513499ab7d9a833fe902fce2 /hcid
parent3afdb2d2b7e8938e7cf2c225d61e628c04e6310e (diff)
Change to use sdp_connect() to make async searchs
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-sdp.c73
1 files changed, 23 insertions, 50 deletions
diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c
index e0ad16d4..bf60d7fa 100644
--- a/hcid/dbus-sdp.c
+++ b/hcid/dbus-sdp.c
@@ -78,6 +78,7 @@ typedef int connect_cb_t (struct transaction_context *t);
struct pending_connect {
DBusConnection *conn;
DBusMessage *rq;
+ sdp_session_t *session;
char *dst;
connect_cb_t *conn_cb;
};
@@ -766,7 +767,7 @@ static gboolean sdp_client_connect_cb(GIOChannel *chan, GIOCondition cond, void
ctxt->conn = dbus_connection_ref(c->conn);
ctxt->rq = dbus_message_ref(c->rq);
- ctxt->session = sdp_create(sk, 0);
+ ctxt->session = c->session;
/* set the complete transaction callback and starts the search request */
err = c->conn_cb(ctxt);
@@ -791,73 +792,45 @@ done:
return FALSE;
}
-static int connect_request(DBusConnection *conn, DBusMessage *msg, uint16_t dev_id,
- const char *dst, connect_cb_t *cb, int *err)
+static int connect_request(DBusConnection *conn, DBusMessage *msg,
+ uint16_t dev_id, const char *dst,
+ connect_cb_t *cb, int *err)
{
struct pending_connect *c = NULL;
GIOChannel *chan = NULL;
- struct sockaddr_l2 sa;
- int sk, watch = 0;
+ bdaddr_t srcba, dstba;
- // create L2CAP connection
- /* FIXME: use set_nonblocking */
- sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
- if (sk < 0) {
+ c = pending_connect_new(conn, msg, dst, cb);
+ if (!c) {
if (err)
- *err = errno;
-
+ *err = ENOMEM;
return -1;
}
- chan = g_io_channel_unix_new(sk);
- g_io_channel_set_close_on_unref(chan, TRUE);
-
- sa.l2_family = AF_BLUETOOTH;
- sa.l2_psm = 0;
+ hci_devba(dev_id, &srcba);
+ str2ba(dst, &dstba);
- hci_devba(dev_id, &sa.l2_bdaddr);
-
- if (bind(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
+ c->session = sdp_connect(&srcba, &dstba, SDP_NON_BLOCKING);
+ if (!c->session) {
if (err)
*err = errno;
- goto fail;
- }
-
- sa.l2_psm = htobs(SDP_PSM);
- str2ba(dst, &sa.l2_bdaddr);
-
- c = pending_connect_new(conn, msg, dst, cb);
- if (!c) {
- if (err)
- *err = ENOMEM;
- goto fail;
+ error("sdp_connect() failed:%s (%d)", strerror(errno), errno);
+ pending_connect_free(c);
+ return -1;
}
- fcntl(sk, F_SETFL, fcntl(sk, F_GETFL, 0)|O_NONBLOCK);
- if (connect(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
- if (!(errno == EAGAIN || errno == EINPROGRESS)) {
- if (err)
- *err = errno;
- error("connect() failed:%s (%d)", strerror(errno), errno);
- goto fail;
- }
+ chan = g_io_channel_unix_new(c->session->sock);
+ g_io_channel_set_close_on_unref(chan, TRUE);
- watch = g_io_add_watch(chan, G_IO_OUT,
- sdp_client_connect_cb, c);
- pending_connects = slist_append(pending_connects, c);
- } else {
+ if (sdp_is_connected(c->session)) {
sdp_client_connect_cb(chan, G_IO_OUT, c);
+ return 0;
}
- return 0;
-fail:
- if (chan)
- g_io_channel_unref(chan);
+ g_io_add_watch(chan, G_IO_OUT, sdp_client_connect_cb, c);
+ pending_connects = slist_append(pending_connects, c);
- if (c)
- pending_connect_free(c);
-
- return -1;
+ return 0;
}
static int remote_svc_rec_conn_cb(struct transaction_context *ctxt)