]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
async_sock: make use of recvmsg() in read_packet_handler()
authorStefan Metzmacher <metze@samba.org>
Mon, 28 Apr 2025 15:46:44 +0000 (17:46 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 12 May 2025 10:31:30 +0000 (10:31 +0000)
This typically has a better call stack in the kernel.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/async_req/async_sock.c

index 2185961ea3ccbb6e2a1a7547d2eae0eb20551ee0..6cfcafd957881cac848bb70eb9f7fab8a2c1c812 100644 (file)
@@ -449,6 +449,7 @@ ssize_t writev_recv(struct tevent_req *req, int *perrno)
 
 struct read_packet_state {
        int fd;
+       bool is_sock;
        struct tevent_fd *fde;
        uint8_t *buf;
        size_t nread;
@@ -478,6 +479,7 @@ struct tevent_req *read_packet_send(TALLOC_CTX *mem_ctx,
                return NULL;
        }
        state->fd = fd;
+       state->is_sock = true;
        state->nread = 0;
        state->more = more;
        state->private_data = private_data;
@@ -519,9 +521,22 @@ static void read_packet_handler(struct tevent_context *ev,
        ssize_t nread, more;
        uint8_t *tmp;
 
-       nread = recv(state->fd, state->buf+state->nread, total-state->nread,
-                    0);
-       if ((nread == -1) && (errno == ENOTSOCK)) {
+       if (state->is_sock) {
+               struct iovec iov = {
+                       .iov_base = state->buf+state->nread,
+                       .iov_len = total-state->nread,
+               };
+               struct msghdr msg = {
+                       .msg_iov = &iov,
+                       .msg_iovlen = 1,
+               };
+
+               nread = recvmsg(state->fd, &msg, 0);
+               if ((nread == -1) && (errno == ENOTSOCK)) {
+                       state->is_sock = false;
+               }
+       }
+       if (!state->is_sock) {
                nread = read(state->fd, state->buf+state->nread,
                             total-state->nread);
        }