]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3750 --resolve
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 8 Dec 2011 18:25:52 +0000 (12:25 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 8 Dec 2011 18:26:36 +0000 (12:26 -0600)
src/mod/event_handlers/mod_event_socket/mod_event_socket.c

index 27068bb593e6c5fdc3f1d91fcd7d7383a8cc4d91..d35488d2358af0d47b691396bb7ee58c35c088f0 100644 (file)
@@ -94,6 +94,7 @@ struct listener {
        char remote_ip[50];
        switch_port_t remote_port;
        switch_event_t *filters;
+       time_t linger_timeout;
        struct listener *next;
 };
 
@@ -1343,6 +1344,12 @@ 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) {
+                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session), SWITCH_LOG_DEBUG, "linger timeout, closing socket\n");
+                       status = SWITCH_STATUS_FALSE;
+                       break;
+               }
+
                if (channel && switch_channel_down(channel) && !switch_test_flag(listener, LFLAG_HANDLE_DISCO)) {
                        switch_set_flag_locked(listener, LFLAG_HANDLE_DISCO);
                        if (switch_test_flag(listener, LFLAG_LINGER)) {
@@ -2260,8 +2267,15 @@ 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? */
+                       if (*(cmd+6) == ' ' && *(cmd+7)) { /*how long do you want to linger?*/
+                               linger_time = (uint32_t)atoi(cmd+7);
+                       }
+
+                       /*do we need a mutex to update linger_timeout ?*/
+                       listener->linger_timeout = switch_epoch_time_now(NULL) + linger_time;
                        switch_set_flag_locked(listener, LFLAG_LINGER);
-                       switch_snprintf(reply, reply_len, "+OK will linger");
+                       switch_snprintf(reply, reply_len, "+OK will linger %d seconds", linger_time);
                } else {
                        switch_snprintf(reply, reply_len, "-ERR not controlling a session");
                }