1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

lib: Make accept_recv() return the listening socket

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>
This commit is contained in:
Volker Lendecke 2021-01-17 11:04:47 +01:00 committed by Jeremy Allison
parent f055d3f7db
commit e593f96960
5 changed files with 12 additions and 4 deletions

View 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");

View 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++;

View 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);

View 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;
}

View 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);