summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-10-06 10:21:51 -0300
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2008-10-06 10:21:51 -0300
commite67f2377509cf88a1d5e3d339afe93ace97e85d5 (patch)
tree862f300dd6ccad495c7f5046820f545d9f1494ac /common
parent7cfc028f6c1f7dfce7fa3b10f8ba9b49aa806c09 (diff)
Make sco_connect to use sco_bind.
Diffstat (limited to 'common')
-rw-r--r--common/glib-helper.c80
1 files changed, 34 insertions, 46 deletions
diff --git a/common/glib-helper.c b/common/glib-helper.c
index 3ccadbcf..330bbf72 100644
--- a/common/glib-helper.c
+++ b/common/glib-helper.c
@@ -739,6 +739,38 @@ static int transport_connect(BtIO *io, struct sockaddr *addr,
return 0;
}
+static int sco_bind(struct io_context *io_ctxt, const char *address,
+ uint16_t mtu, struct sockaddr_sco *addr)
+{
+ int err;
+ struct sco_options sco_opt;
+
+ io_ctxt->fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
+ if (io_ctxt->fd < 0)
+ return -errno;
+
+ memset(addr, 0, sizeof(*addr));
+ addr->sco_family = AF_BLUETOOTH;
+ str2ba(address, &addr->sco_bdaddr);
+
+ err = bind(io_ctxt->fd, (struct sockaddr *) addr, sizeof(*addr));
+ if (err < 0) {
+ close(io_ctxt->fd);
+ return -errno;
+ }
+
+ if (mtu) {
+ socklen_t olen = sizeof(sco_opt);
+ memset(&sco_opt, 0, olen);
+ getsockopt(io_ctxt->fd, SOL_SCO, SCO_OPTIONS, &sco_opt, &olen);
+ sco_opt.mtu = mtu;
+ setsockopt(io_ctxt->fd, SOL_SCO, SCO_OPTIONS, &sco_opt,
+ sizeof(sco_opt));
+ }
+
+ return 0;
+}
+
static BtIOError sco_connect(BtIO *io, BtIOFunc func)
{
struct io_context *io_ctxt = io->io_ctxt;
@@ -747,21 +779,9 @@ static BtIOError sco_connect(BtIO *io, BtIOFunc func)
io_ctxt->func = func;
- sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
- if (sk < 0)
- return -errno;
-
- memset(&addr, 0, sizeof(addr));
- addr.sco_family = AF_BLUETOOTH;
- str2ba(io->src, &addr.sco_bdaddr);
-
- err = bind(sk, (struct sockaddr *) &addr, sizeof(addr));
- if (err < 0) {
- close(sk);
+ err = sco_bind(io_ctxt, io->src, 0, &addr);
+ if (err < 0)
return BT_IO_FAILED;
- }
-
- io_ctxt->fd = sk;
memset(&addr, 0, sizeof(addr));
addr.sco_family = AF_BLUETOOTH;
@@ -961,38 +981,6 @@ static BtIOError rfcomm_connect(BtIO *io, BtIOFunc func)
return BT_IO_SUCCESS;
}
-static int sco_bind(struct io_context *io_ctxt, const char *address,
- uint16_t mtu, struct sockaddr_sco *addr)
-{
- int err;
- struct sco_options sco_opt;
-
- io_ctxt->fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
- if (io_ctxt->fd < 0)
- return -errno;
-
- if (mtu) {
- socklen_t olen = sizeof(sco_opt);
- memset(&sco_opt, 0, olen);
- getsockopt(io_ctxt->fd, SOL_SCO, SCO_OPTIONS, &sco_opt, &olen);
- sco_opt.mtu = mtu;
- setsockopt(io_ctxt->fd, SOL_SCO, SCO_OPTIONS, &sco_opt,
- sizeof(sco_opt));
- }
-
- memset(addr, 0, sizeof(*addr));
- addr->sco_family = AF_BLUETOOTH;
- str2ba(address, &addr->sco_bdaddr);
-
- err = bind(io_ctxt->fd, (struct sockaddr *) addr, sizeof(*addr));
- if (err < 0) {
- close(io_ctxt->fd);
- return -errno;
- }
-
- return 0;
-}
-
static BtIOError sco_listen(BtIO *io, BtIOFunc func)
{
struct io_context *io_ctxt = io->io_ctxt;