From 06322d33e0ff398be17dba8291fad477b87ce3bc Mon Sep 17 00:00:00 2001 From: Giovanni Maruzzelli Date: Wed, 13 Jul 2011 06:04:26 -0500 Subject: [PATCH] skypopen: brought almost all sleeps to at least 20millisec, because various platforms have no smaller granularity (eg: virtual machines). Fixed bogus values in 'sk list' report --- src/mod/endpoints/mod_skypopen/mod_skypopen.c | 75 ++++++++++--------- .../mod_skypopen/skypopen_protocol.c | 24 +++--- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index fb6af40c80..61a4ccae70 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -364,7 +364,7 @@ static switch_status_t interface_exists(char *the_interface) if (globals.SKYPOPEN_INTERFACES[interface_id].skypopen_signaling_thread) { #ifdef WIN32 skypopen_signaling_write(tech_pvt, "DIE"); - switch_sleep(10000); + switch_sleep(20000); switch_file_write(tech_pvt->SkypopenHandles.fdesc[1], "sciutati", &howmany); // let's the controldev_thread die #else /* WIN32 */ howmany = write(tech_pvt->SkypopenHandles.fdesc[1], "sciutati", howmany); @@ -381,7 +381,7 @@ static switch_status_t interface_exists(char *the_interface) if (tech_pvt->running && tech_pvt->SkypopenHandles.disp) { XEvent e; Atom atom1 = XInternAtom(tech_pvt->SkypopenHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); - switch_sleep(1000); + switch_sleep(20000); XFlush(tech_pvt->SkypopenHandles.disp); memset(&e, 0, sizeof(e)); e.xclient.type = ClientMessage; @@ -494,9 +494,9 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) DEBUGA_SKYPE("audio tcp threads to DIE\n", SKYPOPEN_P_LOG); conta = 0; while (tech_pvt->tcp_srv_thread) { - switch_sleep(5000); + switch_sleep(50000); conta++; - if (conta == 200) { + if (conta == 20) { ERRORA("tcp_srv_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } @@ -504,9 +504,9 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) DEBUGA_SKYPE("audio tcp srv thread DEAD %d\n", SKYPOPEN_P_LOG, conta); conta = 0; while (tech_pvt->tcp_cli_thread) { - switch_sleep(5000); + switch_sleep(50000); conta++; - if (conta == 200) { + if (conta == 20) { ERRORA("tcp_cli_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } @@ -873,11 +873,13 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch try = 0; if (!bytes_read) { - switch_sleep(1000); + switch_sleep(1000); //XXX don't like this try++; - if (try < 5) + if (try < 5){ + DEBUGA_SKYPE("skypopen_audio_read going back to read\n", SKYPOPEN_P_LOG); goto read; - DEBUGA_SKYPE("skypopen_audio_read Silence\n", SKYPOPEN_P_LOG); + } + WARNINGA("skypopen_audio_read Silence\n", SKYPOPEN_P_LOG); memset(tech_pvt->read_frame.data, 255, BYTES_PER_FRAME); tech_pvt->read_frame.datalen = BYTES_PER_FRAME; @@ -1056,9 +1058,9 @@ static switch_status_t channel_answer_channel(switch_core_session_t *session) if (switch_channel_get_state(channel) == CS_RESET) { return SWITCH_STATUS_FALSE; } - switch_sleep(5000); + switch_sleep(50000); conta++; - if (conta == 100) { //0.5 seconds + if (conta == 10) { //0.5 seconds return SWITCH_STATUS_FALSE; } } @@ -1361,7 +1363,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } - tech_pvt->ob_calls++; rdest = strchr(caller_profile->destination_number, '/'); *rdest++ = '\0'; @@ -1371,6 +1372,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi caller_profile->destination_number = rdest; switch_mutex_lock(tech_pvt->flag_mutex); + tech_pvt->ob_calls++; switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_mutex_unlock(tech_pvt->flag_mutex); switch_channel_set_state(channel, CS_INIT); @@ -1428,7 +1430,7 @@ static void *SWITCH_THREAD_FUNC skypopen_signaling_thread_func(switch_thread_t * if (channel) { switch_channel_state_t state = switch_channel_get_state(channel); if (state < CS_EXECUTE) { - switch_sleep(10000); //10 msec, let the state evolve from CS_NEW + switch_sleep(20000); //20 msec, let the state evolve from CS_NEW } switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); } else { @@ -1442,9 +1444,9 @@ static void *SWITCH_THREAD_FUNC skypopen_signaling_thread_func(switch_thread_t * DEBUGA_SKYPE("audio tcp threads to DIE\n", SKYPOPEN_P_LOG); conta = 0; while (tech_pvt->tcp_srv_thread) { - switch_sleep(5000); + switch_sleep(50000); conta++; - if (conta == 200) { + if (conta == 20) { ERRORA("tcp_srv_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } @@ -1452,9 +1454,9 @@ static void *SWITCH_THREAD_FUNC skypopen_signaling_thread_func(switch_thread_t * DEBUGA_SKYPE("audio tcp srv thread DEAD %d\n", SKYPOPEN_P_LOG, conta); conta = 0; while (tech_pvt->tcp_cli_thread) { - switch_sleep(5000); + switch_sleep(50000); conta++; - if (conta == 200) { + if (conta == 20) { ERRORA("tcp_cli_thread is NOT dead, this can LEAK MEMORY\n", SKYPOPEN_P_LOG); break; } @@ -1647,7 +1649,7 @@ static switch_status_t load_config(int reload_type) } else { DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPOPEN_P_LOG); } - switch_sleep(1000); + switch_sleep(20000); #endif /* WIN32 */ if (interface_id && interface_id < SKYPOPEN_MAX_INTERFACES) { @@ -1795,20 +1797,20 @@ static switch_status_t load_config(int reload_type) SKYPOPEN_P_LOG, interface_id, globals.SKYPOPEN_INTERFACES[interface_id].skype_user); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "PROTOCOL 7"); - switch_sleep(10000); + switch_sleep(20000); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "SET AUTOAWAY OFF"); - switch_sleep(10000); + switch_sleep(20000); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "SET WINDOWSTATE HIDDEN"); - switch_sleep(10000); + switch_sleep(20000); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "SET USERSTATUS ONLINE"); - switch_sleep(10000); + switch_sleep(20000); if (globals.SKYPOPEN_INTERFACES[interface_id].silent_mode) { skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "SET SILENT_MODE ON"); - switch_sleep(10000); + switch_sleep(20000); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "SET SILENT_MODE OFF"); - switch_sleep(10000); + switch_sleep(20000); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[interface_id], "SET SILENT_MODE ON"); - switch_sleep(10000); + switch_sleep(20000); } } else { ERRORA @@ -1929,7 +1931,7 @@ static switch_status_t chat_send(const char *proto, const char *from, const char snprintf(skype_msg, sizeof(skype_msg), "CHAT CREATE %s", to); skypopen_signaling_write(tech_pvt, skype_msg); - switch_sleep(1000); + switch_sleep(20000); } found = 0; @@ -1946,11 +1948,12 @@ static switch_status_t chat_send(const char *proto, const char *from, const char if (found) { break; } - if (tried > 1000) { + tried++; + if (tried > 20) { ERRORA("No chat with dialog_partner='%s' was found\n", SKYPOPEN_P_LOG, to); break; } - switch_sleep(1000); + switch_sleep(50000); } } @@ -2032,12 +2035,12 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypopen_shutdown) if (globals.SKYPOPEN_INTERFACES[interface_id].skypopen_signaling_thread) { #ifdef WIN32 skypopen_signaling_write(tech_pvt, "DIE"); - switch_sleep(10000); + switch_sleep(20000); switch_file_write(tech_pvt->SkypopenHandles.fdesc[1], "sciutati", &howmany); // let's the controldev_thread die #else /* WIN32 */ skypopen_signaling_write(tech_pvt, "DIE"); - switch_sleep(10000); + switch_sleep(20000); howmany = write(tech_pvt->SkypopenHandles.fdesc[1], "sciutati", howmany); #endif /* WIN32 */ } @@ -2053,7 +2056,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypopen_shutdown) XEvent e; Atom atom1 = XInternAtom(tech_pvt->SkypopenHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False); - switch_sleep(1000); + switch_sleep(20000); XFlush(tech_pvt->SkypopenHandles.disp); memset(&e, 0, sizeof(e)); e.xclient.type = ClientMessage; @@ -2456,12 +2459,12 @@ SWITCH_STANDARD_API(sk_function) for (tmp_i = 0; tmp_i < SKYPOPEN_MAX_INTERFACES; tmp_i++) { if (strlen(globals.SKYPOPEN_INTERFACES[tmp_i].name)) { skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[tmp_i], "GET PROFILE PSTN_BALANCE"); - switch_sleep(10000); + switch_sleep(20000); strncpy(tmp_message, globals.SKYPOPEN_INTERFACES[tmp_i].message, sizeof(globals.SKYPOPEN_INTERFACES[tmp_i].message)); skypopen_signaling_write(&globals.SKYPOPEN_INTERFACES[tmp_i], "GET PROFILE PSTN_BALANCE_CURRENCY"); - switch_sleep(10000); + switch_sleep(20000); if(strlen(tmp_message)>21 && strlen(globals.SKYPOPEN_INTERFACES[tmp_i].message) > 30) stream->write_function(stream, " %s \t%s\t%s\n", globals.SKYPOPEN_INTERFACES[tmp_i].name, tmp_message+21, globals.SKYPOPEN_INTERFACES[tmp_i].message+30); } @@ -2480,13 +2483,13 @@ SWITCH_STANDARD_API(sk_function) stream->write_function(stream, "= ====\t ======== \t======= =======\t======\t============\t======\n"); for (i = 0; i < SKYPOPEN_MAX_INTERFACES; i++) { + if (strlen(globals.SKYPOPEN_INTERFACES[i].name)) { next_flag_char = i == globals.next_interface ? '*' : ' '; ib += globals.SKYPOPEN_INTERFACES[i].ib_calls; ib_failed += globals.SKYPOPEN_INTERFACES[i].ib_failed_calls; ob += globals.SKYPOPEN_INTERFACES[i].ob_calls; ob_failed += globals.SKYPOPEN_INTERFACES[i].ob_failed_calls; - if (strlen(globals.SKYPOPEN_INTERFACES[i].name)) { stream->write_function(stream, "%c %d\t[%s]\t%3u/%u\t%6u/%u\t%s\t%s\t%s\n", next_flag_char, @@ -2498,7 +2501,7 @@ SWITCH_STANDARD_API(sk_function) interface_status[globals.SKYPOPEN_INTERFACES[i].interface_state], skype_callflow[globals.SKYPOPEN_INTERFACES[i].skype_callflow], globals.SKYPOPEN_INTERFACES[i].session_uuid_str); } else if (argc > 1 && !strcasecmp(argv[1], "full")) { - stream->write_function(stream, "%c\t%d\n", next_flag_char, i); + stream->write_function(stream, "%c %d\n", next_flag_char, i); } } @@ -2915,7 +2918,7 @@ int skypopen_transfer(private_t *tech_pvt) sprintf(msg_to_skype, "ALTER CALL %s HANGUP", id); skypopen_signaling_write(tech_pvt, msg_to_skype); } - switch_sleep(10000); + switch_sleep(20000); DEBUGA_SKYPE ("We have NOT answered a Skype RING from skype_call %s, because we are already in a skypopen call (%s)\n", SKYPOPEN_P_LOG, id, tech_pvt->skype_call_id); diff --git a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c index b62ece6419..091fb7a57f 100644 --- a/src/mod/endpoints/mod_skypopen/skypopen_protocol.c +++ b/src/mod/endpoints/mod_skypopen/skypopen_protocol.c @@ -186,7 +186,7 @@ int skypopen_signaling_read(private_t *tech_pvt) SKYPOPEN_P_LOG); skypopen_sleep(1000000); skypopen_signaling_write(tech_pvt, "PROTOCOL 7"); - skypopen_sleep(10000); + skypopen_sleep(20000); return 0; } if (!strncasecmp(message, "ERROR 92 CALL", 12)) { @@ -898,6 +898,9 @@ void *skypopen_do_tcp_srv_thread_func(void *obj) if (tech_pvt->timer_read_srv.timer_interface && tech_pvt->timer_read_srv.timer_interface->timer_next) { switch_core_timer_next(&tech_pvt->timer_read_srv); + } else { + skypopen_sleep(20000); + } //rt = select(fdselect + 1, &fs, NULL, NULL, &to); if (rt > 0) { @@ -905,12 +908,12 @@ void *skypopen_do_tcp_srv_thread_func(void *obj) if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) { len = recv(fd, (char *) srv_in, BYTES_PER_FRAME * 2, 0); } else { - skypopen_sleep(10000); + //skypopen_sleep(10000); continue; } if (tech_pvt->begin_to_read == 0) { DEBUGA_SKYPE("len=%d\n", SKYPOPEN_P_LOG, len); - skypopen_sleep(10000); + //skypopen_sleep(10000); continue; } @@ -1054,6 +1057,8 @@ void *skypopen_do_tcp_cli_thread_func(void *obj) if (tech_pvt->timer_write.timer_interface && tech_pvt->timer_write.timer_interface->timer_next && tech_pvt->interface_state != SKYPOPEN_STATE_HANGUP_REQUESTED) { switch_core_timer_next(&tech_pvt->timer_write); + } else { + skypopen_sleep(20000); } if (tech_pvt->begin_to_write == 0) { @@ -1064,7 +1069,7 @@ void *skypopen_do_tcp_cli_thread_func(void *obj) DEBUGA_SKYPE("len=%d, error: %s\n", SKYPOPEN_P_LOG, len, strerror(errno)); break; } - skypopen_sleep(10000); + //skypopen_sleep(10000); continue; } else { @@ -1367,7 +1372,7 @@ LRESULT APIENTRY skypopen_present(HWND hWindow, UINT uiMessage, WPARAM uiParam, } break; case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION: - skypopen_sleep(5000); + skypopen_sleep(20000); break; case SKYPECONTROLAPI_ATTACH_REFUSED: ERRORA("Skype client refused to be connected by Skypopen!\n", SKYPOPEN_P_LOG); @@ -1377,7 +1382,7 @@ LRESULT APIENTRY skypopen_present(HWND hWindow, UINT uiMessage, WPARAM uiParam, break; case SKYPECONTROLAPI_ATTACH_API_AVAILABLE: DEBUGA_SKYPE("Skype API available\n", SKYPOPEN_P_LOG); - skypopen_sleep(5000); + skypopen_sleep(20000); break; default: WARNINGA("GOT AN UNKNOWN SKYPE WINDOWS MSG\n", SKYPOPEN_P_LOG); @@ -1681,7 +1686,7 @@ void skypopen_clean_disp(void *data) DEBUGA_SKYPE("NOT destroyed disp\n", SKYPOPEN_P_LOG); } DEBUGA_SKYPE("OUT destroyed disp\n", SKYPOPEN_P_LOG); - skypopen_sleep(1000); + skypopen_sleep(20000); } void *skypopen_do_skypeapi_thread_func(void *obj) @@ -1927,13 +1932,14 @@ void *skypopen_do_skypeapi_thread_func(void *obj) SKYPOPEN_P_LOG, buf); skypopen_sleep(1000000); //1 sec } - skypopen_sleep(1000); //0.1 msec + skypopen_sleep(20000); //20 msec break; } } if (continue_is_broken) { XFlush(disp); - skypopen_sleep(1000); //0.1 msec + skypopen_sleep(20000); //20 msec + WARNINGA("continue_is_broken\n", SKYPOPEN_P_LOG); continue; } strcat(buffer, buf);