Skinny: block socket to decrease CPU usage

non-blocking mode can still be used by setting MOD_SKINNY_NONBLOCK
This commit is contained in:
Mathieu Parent 2010-09-03 19:08:41 +02:00
parent a8ad3da74e
commit b762a0aa7f
2 changed files with 8 additions and 11 deletions

View 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);

View 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;
}