diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-07-17 07:45:23 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:10:11 -0500 |
commit | 73b066281e6f80beb46bbfdb9742e26d3550dfce (patch) | |
tree | afe26695d03c9c88d90ce6443b8eb3c4d6d79720 | |
parent | 45b64e394d19c64ec2e0a65e75b52c5024abf592 (diff) | |
download | samba-73b066281e6f80beb46bbfdb9742e26d3550dfce.tar.gz samba-73b066281e6f80beb46bbfdb9742e26d3550dfce.tar.bz2 samba-73b066281e6f80beb46bbfdb9742e26d3550dfce.zip |
r17081: add idle handler support to the smb2 client lib too
metze
(This used to be commit 1f48e7dca6a06078f3655a7f7a8f109bd6c0cb8e)
-rw-r--r-- | source4/libcli/smb2/smb2.h | 9 | ||||
-rw-r--r-- | source4/libcli/smb2/transport.c | 36 |
2 files changed, 45 insertions, 0 deletions
diff --git a/source4/libcli/smb2/smb2.h b/source4/libcli/smb2/smb2.h index 2c1892cafc..cee414b6e2 100644 --- a/source4/libcli/smb2/smb2.h +++ b/source4/libcli/smb2/smb2.h @@ -48,6 +48,15 @@ struct smb2_transport { /* 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; }; diff --git a/source4/libcli/smb2/transport.c b/source4/libcli/smb2/transport.c index df3bec8720..c970bf7147 100644 --- a/source4/libcli/smb2/transport.c +++ b/source4/libcli/smb2/transport.c @@ -307,3 +307,39 @@ void smb2_transport_send(struct smb2_request *req) 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); +} |