From 73b066281e6f80beb46bbfdb9742e26d3550dfce Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 17 Jul 2006 07:45:23 +0000 Subject: r17081: add idle handler support to the smb2 client lib too metze (This used to be commit 1f48e7dca6a06078f3655a7f7a8f109bd6c0cb8e) --- source4/libcli/smb2/smb2.h | 9 +++++++++ source4/libcli/smb2/transport.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) (limited to 'source4/libcli/smb2') 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); +} -- cgit