diff options
Diffstat (limited to 'source3/smbd')
-rw-r--r-- | source3/smbd/process.c | 27 | ||||
-rw-r--r-- | source3/smbd/server.c | 26 |
2 files changed, 41 insertions, 12 deletions
diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 83072817a3..5edb2c1009 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,7 +22,6 @@ #include "includes.h" uint16 global_smbpid; -extern int keepalive; extern struct auth_context *negprot_global_auth_context; extern int smb_echo_count; @@ -221,6 +220,7 @@ BOOL push_deferred_smb_message(uint16 mid, struct idle_event { struct timed_event *te; struct timeval interval; + char *name; BOOL (*handler)(const struct timeval *now, void *private_data); void *private_data; }; @@ -241,17 +241,19 @@ static void idle_event_handler(struct event_context *ctx, return; } - event->te = event_add_timed(smbd_event_context(), event, + event->te = event_add_timed(ctx, event, timeval_sum(now, &event->interval), - "idle_event_handler", + event->name, idle_event_handler, event); /* We can't do much but fail here. */ SMB_ASSERT(event->te != NULL); } -struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, +struct idle_event *event_add_idle(struct event_context *event_ctx, + TALLOC_CTX *mem_ctx, struct timeval interval, + const char *name, BOOL (*handler)(const struct timeval *now, void *private_data), void *private_data) @@ -269,9 +271,15 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx, result->handler = handler; result->private_data = private_data; - result->te = event_add_timed(smbd_event_context(), result, + if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) { + DEBUG(0, ("talloc failed\n")); + TALLOC_FREE(result); + return NULL; + } + + result->te = event_add_timed(event_ctx, result, timeval_sum(&now, &interval), - "idle_event_handler", + result->name, idle_event_handler, result); if (result->te == NULL) { DEBUG(0, ("event_add_timed failed\n")); @@ -1363,12 +1371,7 @@ static BOOL timeout_processing(int *select_timeout, last_idle_closed_check = t; } - if (keepalive && (t - last_keepalive_sent_time)>keepalive) { - if (!send_keepalive(smbd_server_fd())) { - DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); - return False; - } - + if (lp_keepalive() && (t - last_keepalive_sent_time)> lp_keepalive()) { /* send a keepalive for a password server or the like. This is attached to the auth_info created in the negprot */ diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 0ae2f3e836..0d4953e5b8 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -814,6 +814,18 @@ static BOOL init_structs(void ) return True; } +/* + * Send keepalive packets to our client + */ +static BOOL keepalive_fn(const struct timeval *now, void *private_data) +{ + if (!send_keepalive(smbd_server_fd())) { + DEBUG( 2, ( "Keepalive failed - exiting.\n" ) ); + return False; + } + return True; +} + /**************************************************************************** main program. ****************************************************************************/ @@ -1107,6 +1119,20 @@ extern void build_options(BOOL screen); /* register our message handlers */ message_register(MSG_SMB_FORCE_TDIS, msg_force_tdis, NULL); + if (lp_keepalive() != 0) { + struct timeval interval; + + interval.tv_sec = lp_keepalive(); + interval.tv_usec = 0; + + if (!(event_add_idle(smbd_event_context(), NULL, + interval, "keepalive", keepalive_fn, + NULL))) { + DEBUG(0, ("Could not add keepalive event\n")); + exit(1); + } + } + smbd_process(); namecache_shutdown(); |