summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-sysdeps-unix.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2006-09-16 15:34:34 +0000
committerHavoc Pennington <hp@redhat.com>2006-09-16 15:34:34 +0000
commit08079a5bdedd6ec91cda413983e4bd3b6ee0252d (patch)
treecbb7fe4a86f449c2595825c720557c955076a874 /dbus/dbus-sysdeps-unix.c
parente24dec0a89a5853cb448fb3037f2658f2b682650 (diff)
2006-09-16 Havoc Pennington <hp@redhat.com>
* dbus/dbus-sysdeps-unix.h: small change to Peter's patch to make dbus-sysdeps-unix-util.c build, add unix-specific sysdeps header. * dbus/dbus-sysdeps.h, dbus-sysdeps-unix.c: patch from Peter Kümmel bug #8249 to make the sysdeps.h read/write/open/close functions specifically for sockets only, and move generic read/write/open/close into unix-specific code.
Diffstat (limited to 'dbus/dbus-sysdeps-unix.c')
-rw-r--r--dbus/dbus-sysdeps-unix.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 51898443..1ce928af 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -24,6 +24,7 @@
#include "dbus-internals.h"
#include "dbus-sysdeps.h"
+#include "dbus-sysdeps-unix.h"
#include "dbus-threads.h"
#include "dbus-protocol.h"
#include "dbus-string.h"
@@ -76,6 +77,54 @@
* @{
*/
+dbus_bool_t
+_dbus_open_socket (int *fd,
+ int domain,
+ int type,
+ int protocol)
+{
+ *fd = socket (domain, type, protocol);
+ return fd >= 0;
+}
+
+dbus_bool_t
+_dbus_close_socket (int fd,
+ DBusError *error)
+{
+ return _dbus_close (fd, error);
+}
+
+int
+_dbus_read_socket (int fd,
+ DBusString *buffer,
+ int count)
+{
+ return _dbus_read (fd, buffer, count);
+}
+
+int
+_dbus_write_socket (int fd,
+ const DBusString *buffer,
+ int start,
+ int len)
+{
+ return _dbus_write (fd, buffer, start, len);
+}
+
+int
+_dbus_write_socket_two (int fd,
+ const DBusString *buffer1,
+ int start1,
+ int len1,
+ const DBusString *buffer2,
+ int start2,
+ int len2)
+{
+ return _dbus_write_two (fd, buffer1, start1, len1,
+ buffer2, start2, len2);
+}
+
+
/**
* Thin wrapper around the read() system call that appends
* the data it reads to the DBusString buffer. It appends
@@ -306,9 +355,8 @@ _dbus_connect_unix_socket (const char *path,
_dbus_verbose ("connecting to unix socket %s abstract=%d\n",
path, abstract);
- fd = socket (PF_UNIX, SOCK_STREAM, 0);
- if (fd < 0)
+ if (!_dbus_open_socket (&fd, PF_UNIX, SOCK_STREAM, 0))
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
@@ -442,9 +490,7 @@ _dbus_listen_unix_socket (const char *path,
_dbus_verbose ("listening on unix socket %s abstract=%d\n",
path, abstract);
- listen_fd = socket (PF_UNIX, SOCK_STREAM, 0);
-
- if (listen_fd < 0)
+ if (!_dbus_open_socket (&listen_fd, PF_UNIX, SOCK_STREAM, 0))
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to create socket \"%s\": %s",
@@ -578,10 +624,9 @@ _dbus_connect_tcp_socket (const char *host,
struct in_addr *haddr;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
- fd = socket (AF_INET, SOCK_STREAM, 0);
-
- if (fd < 0)
+ if (!_dbus_open_socket (&fd, AF_INET, SOCK_STREAM, 0))
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
@@ -658,9 +703,8 @@ _dbus_listen_tcp_socket (const char *host,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- listen_fd = socket (AF_INET, SOCK_STREAM, 0);
- if (listen_fd < 0)
+ if (!_dbus_open_socket (&listen_fd, AF_INET, SOCK_STREAM, 0))
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to create socket \"%s:%d\": %s",