Skinny: block socket to decrease CPU usage
non-blocking mode can still be used by setting MOD_SKINNY_NONBLOCK
This commit is contained in:
parent
a8ad3da74e
commit
b762a0aa7f
|
@ -1391,9 +1391,13 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
||||||
|
|
||||||
switch_assert(listener != NULL);
|
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_TCP_NODELAY, TRUE);
|
||||||
switch_socket_opt_set(listener->sock, SWITCH_SO_NONBLOCK, 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 (listener->profile->debug > 0) {
|
||||||
if (zstr(listener->remote_ip)) {
|
if (zstr(listener->remote_ip)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connection Open\n");
|
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);
|
switch_set_flag_locked(listener, LFLAG_RUNNING);
|
||||||
keepalive_listener(listener, NULL);
|
keepalive_listener(listener, NULL);
|
||||||
add_listener(listener);
|
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) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case SWITCH_STATUS_BREAK:
|
|
||||||
break;
|
|
||||||
case SWITCH_STATUS_TIMEOUT:
|
case SWITCH_STATUS_TIMEOUT:
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Communication Time Out with %s:%d.\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Communication Time Out with %s:%d.\n",
|
||||||
listener->remote_ip, listener->remote_port);
|
listener->remote_ip, listener->remote_port);
|
||||||
|
|
|
@ -118,10 +118,6 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
|
||||||
return SWITCH_STATUS_MEMERR;
|
return SWITCH_STATUS_MEMERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!listener_is_ready(listener)) {
|
|
||||||
return SWITCH_STATUS_BREAK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = mbuf;
|
ptr = mbuf;
|
||||||
|
|
||||||
while (listener_is_ready(listener)) {
|
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);
|
status = switch_socket_recv(listener->sock, ptr, &mlen);
|
||||||
|
|
||||||
if (!listener_is_ready(listener)) {
|
if (!listener_is_ready(listener)) {
|
||||||
return SWITCH_STATUS_BREAK;
|
break;
|
||||||
}
|
}
|
||||||
if (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS) {
|
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.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break with status=%d.\n", status);
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue