]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Make accept_recv() return the listening socket
authorVolker Lendecke <vl@samba.org>
Sun, 17 Jan 2021 10:04:47 +0000 (11:04 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 22 Jan 2021 19:54:38 +0000 (19:54 +0000)
This is helpful if you are in a listening loop with the same receiver
for many sockets doing the same thing.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
ctdb/common/sock_daemon.c
ctdb/tests/src/comm_server_test.c
ctdb/tests/src/fake_ctdbd.c
lib/async_req/async_sock.c
lib/async_req/async_sock.h

index 7d026515d687ca5a2ecc796b8b572f1e9084314a..6298653f4ec9dcb07855d217d5a3c0d1fb2dd44d 100644 (file)
@@ -371,7 +371,7 @@ static void sock_socket_start_new_client(struct tevent_req *subreq)
        struct sock_client *client;
        int client_fd, ret;
 
-       client_fd = accept_recv(subreq, NULL, &ret);
+       client_fd = accept_recv(subreq, NULL, NULL, &ret);
        TALLOC_FREE(subreq);
        if (client_fd == -1) {
                D_ERR("failed to accept new connection\n");
index 721aa679b635405b1f00a608a2284d2226cb0d9f..86b5658b949f79b672021f2e72d580d96defd4a1 100644 (file)
@@ -175,7 +175,7 @@ static void socket_process_client(struct tevent_req *subreq)
        int client_fd;
        int err = 0;
 
-       client_fd = accept_recv(subreq, NULL, &err);
+       client_fd = accept_recv(subreq, NULL, NULL, &err);
        TALLOC_FREE(subreq);
 
        state->num_clients++;
index 2b2ed066f75d44fe0f9e9125cea43079f404223f..146b7da344c62fd41da11e21ba67d23a0fcc81cf 100644 (file)
@@ -4284,7 +4284,7 @@ static void server_new_client(struct tevent_req *subreq)
        int client_fd;
        int ret = 0;
 
-       client_fd = accept_recv(subreq, NULL, &ret);
+       client_fd = accept_recv(subreq, NULL, NULL, &ret);
        TALLOC_FREE(subreq);
        if (client_fd == -1) {
                tevent_req_error(req, ret);
index 1a39c98ab384a900e1dcfa7f569cc90df7a2bd5c..3035aaaf623514f7f1906791e0e37f485022fb39 100644 (file)
@@ -767,20 +767,27 @@ static void accept_handler(struct tevent_context *ev, struct tevent_fd *fde,
 }
 
 int accept_recv(struct tevent_req *req,
+               int *listen_sock,
                struct samba_sockaddr *paddr,
                int *perr)
 {
        struct accept_state *state = tevent_req_data(req, struct accept_state);
+       int sock = state->sock;
        int err;
 
        if (tevent_req_is_unix_error(req, &err)) {
                if (perr != NULL) {
                        *perr = err;
                }
+               tevent_req_received(req);
                return -1;
        }
+       if (listen_sock != NULL) {
+               *listen_sock = state->listen_sock;
+       }
        if (paddr != NULL) {
                *paddr = state->addr;
        }
-       return state->sock;
+       tevent_req_received(req);
+       return sock;
 }
index 6952345df0c8f44aafadee8c4f2c92768d4e7337..780195e3725d983dc432919e94c51fd47d9c1e9a 100644 (file)
@@ -61,6 +61,7 @@ struct samba_sockaddr;
 struct tevent_req *accept_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
                               int listen_sock);
 int accept_recv(struct tevent_req *req,
+               int *listen_sock,
                struct samba_sockaddr *paddr,
                int *perr);