summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2015-10-28 10:30:32 +0100
committerAndreas Schneider <asn@samba.org>2015-10-28 11:03:15 +0100
commitf649d0c5250867bf3d30d8f3059c3fbd75e17dd0 (patch)
tree4b3d328e69e69efb422773f4ac77a1c8b9c393d5
parent21cb6c86761c6a2db85a81d85395315d83f0cb52 (diff)
downloadsocket_wrapper-f649d0c5250867bf3d30d8f3059c3fbd75e17dd0.tar.gz
socket_wrapper-f649d0c5250867bf3d30d8f3059c3fbd75e17dd0.tar.xz
socket_wrapper-f649d0c5250867bf3d30d8f3059c3fbd75e17dd0.zip
swrap: Add a wrapper for write()
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--src/socket_wrapper.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 3c0c279..b43c877 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -398,6 +398,7 @@ struct swrap_libc_fns {
#ifdef HAVE_TIMERFD_CREATE
int (*libc_timerfd_create)(int clockid, int flags);
#endif
+ ssize_t (*libc_write)(int fd, const void *buf, size_t count);
ssize_t (*libc_writev)(int fd, const struct iovec *iov, int iovcnt);
};
@@ -837,6 +838,13 @@ static int libc_timerfd_create(int clockid, int flags)
}
#endif
+static ssize_t libc_write(int fd, const void *buf, size_t count)
+{
+ swrap_load_lib_function(SWRAP_LIBC, write);
+
+ return swrap.fns.libc_write(fd, buf, count);
+}
+
static ssize_t libc_writev(int fd, const struct iovec *iov, int iovcnt)
{
swrap_load_lib_function(SWRAP_LIBSOCKET, writev);
@@ -4544,6 +4552,58 @@ ssize_t read(int s, void *buf, size_t len)
}
/****************************************************************************
+ * WRITE
+ ***************************************************************************/
+
+static ssize_t swrap_write(int s, const void *buf, size_t len)
+{
+ struct msghdr msg;
+ struct iovec tmp;
+ struct sockaddr_un un_addr;
+ ssize_t ret;
+ int rc;
+ struct socket_info *si;
+
+ si = find_socket_info(s);
+ if (si == NULL) {
+ return libc_write(s, buf, len);
+ }
+
+ tmp.iov_base = discard_const_p(char, buf);
+ tmp.iov_len = len;
+
+ ZERO_STRUCT(msg);
+ msg.msg_name = NULL; /* optional address */
+ msg.msg_namelen = 0; /* size of address */
+ msg.msg_iov = &tmp; /* scatter/gather array */
+ msg.msg_iovlen = 1; /* # elements in msg_iov */
+#if HAVE_STRUCT_MSGHDR_MSG_CONTROL
+ msg.msg_control = NULL; /* ancillary data, see below */
+ msg.msg_controllen = 0; /* ancillary data buffer len */
+ msg.msg_flags = 0; /* flags on received message */
+#endif
+
+ rc = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, NULL, NULL, NULL);
+ if (rc < 0) {
+ return -1;
+ }
+
+ buf = msg.msg_iov[0].iov_base;
+ len = msg.msg_iov[0].iov_len;
+
+ ret = libc_write(s, buf, len);
+
+ swrap_sendmsg_after(s, si, &msg, NULL, ret);
+
+ return ret;
+}
+
+ssize_t write(int s, const void *buf, size_t len)
+{
+ return swrap_write(s, buf, len);
+}
+
+/****************************************************************************
* SEND
***************************************************************************/