From 6a3478f2f16c6b228b78c158719c8fe511312dfa Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 13 Apr 2012 08:43:46 -0500 Subject: [PATCH] FS-3750 --resolve --- .../mod_event_socket/mod_event_socket.c | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c index e90d174966..8863476ed5 100644 --- a/src/mod/event_handlers/mod_event_socket/mod_event_socket.c +++ b/src/mod/event_handlers/mod_event_socket/mod_event_socket.c @@ -1344,7 +1344,8 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event, } } - if (switch_test_flag(listener, LFLAG_HANDLE_DISCO) && switch_epoch_time_now(NULL) > listener->linger_timeout) { + if (switch_test_flag(listener, LFLAG_HANDLE_DISCO) && + listener->linger_timeout != (time_t) -1 && switch_epoch_time_now(NULL) > listener->linger_timeout) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session), SWITCH_LOG_DEBUG, "linger timeout, closing socket\n"); status = SWITCH_STATUS_FALSE; break; @@ -1356,8 +1357,18 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event, char message[128] = ""; char disco_buf[512] = ""; - switch_snprintf(message, sizeof(message), - "Channel %s has disconnected, lingering by request from remote.\n", switch_channel_get_name(channel)); + if (listener->linger_timeout != (time_t) -1) { + listener->linger_timeout += switch_epoch_time_now(NULL); + switch_snprintf(message, sizeof(message), + "Channel %s has disconnected, lingering %d seconds by request from remote.\n", + switch_channel_get_name(channel), listener->linger_timeout); + } else { + switch_snprintf(message, sizeof(message), + "Channel %s has disconnected, lingering by request from remote.\n", + switch_channel_get_name(channel)); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s", message); + mlen = strlen(message); switch_snprintf(disco_buf, sizeof(disco_buf), "Content-Type: text/disconnect-notice\n" @@ -2056,8 +2067,12 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even if (async) { if ((status = switch_core_session_queue_private_event(listener->session, event, SWITCH_FALSE)) == SWITCH_STATUS_SUCCESS) { switch_snprintf(reply, reply_len, "+OK"); + } else if (status == SWITCH_STATUS_TERM) { + switch_snprintf(reply, reply_len, "-ERR closed queue"); + status = SWITCH_STATUS_SUCCESS; } else { switch_snprintf(reply, reply_len, "-ERR memory error"); + status = SWITCH_STATUS_SUCCESS; } } else { switch_ivr_parse_event(listener->session, *event); @@ -2067,8 +2082,12 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even if (!zstr(uuid) && (session = switch_core_session_locate(uuid))) { if ((status = switch_core_session_queue_private_event(session, event, SWITCH_FALSE)) == SWITCH_STATUS_SUCCESS) { switch_snprintf(reply, reply_len, "+OK"); + } else if (status == SWITCH_STATUS_TERM) { + switch_snprintf(reply, reply_len, "-ERR closed queue"); + status = SWITCH_STATUS_SUCCESS; } else { switch_snprintf(reply, reply_len, "-ERR memory error"); + status = SWITCH_STATUS_SUCCESS; } switch_core_session_rwunlock(session); } else { @@ -2267,15 +2286,20 @@ static switch_status_t parse_command(listener_t *listener, switch_event_t **even } } else if (!strncasecmp(cmd, "linger", 6)) { if (listener->session) { - uint32_t linger_time = 600; /* sounds reasonable? */ + time_t linger_time = 600; /* sounds reasonable? */ if (*(cmd+6) == ' ' && *(cmd+7)) { /*how long do you want to linger?*/ - linger_time = (uint32_t)atoi(cmd+7); + linger_time = (time_t) atoi(cmd+7); + } else { + linger_time = (time_t) -1; } - /*do we need a mutex to update linger_timeout ?*/ - listener->linger_timeout = switch_epoch_time_now(NULL) + linger_time; + listener->linger_timeout = linger_time; switch_set_flag_locked(listener, LFLAG_LINGER); - switch_snprintf(reply, reply_len, "+OK will linger %d seconds", linger_time); + if (listener->linger_timeout != (time_t) -1) { + switch_snprintf(reply, reply_len, "+OK will linger %d seconds", linger_time); + } else { + switch_snprintf(reply, reply_len, "+OK will linger"); + } } else { switch_snprintf(reply, reply_len, "-ERR not controlling a session"); }