summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/headset.c28
-rw-r--r--common/dbus.c29
-rw-r--r--common/dbus.h2
-rw-r--r--hcid/dbus-rfcomm.c28
-rw-r--r--input/input-service.c28
5 files changed, 32 insertions, 83 deletions
diff --git a/audio/headset.c b/audio/headset.c
index 1e7a6aad..55a47e8e 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -132,34 +132,6 @@ static DBusHandlerResult hs_stop(struct headset *hs, DBusMessage *msg);
static void hs_signal(struct headset *hs, const char *name);
static void hs_signal_gain_setting(struct headset *hs, const char *buf);
-static int set_nonblocking(int fd, int *err)
-{
- long arg;
-
- arg = fcntl(fd, F_GETFL);
- if (arg < 0) {
- if (err)
- *err = errno;
- error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
- return -1;
- }
-
- /* Return if already nonblocking */
- if (arg & O_NONBLOCK)
- return 0;
-
- arg |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, arg) < 0) {
- if (err)
- *err = errno;
- error("fcntl(F_SETFL, O_NONBLOCK): %s (%d)",
- strerror(errno), errno);
- return -1;
- }
-
- return 0;
-}
-
static void pending_connect_free(struct pending_connect *c)
{
if (c->io)
diff --git a/common/dbus.c b/common/dbus.c
index 7837aeba..92a86e73 100644
--- a/common/dbus.c
+++ b/common/dbus.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <errno.h>
+#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
@@ -643,3 +644,31 @@ DBusHandlerResult simple_introspect(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
+
+int set_nonblocking(int fd, int *err)
+{
+ long arg;
+
+ arg = fcntl(fd, F_GETFL);
+ if (arg < 0) {
+ if (err)
+ *err = errno;
+ error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
+ return -1;
+ }
+
+ /* Return if already nonblocking */
+ if (arg & O_NONBLOCK)
+ return 0;
+
+ arg |= O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, arg) < 0) {
+ if (err)
+ *err = errno;
+ error("fcntl(F_SETFL, O_NONBLOCK): %s (%d)",
+ strerror(errno), errno);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/common/dbus.h b/common/dbus.h
index 801d90c6..d59903ee 100644
--- a/common/dbus.h
+++ b/common/dbus.h
@@ -51,4 +51,6 @@ static inline DBusHandlerResult send_message_and_unref(DBusConnection *conn, DBu
return DBUS_HANDLER_RESULT_HANDLED;
}
+int set_nonblocking(int fd, int *err);
+
#endif /* __H_BLUEZ_DBUS_H__ */
diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c
index 515a55aa..3bae204f 100644
--- a/hcid/dbus-rfcomm.c
+++ b/hcid/dbus-rfcomm.c
@@ -172,34 +172,6 @@ static void pending_connect_free(struct pending_connect *c)
free(c);
}
-static int set_nonblocking(int fd, int *err)
-{
- long arg;
-
- arg = fcntl(fd, F_GETFL);
- if (arg < 0) {
- if (err)
- *err = errno;
- error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
- return -1;
- }
-
- /* Return if already nonblocking */
- if (arg & O_NONBLOCK)
- return 0;
-
- arg |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, arg) < 0) {
- if (err)
- *err = errno;
- error("fcntl(F_SETFL, O_NONBLOCK): %s (%d)",
- strerror(errno), errno);
- return -1;
- }
-
- return 0;
-}
-
static int rfcomm_release(struct rfcomm_node *node, int *err)
{
struct rfcomm_dev_req req;
diff --git a/input/input-service.c b/input/input-service.c
index f14edfe1..c7c07283 100644
--- a/input/input-service.c
+++ b/input/input-service.c
@@ -28,7 +28,6 @@
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
-#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -471,31 +470,6 @@ static const char *create_input_path(uint8_t minor)
return path;
}
-/* FIXME: Move to a common file. It is already used by audio and rfcomm */
-static int set_nonblocking(int fd)
-{
- long arg;
-
- arg = fcntl(fd, F_GETFL);
- if (arg < 0) {
- error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
- return -1;
- }
-
- /* Return if already nonblocking */
- if (arg & O_NONBLOCK)
- return 0;
-
- arg |= O_NONBLOCK;
- if (fcntl(fd, F_SETFL, arg) < 0) {
- error("fcntl(F_SETFL, O_NONBLOCK): %s (%d)",
- strerror(errno), errno);
- return -1;
- }
-
- return 0;
-}
-
static int l2cap_connect(struct pending_connect *pc,
unsigned short psm, GIOFunc cb)
{
@@ -514,7 +488,7 @@ static int l2cap_connect(struct pending_connect *pc,
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0)
goto failed;
- if (set_nonblocking(sk) < 0)
+ if (set_nonblocking(sk, NULL) < 0)
goto failed;
memset(&opts, 0, sizeof(opts));