Author: metze
Date: 2006-07-17 07:45:23 +0000 (Mon, 17 Jul 2006)
New Revision: 17081

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17081

Log:
add idle handler support to the smb2 client lib too

metze
Modified:
   branches/SAMBA_4_0/source/libcli/smb2/smb2.h
   branches/SAMBA_4_0/source/libcli/smb2/transport.c


Changeset:
Modified: branches/SAMBA_4_0/source/libcli/smb2/smb2.h
===================================================================
--- branches/SAMBA_4_0/source/libcli/smb2/smb2.h        2006-07-17 03:53:39 UTC 
(rev 17080)
+++ branches/SAMBA_4_0/source/libcli/smb2/smb2.h        2006-07-17 07:45:23 UTC 
(rev 17081)
@@ -48,6 +48,15 @@
 
        /* context of the stream -> packet parser */
        struct packet_context *packet;
+
+       /* an idle function - if this is defined then it will be
+          called once every period microseconds while we are waiting
+          for a packet */
+       struct {
+               void (*func)(struct smb2_transport *, void *);
+               void *private;
+               uint_t period;
+       } idle;
 };
 
 

Modified: branches/SAMBA_4_0/source/libcli/smb2/transport.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/smb2/transport.c   2006-07-17 03:53:39 UTC 
(rev 17080)
+++ branches/SAMBA_4_0/source/libcli/smb2/transport.c   2006-07-17 07:45:23 UTC 
(rev 17081)
@@ -307,3 +307,39 @@
 
        talloc_set_destructor(req, smb2_request_destructor);
 }
+
+static void idle_handler(struct event_context *ev, 
+                        struct timed_event *te, struct timeval t, void 
*private)
+{
+       struct smb2_transport *transport = talloc_get_type(private,
+                                                          struct 
smb2_transport);
+       struct timeval next = timeval_add(&t, 0, transport->idle.period);
+       transport->socket->event.te = 
event_add_timed(transport->socket->event.ctx, 
+                                                     transport,
+                                                     next,
+                                                     idle_handler, transport);
+       transport->idle.func(transport, transport->idle.private);
+}
+
+/*
+  setup the idle handler for a transport
+  the period is in microseconds
+*/
+void smb2_transport_idle_handler(struct smb2_transport *transport, 
+                                void (*idle_func)(struct smb2_transport *, 
void *),
+                                uint64_t period,
+                                void *private)
+{
+       transport->idle.func = idle_func;
+       transport->idle.private = private;
+       transport->idle.period = period;
+
+       if (transport->socket->event.te != NULL) {
+               talloc_free(transport->socket->event.te);
+       }
+
+       transport->socket->event.te = 
event_add_timed(transport->socket->event.ctx, 
+                                                     transport,
+                                                     timeval_current_ofs(0, 
period),
+                                                     idle_handler, transport);
+}

Reply via email to