s3-rpc_server: add termination function
authorSimo Sorce <idra@samba.org>
Mon, 25 Apr 2011 21:24:15 +0000 (17:24 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 10 Aug 2011 16:14:03 +0000 (18:14 +0200)
This way we can act when a client disconnects.

Signed-off-by: Andreas Schneider <asn@samba.org>
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h

index e5e856b61ffef5f59fedc1f7d51eba0cc6cf6eb9..fe78a1c629051d28a582e82c23641d7449938963 100644 (file)
@@ -281,7 +281,7 @@ static void named_pipe_listener(struct tevent_context *ev,
        named_pipe_accept_function(state->ev_ctx,
                                   state->msg_ctx,
                                   state->ep.name,
-                                  sd);
+                                  sd, NULL, 0);
 }
 
 
@@ -314,13 +314,26 @@ struct named_pipe_client {
 
        struct iovec *iov;
        size_t count;
+
+       named_pipe_termination_fn *term_fn;
+       void *private_data;
 };
 
+static int named_pipe_destructor(struct named_pipe_client *npc)
+{
+       if (npc->term_fn) {
+               npc->term_fn(npc->private_data);
+       }
+       return 0;
+}
+
 static void named_pipe_accept_done(struct tevent_req *subreq);
 
 void named_pipe_accept_function(struct tevent_context *ev_ctx,
                                struct messaging_context *msg_ctx,
-                               const char *pipe_name, int fd)
+                               const char *pipe_name, int fd,
+                               named_pipe_termination_fn *term_fn,
+                               void *private_data)
 {
        struct named_pipe_client *npc;
        struct tstream_context *plain;
@@ -343,6 +356,10 @@ void named_pipe_accept_function(struct tevent_context *ev_ctx,
        }
        npc->ev = ev_ctx;
        npc->msg_ctx = msg_ctx;
+       npc->term_fn = term_fn;
+       npc->private_data = private_data;
+
+       talloc_set_destructor(npc, named_pipe_destructor);
 
        /* make sure socket is in NON blocking state */
        ret = set_blocking(fd, false);
index b81c7e2c39bf968e834d1d0b7b933d19912d32e7..c6ac2e29b36a108878a6bbf76d1bb8b648c7fba9 100644 (file)
@@ -23,6 +23,7 @@
 struct pipes_struct;
 
 typedef bool (*dcerpc_ncacn_disconnect_fn)(struct pipes_struct *p);
+typedef void (named_pipe_termination_fn)(void *private_data);
 
 void set_incoming_fault(struct pipes_struct *p);
 void process_complete_pdu(struct pipes_struct *p);
@@ -32,7 +33,9 @@ bool setup_named_pipe_socket(const char *pipe_name,
                             struct messaging_context *msg_ctx);
 void named_pipe_accept_function(struct tevent_context *ev_ctx,
                                struct messaging_context *msg_ctx,
-                               const char *pipe_name, int fd);
+                               const char *pipe_name, int fd,
+                               named_pipe_termination_fn *term_fn,
+                               void *private_data);
 
 uint16_t setup_dcerpc_ncacn_tcpip_socket(struct tevent_context *ev_ctx,
                                         struct messaging_context *msg_ctx,