r4938: allow the caller to supply an existing event_context if they want to
authorAndrew Tridgell <tridge@samba.org>
Sun, 23 Jan 2005 09:01:46 +0000 (09:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:09:07 +0000 (13:09 -0500)
in smb_composite_connect_send(). This makes doing parallel calls much
easier.
(This used to be commit 442308970c123b9fb25615673049e1c1c234a0b9)

source4/libcli/cliconnect.c
source4/libcli/composite/connect.c
source4/libcli/raw/clisocket.c
source4/torture/rpc/xplogin.c

index aaed36eb05b1eb682a9d06aa0afa727c736e7e0b..4d9fb5ba1f0fb95fdda53d0fb9620722e5a10834 100644 (file)
@@ -32,7 +32,7 @@ BOOL smbcli_socket_connect(struct smbcli_state *cli, const char *server)
 {
        struct smbcli_socket *sock;
 
-       sock = smbcli_sock_init(cli);
+       sock = smbcli_sock_init(cli, NULL);
        if (!sock) return False;
 
        if (!smbcli_sock_connect_byname(sock, server, 0)) {
index 83f1dc4fa66cba6cb6d3eb7c5248867301d6c135..69b394310e526a3fa8f2f25268b028ee3df5466d 100644 (file)
@@ -330,7 +330,8 @@ static void composite_handler(struct smbcli_composite *req)
 /*
   a function to establish a smbcli_tree from scratch
 */
-struct smbcli_composite *smb_composite_connect_send(struct smb_composite_connect *io)
+struct smbcli_composite *smb_composite_connect_send(struct smb_composite_connect *io,
+                                                   struct event_context *event_ctx)
 {
        struct smbcli_composite *c;
        struct connect_state *state;
@@ -342,14 +343,14 @@ struct smbcli_composite *smb_composite_connect_send(struct smb_composite_connect
        state = talloc(c, struct connect_state);
        if (state == NULL) goto failed;
 
-       state->sock = smbcli_sock_init(state);
+       state->sock = smbcli_sock_init(state, event_ctx);
        if (state->sock == NULL) goto failed;
 
        state->io = io;
        state->stage = CONNECT_RESOLVE;
 
        c->state = SMBCLI_REQUEST_SEND;
-       c->event_ctx = state->sock->event.ctx;
+       c->event_ctx = talloc_reference(c, state->sock->event.ctx);
        c->private = state;
 
        name.name = io->in.dest_host;
@@ -391,6 +392,6 @@ NTSTATUS smb_composite_connect_recv(struct smbcli_composite *c, TALLOC_CTX *mem_
 */
 NTSTATUS smb_composite_connect(struct smb_composite_connect *io, TALLOC_CTX *mem_ctx)
 {
-       struct smbcli_composite *c = smb_composite_connect_send(io);
+       struct smbcli_composite *c = smb_composite_connect_send(io, NULL);
        return smb_composite_connect_recv(c, mem_ctx);
 }
index cbbd6490bdc5f388a44fb41c54e3f4d1e9305ea9..9249f453e880360e90996f1546f0c63b22bd79b5 100644 (file)
@@ -49,8 +49,10 @@ static int smbcli_sock_destructor(void *ptr)
 
 /*
   create a smbcli_socket context
+  The event_ctx is optional - if not supplied one will be created
 */
-struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx)
+struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, 
+                                      struct event_context *event_ctx)
 {
        struct smbcli_socket *sock;
 
@@ -59,7 +61,11 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx)
                return NULL;
        }
 
-       sock->event.ctx = event_context_init(sock);
+       if (event_ctx) {
+               sock->event.ctx = talloc_reference(sock, event_ctx);
+       } else {
+               sock->event.ctx = event_context_init(sock);
+       }
        if (sock->event.ctx == NULL) {
                talloc_free(sock);
                return NULL;
index 8acf3c4eb7c24061b1640ae8470c48b0ad3d17af..25bda40da97e8b828493dc6e2787d39f2d7c5c47 100644 (file)
@@ -43,7 +43,7 @@ static NTSTATUS after_negprot(struct smbcli_transport **dst_transport,
        struct smbcli_transport *transport;
        NTSTATUS status;
 
-       sock = smbcli_sock_init(NULL);
+       sock = smbcli_sock_init(NULL, NULL);
        if (sock == NULL)
                return NT_STATUS_NO_MEMORY;