From 8ea26bf2fdad4440d65b020943e19128c34c4ed9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 01:21:18 +0000 Subject: [PATCH] r4765: simplify the async socket code to always go via the event handler rather than short-circuiting in the unlikely event the OS returns an immediate success on a non-blocking connect (This used to be commit db4380717041485e216f965103f9e803518b45c3) --- source4/libcli/raw/clisocket.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index d20dc4bf256..851cf67caa0 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -85,17 +85,11 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, conn->iports[i]); - if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { conn->sock->event.fde->private = c; return; } - if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; - if (c->async.fn) { - c->async.fn(c); - } - return; - } } c->state = SMBCLI_REQUEST_ERROR; @@ -153,7 +147,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, - struct ipv4_addr *ip, int port) + const char *host_addr, int port) { struct smbcli_composite *c; struct clisocket_connect *conn; @@ -186,7 +180,7 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->iports[1] = 0; } - conn->dest_host = talloc_strdup(c, sys_inet_ntoa(*ip)); + conn->dest_host = talloc_strdup(c, host_addr); if (conn->dest_host == NULL) goto failed; c->private = conn; @@ -200,14 +194,11 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, c->status = smbcli_sock_connect_one(sock, conn->dest_host, conn->iports[i]); - if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { sock->event.fde->private = c; return c; } - if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; - return c; - } } c->state = SMBCLI_REQUEST_ERROR; @@ -235,11 +226,11 @@ NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) { struct smbcli_composite *c; - c = smbcli_sock_connect_send(sock, ip, port); + c = smbcli_sock_connect_send(sock, host_addr, port); if (c == NULL) { return NT_STATUS_NO_MEMORY; } @@ -339,7 +330,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in sock->hostname = name; - status = smbcli_sock_connect(sock, &ip, port); + status = smbcli_sock_connect(sock, sys_inet_ntoa(ip), port); return NT_STATUS_IS_OK(status); } -- 2.11.4.GIT