tstream_bsd_writev_handler => sendmsg()
authorStefan Metzmacher <metze@samba.org>
Sat, 30 Oct 2010 14:04:36 +0000 (16:04 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 08:28:06 +0000 (10:28 +0200)
lib/tsocket/tsocket_bsd.c

index 708d17edc321094b9423e082cca8a101078a2757..7ebc564692d79b0edfb6fac6733a5a266819e8e1 100644 (file)
@@ -1114,6 +1114,7 @@ static void tdgram_bsd_sendto_handler(void *private_data)
        ssize_t ret;
        int err;
        bool retry;
+       int flags = 0;
 
        if (state->dst) {
                struct tsocket_address_bsd *bsda =
@@ -1124,7 +1125,10 @@ static void tdgram_bsd_sendto_handler(void *private_data)
                sa_socklen = bsda->sa_socklen;
        }
 
-       ret = sendto(bsds->fd, state->buf, state->len, 0, sa, sa_socklen);
+#ifdef MSG_NOSIGNAL
+       flags |= MSG_NOSIGNAL;
+#endif
+       ret = sendto(bsds->fd, state->buf, state->len, flags, sa, sa_socklen);
        err = tsocket_bsd_error_from_errno(ret, errno, &retry);
        if (retry) {
                /* retry later */
@@ -1985,8 +1989,21 @@ static void tstream_bsd_writev_handler(void *private_data)
        int err;
        int _count;
        bool ok, retry;
-
-       ret = writev(bsds->fd, state->vector, state->count);
+       struct msghdr msg;
+       int flags = 0;
+
+       msg.msg_name = NULL;           /* optional address */
+       msg.msg_namelen = 0;           /* size of address */
+       msg.msg_iov = state->vector;   /* scatter/gather array */
+       msg.msg_iovlen = state->count; /* # elements in msg_iov */
+       msg.msg_control = NULL;        /* ancillary data, see below */
+       msg.msg_controllen = 0;        /* ancillary data buffer len */
+       msg.msg_flags = 0;             /* flags on received message */
+
+#ifdef MSG_NOSIGNAL
+       flags |= MSG_NOSIGNAL;
+#endif
+       ret = sendmsg(bsds->fd, &msg, flags);
        if (ret == 0) {
                /* propagate end of file */
                tevent_req_error(req, EPIPE);