]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Skinny: block socket to decrease CPU usage
authorMathieu Parent <math.parent@gmail.com>
Fri, 3 Sep 2010 17:08:41 +0000 (19:08 +0200)
committerMathieu Parent <math.parent@gmail.com>
Fri, 3 Sep 2010 17:08:41 +0000 (19:08 +0200)
non-blocking mode can still be used by setting MOD_SKINNY_NONBLOCK

src/mod/endpoints/mod_skinny/mod_skinny.c
src/mod/endpoints/mod_skinny/skinny_protocol.c

index 5da1367a3537a8b49099c475f28d843c6c3e6762..cbeae6cf5afadce27d298d3347ea517fbaccc9c4 100644 (file)
@@ -1391,9 +1391,13 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
 
        switch_assert(listener != NULL);
 
+#if MOD_SKINNY_NONBLOCK
        switch_socket_opt_set(listener->sock, SWITCH_SO_TCP_NODELAY, TRUE);
        switch_socket_opt_set(listener->sock, SWITCH_SO_NONBLOCK, TRUE);
-
+#else
+       switch_socket_opt_set(listener->sock, SWITCH_SO_NONBLOCK, FALSE);
+       switch_socket_timeout_set(listener->sock, 5000000);
+#endif
        if (listener->profile->debug > 0) {
                if (zstr(listener->remote_ip)) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
@@ -1402,7 +1406,6 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
                }
        }
 
-       switch_socket_opt_set(listener->sock, SWITCH_SO_NONBLOCK, TRUE);
        switch_set_flag_locked(listener, LFLAG_RUNNING);
        keepalive_listener(listener, NULL);
        add_listener(listener);
@@ -1413,8 +1416,6 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
 
                if (status != SWITCH_STATUS_SUCCESS) {
                        switch(status) {
-                               case SWITCH_STATUS_BREAK:
-                                       break;
                                case SWITCH_STATUS_TIMEOUT:
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Communication Time Out with %s:%d.\n",
                                                listener->remote_ip, listener->remote_port);
index 28699b9c039e770953c4e579cb64f7bd64aae43e..c519dc4bf539486e92fb77dd7ff84459140039d8 100644 (file)
@@ -118,10 +118,6 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
                return SWITCH_STATUS_MEMERR;
        }
 
-       if (!listener_is_ready(listener)) {
-               return SWITCH_STATUS_BREAK;
-       }
-
        ptr = mbuf;
 
        while (listener_is_ready(listener)) {
@@ -137,10 +133,10 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
                status = switch_socket_recv(listener->sock, ptr, &mlen);
 
                if (!listener_is_ready(listener)) {
-                       return SWITCH_STATUS_BREAK;
+                       break;
                }
-               if (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break.\n");
+               if ((status != 70007 /* APR_TIMEUP */) && !SWITCH_STATUS_IS_BREAK(status) && (status != SWITCH_STATUS_SUCCESS)) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break with status=%d.\n", status);
                        return SWITCH_STATUS_FALSE;
                }