<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14517] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14517">14517</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2009-08-14 12:12:09 -0500 (Fri, 14 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>skypiax: ubermegapatch, more stability, robustness, scalability. Memory leaks not yet investigated, we'll do next</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxmod_skypiaxc">freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxskypiaxh">freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxskypiax_protocolc">freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxmod_skypiaxc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14516 => 14517)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c        2009-08-14 13:27:27 UTC (rev 14516)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c        2009-08-14 17:12:09 UTC (rev 14517)
</span><span class="lines">@@ -148,6 +148,7 @@
</span><span class="cx"> static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
</span><span class="cx"> static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
</span><span class="cx"> static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
</span><ins>+static switch_status_t  skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *session);
</ins><span class="cx"> 
</span><span class="cx"> static switch_status_t skypiax_codec(private_t * tech_pvt, int sample_rate, int codec_ms)
</span><span class="cx"> {
</span><span class="lines">@@ -173,30 +174,40 @@
</span><span class="cx"> 
</span><span class="cx">         session = switch_core_session_locate(tech_pvt-&gt;session_uuid_str);
</span><span class="cx"> 
</span><del>-        switch_core_session_set_read_codec(session, &amp;tech_pvt-&gt;read_codec);
-        switch_core_session_set_write_codec(session, &amp;tech_pvt-&gt;write_codec);
</del><ins>+        if(session){
+                switch_core_session_set_read_codec(session, &amp;tech_pvt-&gt;read_codec);
+                switch_core_session_set_write_codec(session, &amp;tech_pvt-&gt;write_codec);
+                switch_core_session_rwunlock(session);
+        } else {
+                ERRORA(&quot;no session\n&quot;, SKYPIAX_P_LOG);
+                return SWITCH_STATUS_FALSE;
+        }
</ins><span class="cx"> 
</span><del>-        switch_core_session_rwunlock(session);
-
</del><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *session)
</del><ins>+switch_status_t skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *session)
</ins><span class="cx"> {
</span><span class="cx"> 
</span><ins>+        switch_assert(tech_pvt != NULL);
+        switch_assert(session != NULL);
</ins><span class="cx">         tech_pvt-&gt;read_frame.data = tech_pvt-&gt;databuf;
</span><span class="cx">         tech_pvt-&gt;read_frame.buflen = sizeof(tech_pvt-&gt;databuf);
</span><span class="cx">         switch_mutex_init(&amp;tech_pvt-&gt;mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
</span><span class="cx">         switch_mutex_init(&amp;tech_pvt-&gt;flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
</span><span class="cx">         switch_core_session_set_private(session, tech_pvt);
</span><span class="cx">         switch_copy_string(tech_pvt-&gt;session_uuid_str, switch_core_session_get_uuid(session), sizeof(tech_pvt-&gt;session_uuid_str));
</span><ins>+        if(!strlen(tech_pvt-&gt;session_uuid_str)){
+                ERRORA(&quot;no tech_pvt-&gt;session_uuid_str\n&quot;, SKYPIAX_P_LOG);
+                return SWITCH_STATUS_FALSE;
+        }
</ins><span class="cx">         if (skypiax_codec(tech_pvt, SAMPLERATE_SKYPIAX, 20) != SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                 ERRORA(&quot;skypiax_codec FAILED\n&quot;, SKYPIAX_P_LOG);
</span><del>-        } else {
-                DEBUGA_SKYPE(&quot;skypiax_codec SUCCESS\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                return SWITCH_STATUS_FALSE;
</ins><span class="cx">         }
</span><del>-
</del><ins>+        DEBUGA_SKYPE(&quot;skypiax_codec SUCCESS\n&quot;, SKYPIAX_P_LOG);
+        return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /* BEGIN: Changes here */
</span><span class="lines">@@ -364,7 +375,8 @@
</span><span class="cx"> 
</span><span class="cx">         channel = switch_core_session_get_channel(session);
</span><span class="cx">         switch_assert(channel != NULL);
</span><del>-        switch_set_flag_locked(tech_pvt, TFLAG_IO);
</del><ins>+        DEBUGA_SKYPE(&quot;%s CHANNEL INIT\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
+        switch_set_flag(tech_pvt, TFLAG_IO);
</ins><span class="cx"> 
</span><span class="cx">         /* Move channel's state machine to ROUTING. This means the call is trying
</span><span class="cx">            to get from the initial start where the call because, to the point
</span><span class="lines">@@ -376,7 +388,6 @@
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_unlock(globals.mutex);
</span><span class="cx"> 
</span><del>-        DEBUGA_SKYPE(&quot;%s CHANNEL INIT\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
</del><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -394,6 +405,7 @@
</span><span class="cx">                 if (switch_core_codec_ready(&amp;tech_pvt-&gt;write_codec)) {
</span><span class="cx">                         switch_core_codec_destroy(&amp;tech_pvt-&gt;write_codec);
</span><span class="cx">                 }
</span><ins>+                *tech_pvt-&gt;session_uuid_str = '\0';
</ins><span class="cx">                 switch_core_session_set_private(session, NULL);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -406,15 +418,16 @@
</span><span class="cx">         private_t *tech_pvt = NULL;
</span><span class="cx">         char msg_to_skype[256];
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">         channel = switch_core_session_get_channel(session);
</span><span class="cx">         switch_assert(channel != NULL);
</span><span class="cx"> 
</span><span class="cx">         tech_pvt = switch_core_session_get_private(session);
</span><span class="cx">         switch_assert(tech_pvt != NULL);
</span><span class="cx"> 
</span><del>-        switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-        //switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
</del><ins>+        switch_clear_flag(tech_pvt, TFLAG_IO);
+        switch_clear_flag(tech_pvt, TFLAG_VOICE);
+        //switch_set_flag(tech_pvt, TFLAG_HANGUP);
</ins><span class="cx"> 
</span><span class="cx">         if (strlen(tech_pvt-&gt;skype_call_id)) {
</span><span class="cx">                 //switch_thread_cond_signal(tech_pvt-&gt;cond);
</span><span class="lines">@@ -423,7 +436,7 @@
</span><span class="cx">                 skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="cx">         }
</span><span class="cx">         //memset(tech_pvt-&gt;session_uuid_str, '\0', sizeof(tech_pvt-&gt;session_uuid_str));
</span><del>-        *tech_pvt-&gt;session_uuid_str = '\0';
</del><ins>+        //*tech_pvt-&gt;session_uuid_str = '\0';
</ins><span class="cx">         DEBUGA_SKYPE(&quot;%s CHANNEL HANGUP\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
</span><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">         globals.calls--;
</span><span class="lines">@@ -482,13 +495,18 @@
</span><span class="cx">         switch (sig) {
</span><span class="cx">         case SWITCH_SIG_KILL:
</span><span class="cx">                 DEBUGA_SKYPE(&quot;%s CHANNEL got SWITCH_SIG_KILL\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
</span><del>-                switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-                switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-                switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
</del><ins>+                //switch_mutex_lock(tech_pvt-&gt;flag_mutex);
+                switch_clear_flag(tech_pvt, TFLAG_IO);
+                switch_clear_flag(tech_pvt, TFLAG_VOICE);
+                switch_set_flag(tech_pvt, TFLAG_HANGUP);
+                //switch_mutex_unlock(tech_pvt-&gt;flag_mutex);
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_SIG_BREAK:
</span><span class="cx">                 DEBUGA_SKYPE(&quot;%s CHANNEL got SWITCH_SIG_BREAK\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
</span><del>-                switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
</del><ins>+                //switch_set_flag(tech_pvt, TFLAG_BREAK);
+                //switch_mutex_lock(tech_pvt-&gt;flag_mutex);
+                switch_set_flag(tech_pvt, TFLAG_BREAK);
+                //switch_mutex_unlock(tech_pvt-&gt;flag_mutex);
</ins><span class="cx">                 break;
</span><span class="cx">         default:
</span><span class="cx">                 break;
</span><span class="lines">@@ -536,7 +554,8 @@
</span><span class="cx">         switch_assert(tech_pvt != NULL);
</span><span class="cx"> 
</span><span class="cx">         if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
</span><del>-                ERRORA(&quot;CIAPA \n&quot;, SKYPIAX_P_LOG);
</del><ins>+                ERRORA(&quot;channel not ready \n&quot;, SKYPIAX_P_LOG);
+                //TODO: kill the bastard
</ins><span class="cx">                 return SWITCH_STATUS_FALSE;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -548,7 +567,7 @@
</span><span class="cx">                 ERRORA(&quot;skypiax_audio_read ERROR\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx"> 
</span><span class="cx">         } else {
</span><del>-                switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
</del><ins>+                switch_set_flag(tech_pvt, TFLAG_VOICE);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         while (switch_test_flag(tech_pvt, TFLAG_IO)) {
</span><span class="lines">@@ -564,7 +583,7 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if (switch_test_flag(tech_pvt, TFLAG_IO) &amp;&amp; switch_test_flag(tech_pvt, TFLAG_VOICE)) {
</span><del>-                        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
</del><ins>+                        switch_clear_flag(tech_pvt, TFLAG_VOICE);
</ins><span class="cx">                         if (!tech_pvt-&gt;read_frame.datalen) {
</span><span class="cx">                                 DEBUGA_SKYPE(&quot;CHANNEL READ CONTINUE\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                                 continue;
</span><span class="lines">@@ -610,7 +629,8 @@
</span><span class="cx">         switch_assert(tech_pvt != NULL);
</span><span class="cx"> 
</span><span class="cx">         if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
</span><del>-                ERRORA(&quot;CIAPA \n&quot;, SKYPIAX_P_LOG);
</del><ins>+                ERRORA(&quot;channel not ready \n&quot;, SKYPIAX_P_LOG);
+                //TODO: kill the bastard
</ins><span class="cx">                 return SWITCH_STATUS_FALSE;
</span><span class="cx">         }
</span><span class="cx"> #ifdef BIGENDIAN
</span><span class="lines">@@ -721,9 +741,9 @@
</span><span class="cx">                                                                                                         switch_caller_profile_t *outbound_profile,
</span><span class="cx">                                                                                                         switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
</span><span class="cx"> {
</span><ins>+                private_t *tech_pvt = NULL;
</ins><span class="cx">         if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
</span><del>-                private_t *tech_pvt = NULL;
-                switch_channel_t *channel;
</del><ins>+                switch_channel_t *channel = NULL;
</ins><span class="cx">                 switch_caller_profile_t *caller_profile;
</span><span class="cx">                 char *rdest;
</span><span class="cx">                 int found = 0;
</span><span class="lines">@@ -741,16 +761,16 @@
</span><span class="cx">                         *slash = '\0';
</span><span class="cx"> 
</span><span class="cx">                         switch_mutex_lock(globals.mutex);
</span><del>-                        if (strncmp(&quot;ANY&quot;, interface_name, strlen(interface_name)) == 0) {
</del><ins>+                        if (strncmp(&quot;ANY&quot;, interface_name, strlen(interface_name)) == 0 || strncmp(&quot;RR&quot;, interface_name, strlen(interface_name)) == 0) {
</ins><span class="cx">                                 /* we've been asked for the &quot;ANY&quot; interface, let's find the first idle interface */
</span><del>-                                DEBUGA_SKYPE(&quot;Finding one available skype interface\n&quot;, SKYPIAX_P_LOG);
-                                tech_pvt = find_available_skypiax_interface(NULL);
-                                if (tech_pvt)
-                                        found = 1;
-                        } else if (strncmp(&quot;RR&quot;, interface_name, strlen(interface_name)) == 0) {
</del><ins>+                                //DEBUGA_SKYPE(&quot;Finding one available skype interface\n&quot;, SKYPIAX_P_LOG);
+                                //tech_pvt = find_available_skypiax_interface(NULL);
+                                //if (tech_pvt)
+                                        //found = 1;
+                        //} else if (strncmp(&quot;RR&quot;, interface_name, strlen(interface_name)) == 0) {
</ins><span class="cx">                                 /* Find the first idle interface using Round Robin */
</span><span class="cx">                                 DEBUGA_SKYPE(&quot;Finding one available skype interface RR\n&quot;, SKYPIAX_P_LOG);
</span><del>-                                tech_pvt = find_available_skypiax_interface_rr();
</del><ins>+                                tech_pvt = find_available_skypiax_interface_rr(NULL);
</ins><span class="cx">                                 if (tech_pvt)
</span><span class="cx">                                         found = 1;
</span><span class="cx">                         }
</span><span class="lines">@@ -765,7 +785,7 @@
</span><span class="cx">                                                          SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name, globals.SKYPIAX_INTERFACES[i].session_uuid_str);
</span><span class="cx">                                                 switch_core_session_destroy(new_session);
</span><span class="cx">                                                 switch_mutex_unlock(globals.mutex);
</span><del>-                                                return SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE;
</del><ins>+                                                return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
</ins><span class="cx">                                         }
</span><span class="cx"> 
</span><span class="cx">                                         DEBUGA_SKYPE(&quot;globals.SKYPIAX_INTERFACES[%d].name=|||%s|||?\n&quot;, SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name);
</span><span class="lines">@@ -783,14 +803,26 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if (!found) {
</span><del>-                        ERRORA(&quot;Doh! no matching interface for |||%s|||?\n&quot;, SKYPIAX_P_LOG, interface_name);
</del><ins>+                        DEBUGA_SKYPE(&quot;Doh! no available interface for |||%s|||?\n&quot;, SKYPIAX_P_LOG, interface_name);
</ins><span class="cx">                         switch_core_session_destroy(new_session);
</span><span class="cx">                         switch_mutex_unlock(globals.mutex);
</span><del>-                        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
</del><ins>+                        //return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                        return SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 channel = switch_core_session_get_channel(*new_session);
</span><del>-                skypiax_tech_init(tech_pvt, *new_session);
</del><ins>+                if(!channel){
+                        ERRORA(&quot;Doh! no channel?\n&quot;, SKYPIAX_P_LOG);
+                        switch_core_session_destroy(new_session);
+                        switch_mutex_unlock(globals.mutex);
+                        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                }
+                if( skypiax_tech_init(tech_pvt, *new_session) != SWITCH_STATUS_SUCCESS){
+                        ERRORA(&quot;Doh! no tech_init?\n&quot;, SKYPIAX_P_LOG);
+                        switch_core_session_destroy(new_session);
+                        switch_mutex_unlock(globals.mutex);
+                        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                }
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">                 if (outbound_profile) {
</span><span class="lines">@@ -812,19 +844,21 @@
</span><span class="cx">                 rdest = strchr(caller_profile-&gt;destination_number, '/');
</span><span class="cx">                 *rdest++ = '\0';
</span><span class="cx"> 
</span><del>-                skypiax_call(tech_pvt, rdest, 30);
</del><ins>+                //skypiax_call(tech_pvt, rdest, 30);
</ins><span class="cx"> 
</span><span class="cx">                 switch_copy_string(tech_pvt-&gt;session_uuid_str, switch_core_session_get_uuid(*new_session), sizeof(tech_pvt-&gt;session_uuid_str));
</span><span class="cx">                 caller_profile = tech_pvt-&gt;caller_profile;
</span><span class="cx">                 caller_profile-&gt;destination_number = rdest;
</span><span class="cx"> 
</span><span class="cx">                 switch_channel_set_flag(channel, CF_OUTBOUND);
</span><del>-                switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
</del><ins>+                switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
</ins><span class="cx">                 switch_channel_set_state(channel, CS_INIT);
</span><ins>+                skypiax_call(tech_pvt, rdest, 30);
</ins><span class="cx">                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">                 return SWITCH_CAUSE_SUCCESS;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        ERRORA(&quot;Doh! no new_session\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">         return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -849,29 +883,35 @@
</span><span class="cx">                 res = skypiax_signaling_read(tech_pvt);
</span><span class="cx">                 if (res == CALLFLOW_INCOMING_HANGUP) {
</span><span class="cx">                         switch_core_session_t *session = NULL;
</span><ins>+                        switch_channel_t *channel = NULL;
</ins><span class="cx">                         //private_t *tech_pvt = NULL;
</span><del>-                        switch_channel_t *channel = NULL;
-
</del><span class="cx">                         DEBUGA_SKYPE(&quot;skype call ended\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx"> 
</span><span class="cx">                         if (tech_pvt) {
</span><span class="cx">                                 session = switch_core_session_locate(tech_pvt-&gt;session_uuid_str);
</span><del>-
</del><span class="cx">                                 if (session) {
</span><span class="cx">                                         channel = switch_core_session_get_channel(session);
</span><span class="cx">                                         if (channel) {
</span><ins>+                                                switch_channel_state_t state = switch_channel_get_state(channel);
+                                                if(state &lt; CS_EXECUTE){
+                                                        usleep(10000);//10 msec, let the state evolve from CS_NEW
+                                                }
</ins><span class="cx">                                                 switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
</span><del>-                                                switch_core_session_rwunlock(session);
</del><span class="cx">                                         } else {
</span><span class="cx">                                                 ERRORA(&quot;no channel?\n&quot;, SKYPIAX_P_LOG);
</span><ins>+                                        }
</ins><span class="cx">                                                 switch_core_session_rwunlock(session);
</span><del>-                                        }
</del><span class="cx">                                 } else {
</span><span class="cx">                                         DEBUGA_SKYPE(&quot;no session\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                                 }
</span><span class="cx">                                 tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
</span><span class="cx">                                 *tech_pvt-&gt;session_uuid_str = '\0';
</span><del>-                                //memset(tech_pvt-&gt;session_uuid_str, '\0', sizeof(tech_pvt-&gt;session_uuid_str));
</del><ins>+                                *tech_pvt-&gt;skype_call_id = '\0';
+
+                                //ERRORA(&quot;LET'S WAIT\n&quot;, SKYPIAX_P_LOG);
+                                usleep(300000); //0.3 sec
+                                //ERRORA(&quot;WAIT'S OVER\n&quot;, SKYPIAX_P_LOG);
+                                tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
</ins><span class="cx">                         } else {
</span><span class="cx">                                 ERRORA(&quot;no tech_pvt?\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                         }
</span><span class="lines">@@ -1389,16 +1429,29 @@
</span><span class="cx">         switch_threadattr_create(&amp;thd_attr, skypiax_module_pool);
</span><span class="cx">         switch_threadattr_detach_set(thd_attr, 1);
</span><span class="cx">         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
</span><del>-        switch_thread_create(&amp;tech_pvt-&gt;tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread, tech_pvt, skypiax_module_pool);
</del><ins>+        if (switch_thread_create(&amp;tech_pvt-&gt;tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread, tech_pvt, skypiax_module_pool) == SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">         DEBUGA_SKYPE(&quot;started tcp_srv_thread thread.\n&quot;, SKYPIAX_P_LOG);
</span><ins>+        } else {
+        ERRORA(&quot;failed to start tcp_srv_thread thread.\n&quot;, SKYPIAX_P_LOG);
+        return -1;
+        }
</ins><span class="cx"> 
</span><span class="cx">         switch_threadattr_create(&amp;thd_attr, skypiax_module_pool);
</span><span class="cx">         switch_threadattr_detach_set(thd_attr, 1);
</span><span class="cx">         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
</span><del>-        switch_thread_create(&amp;tech_pvt-&gt;tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread, tech_pvt, skypiax_module_pool);
</del><ins>+        if(switch_thread_create(&amp;tech_pvt-&gt;tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread, tech_pvt, skypiax_module_pool) == SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">         DEBUGA_SKYPE(&quot;started tcp_cli_thread thread.\n&quot;, SKYPIAX_P_LOG);
</span><ins>+        }else{
+        ERRORA(&quot;failed to start tcp_cli_thread thread.\n&quot;, SKYPIAX_P_LOG);
+        return -1;
+        }
</ins><span class="cx">         switch_sleep(100000);
</span><span class="cx"> 
</span><ins>+        if(tech_pvt-&gt;tcp_cli_thread == NULL || tech_pvt-&gt;tcp_srv_thread == NULL) {
+                ERRORA(&quot;tcp_cli_thread or tcp_srv_thread exited\n&quot;, SKYPIAX_P_LOG);
+                return -1;
+        }
+
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1410,7 +1463,16 @@
</span><span class="cx">         if ((session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL)) != 0) {
</span><span class="cx">                 switch_core_session_add_stream(session, NULL);
</span><span class="cx">                 channel = switch_core_session_get_channel(session);
</span><del>-                skypiax_tech_init(tech_pvt, session);
</del><ins>+                if(!channel){
+                        ERRORA(&quot;Doh! no channel?\n&quot;, SKYPIAX_P_LOG);
+                        switch_core_session_destroy(&amp;session);
+                        return 0;
+                }
+                if( skypiax_tech_init(tech_pvt, session) != SWITCH_STATUS_SUCCESS){
+                        ERRORA(&quot;Doh! no tech_init?\n&quot;, SKYPIAX_P_LOG);
+                        switch_core_session_destroy(&amp;session);
+                        return 0;
+                }
</ins><span class="cx"> 
</span><span class="cx">                 if ((tech_pvt-&gt;caller_profile =
</span><span class="cx">                          switch_caller_profile_new(switch_core_session_get_pool(session), &quot;skypiax&quot;,
</span><span class="lines">@@ -1426,11 +1488,14 @@
</span><span class="cx">                 if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                         ERRORA(&quot;Error spawning thread\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">                         switch_core_session_destroy(&amp;session);
</span><ins>+                        return 0;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        switch_channel_mark_answered(channel);
</del><ins>+        if(channel){
+                switch_channel_mark_answered(channel);
+        }
</ins><span class="cx"> 
</span><del>-        DEBUGA_SKYPE(&quot;Here\n&quot;, SKYPIAX_P_LOG);
</del><ins>+        DEBUGA_SKYPE(&quot;new_inbound_channel\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx"> 
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="lines">@@ -1457,7 +1522,6 @@
</span><span class="cx">                 DEBUGA_SKYPE(&quot;skype_call: REMOTE PARTY RINGING\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         } else {
</span><span class="cx">                 ERRORA(&quot;No channel???\n&quot;, SKYPIAX_P_LOG);
</span><del>-                goto done;
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_core_session_rwunlock(session);
</span><span class="lines">@@ -1474,7 +1538,8 @@
</span><span class="cx">         if (!switch_strlen_zero(tech_pvt-&gt;session_uuid_str)) {
</span><span class="cx">                 session = switch_core_session_locate(tech_pvt-&gt;session_uuid_str);
</span><span class="cx">         } else {
</span><del>-                ERRORA(&quot;No session???\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                ERRORA(&quot;No session???\n\n\n&quot;, SKYPIAX_P_LOG);
+                //TODO: kill the bastard
</ins><span class="cx">                 goto done;
</span><span class="cx">         }
</span><span class="cx">         if (session) {
</span><span class="lines">@@ -1482,6 +1547,7 @@
</span><span class="cx">                 switch_core_session_add_stream(session, NULL);
</span><span class="cx">         } else {
</span><span class="cx">                 ERRORA(&quot;No session???\n&quot;, SKYPIAX_P_LOG);
</span><ins>+                //TODO: kill the bastard
</ins><span class="cx">                 goto done;
</span><span class="cx">         }
</span><span class="cx">         if (channel) {
</span><span class="lines">@@ -1489,7 +1555,7 @@
</span><span class="cx">                 DEBUGA_SKYPE(&quot;skype_call: REMOTE PARTY EARLY MEDIA\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         } else {
</span><span class="cx">                 ERRORA(&quot;No channel???\n&quot;, SKYPIAX_P_LOG);
</span><del>-                goto done;
</del><ins>+                //TODO: kill the bastard
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_core_session_rwunlock(session);
</span><span class="lines">@@ -1512,7 +1578,7 @@
</span><span class="cx">         if (session) {
</span><span class="cx">                 channel = switch_core_session_get_channel(session);
</span><span class="cx">         } else {
</span><del>-                ERRORA(&quot;No session???\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                ERRORA(&quot;No channel???\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">                 goto done;
</span><span class="cx">         }
</span><span class="cx">         if (channel) {
</span><span class="lines">@@ -1520,17 +1586,17 @@
</span><span class="cx">                 //DEBUGA_SKYPE(&quot;skype_call: %s, answered\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="cx">         } else {
</span><span class="cx">                 ERRORA(&quot;No channel???\n&quot;, SKYPIAX_P_LOG);
</span><del>-                goto done;
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_core_session_rwunlock(session);
</span><span class="cx"> 
</span><span class="cx">   done:
</span><del>-        DEBUGA_SKYPE(&quot;HERE!\n&quot;, SKYPIAX_P_LOG);
</del><ins>+        DEBUGA_SKYPE(&quot;outbound_channel_answered!\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx"> 
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if 0
</ins><span class="cx"> private_t *find_available_skypiax_interface(private_t * tech_pvt)
</span><span class="cx"> {
</span><span class="cx">         private_t *tech_pvt2 = NULL;
</span><span class="lines">@@ -1559,8 +1625,9 @@
</span><span class="cx">         else
</span><span class="cx">                 return NULL;
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx"> 
</span><del>-private_t *find_available_skypiax_interface_rr(void)
</del><ins>+private_t *find_available_skypiax_interface_rr(private_t * tech_pvt_calling)
</ins><span class="cx"> {
</span><span class="cx">         private_t *tech_pvt = NULL;
</span><span class="cx">         int i;
</span><span class="lines">@@ -1585,12 +1652,14 @@
</span><span class="cx"> 
</span><span class="cx">                         tech_pvt = &amp;globals.SKYPIAX_INTERFACES[interface_id];
</span><span class="cx">                         skype_state = tech_pvt-&gt;interface_state;
</span><del>-                        DEBUGA_SKYPE(&quot;skype interface: %d, name: %s, state: %d\n&quot;, SKYPIAX_P_LOG, interface_id,
-                                                 globals.SKYPIAX_INTERFACES[interface_id].name, skype_state);
-                        if (SKYPIAX_STATE_DOWN == skype_state || 0 == skype_state) {
</del><ins>+                        //DEBUGA_SKYPE(&quot;skype interface: %d, name: %s, state: %d\n&quot;, SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].name, skype_state);
+                        if ((tech_pvt_calling ? strcmp(tech_pvt-&gt;skype_user, tech_pvt_calling-&gt;skype_user) : 1) &amp;&amp; (SKYPIAX_STATE_DOWN == skype_state || 0 == skype_state) &amp;&amp; (tech_pvt-&gt;skype_callflow ==CALLFLOW_STATUS_FINISHED || 0 == tech_pvt-&gt;skype_callflow )) {
+                                DEBUGA_SKYPE(&quot;returning as available skype interface name: %s, state: %d callflow: %d\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;name, skype_state, tech_pvt-&gt;skype_callflow);
</ins><span class="cx">                                 /*set to Dialing state to avoid other thread fint it, don't know if it is safe */
</span><span class="cx">                                 //XXX no, it's not safe 
</span><del>-                                //tech_pvt-&gt;interface_state = SKYPIAX_STATE_DIALING ;
</del><ins>+                                if(tech_pvt_calling == NULL){
+                                tech_pvt-&gt;interface_state = SKYPIAX_STATE_SELECTED ;
+                                }
</ins><span class="cx"> 
</span><span class="cx">                                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">                                 return tech_pvt;
</span><span class="lines">@@ -1796,6 +1865,8 @@
</span><span class="cx"> 
</span><span class="cx">         if (found) {
</span><span class="cx">                 //tech_pvt-&gt;callid_number[0]='\0';
</span><ins>+                        //sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
+                                        //skypiax_signaling_write(tech_pvt, msg_to_skype);
</ins><span class="cx">                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">                 return 0;
</span><span class="cx">         }
</span><span class="lines">@@ -1822,7 +1893,9 @@
</span><span class="cx">         } else if (!tech_pvt || !tech_pvt-&gt;skype_call_id) {
</span><span class="cx">                 ERRORA(&quot;No Call ID?\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         } else {
</span><del>-                ERRORA(&quot;We're in a call now %s\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id);
</del><ins>+                DEBUGA_SKYPE(&quot;We're in a call now (%s), let's refuse this one (%s)\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
+                        sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
+                                        skypiax_signaling_write(tech_pvt, msg_to_skype);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_unlock(globals.mutex);
</span><span class="lines">@@ -1858,6 +1931,8 @@
</span><span class="cx"> 
</span><span class="cx">         if (found) {
</span><span class="cx">                 //tech_pvt-&gt;callid_number[0]='\0';
</span><ins>+                        //sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
+                                        //skypiax_signaling_write(tech_pvt, msg_to_skype);
</ins><span class="cx">                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">                 return 0;
</span><span class="cx">         }
</span><span class="lines">@@ -1899,12 +1974,14 @@
</span><span class="cx"> 
</span><span class="cx">                 if (found) {
</span><span class="cx">                         //tech_pvt-&gt;callid_number[0]='\0';
</span><ins>+                        //sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
+                                        //skypiax_signaling_write(tech_pvt, msg_to_skype);
</ins><span class="cx">                         switch_mutex_unlock(globals.mutex);
</span><span class="cx">                         return 0;
</span><span class="cx">                 }
</span><span class="cx">                 DEBUGA_SKYPE(&quot;NOT FOUND\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx"> 
</span><del>-                available_skypiax_interface = find_available_skypiax_interface(tech_pvt);
</del><ins>+                available_skypiax_interface = find_available_skypiax_interface_rr(tech_pvt);
</ins><span class="cx">                 if (available_skypiax_interface) {
</span><span class="cx">                         /* there is a skypiax interface idle, let's transfer the call to it */
</span><span class="cx"> 
</span><span class="lines">@@ -1922,14 +1999,15 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         /* no skypiax interfaces idle, do nothing */
</span><span class="cx">                         DEBUGA_SKYPE
</span><del>-                                (&quot;Not answering the skype_call %s, because we are already in a skypiax call(%s) and no other skypiax interfaces are available OR another interface is answering this call\n&quot;,
-                                 SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
-                        //sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
</del><ins>+                                (&quot;Not answering the skype_call %s, because we are already in a skypiax call(%s) and not transferring, because no other skypiax interfaces are available\n&quot;,
+                                 SKYPIAX_P_LOG, id, tech_pvt-&gt;skype_call_id);
+                        sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
+                                        skypiax_signaling_write(tech_pvt, msg_to_skype);
</ins><span class="cx">                 }
</span><span class="cx">                 switch_sleep(10000);
</span><span class="cx">                 DEBUGA_SKYPE
</span><del>-                        (&quot;We (%s) have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n&quot;,
-                         SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
</del><ins>+                        (&quot;We have NOT answered a Skype RING from skype_call %s, because we are already in a skypiax call (%s)\n&quot;,
+                         SKYPIAX_P_LOG, id, tech_pvt-&gt;skype_call_id);
</ins><span class="cx"> 
</span><span class="cx">                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">         }
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxskypiaxh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h (14516 => 14517)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h        2009-08-14 13:27:27 UTC (rev 14516)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h        2009-08-14 17:12:09 UTC (rev 14517)
</span><span class="lines">@@ -98,6 +98,8 @@
</span><span class="cx"> #define                SKYPIAX_STATE_UP                5
</span><span class="cx"> #define                SKYPIAX_STATE_RINGING        6
</span><span class="cx"> #define                SKYPIAX_STATE_PRERING        7
</span><ins>+#define                SKYPIAX_STATE_ERROR_DOUBLE_CALL        8
+#define                SKYPIAX_STATE_SELECTED        9
</ins><span class="cx"> /*********************************/
</span><span class="cx"> /* call flow from the device */
</span><span class="cx"> #define         CALLFLOW_CALL_IDLE  SKYPIAX_STATE_DOWN
</span><span class="lines">@@ -244,7 +246,6 @@
</span><span class="cx"> typedef struct private_object private_t;
</span><span class="cx"> 
</span><span class="cx"> void *SWITCH_THREAD_FUNC skypiax_api_thread_func(switch_thread_t * thread, void *obj);
</span><del>-void skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *session);
</del><span class="cx"> int skypiax_audio_read(private_t * tech_pvt);
</span><span class="cx"> int skypiax_audio_init(private_t * tech_pvt);
</span><span class="cx"> int skypiax_signaling_write(private_t * tech_pvt, char *msg_to_skype);
</span><span class="lines">@@ -277,8 +278,9 @@
</span><span class="cx"> #endif /* WIN32 */
</span><span class="cx"> int skypiax_close_socket(unsigned int fd);
</span><span class="cx"> private_t *find_available_skypiax_interface(private_t * tech_pvt);
</span><del>-private_t *find_available_skypiax_interface_rr(void);
</del><ins>+private_t *find_available_skypiax_interface_rr(private_t * tech_pvt_calling);
</ins><span class="cx"> int remote_party_is_ringing(private_t * tech_pvt);
</span><span class="cx"> int remote_party_is_early_media(private_t * tech_pvt);
</span><span class="cx"> int skypiax_answer(private_t * tech_pvt, char *id, char *value);
</span><span class="cx"> int skypiax_transfer(private_t * tech_pvt, char *id, char *value);
</span><ins>+int skypiax_socket_create_and_bind(private_t * tech_pvt, int * which_port);
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxskypiax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14516 => 14517)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c        2009-08-14 13:27:27 UTC (rev 14516)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c        2009-08-14 17:12:09 UTC (rev 14517)
</span><span class="lines">@@ -25,6 +25,47 @@
</span><span class="cx"> int xerror = 0;
</span><span class="cx"> #endif /* WIN32 */
</span><span class="cx"> /*************************************/
</span><ins>+
+int skypiax_socket_create_and_bind(private_t * tech_pvt, int * which_port)
+{
+        int s=-1;
+        struct sockaddr_in my_addr;
+        int start_port = 6001;
+
+        memset(&amp;my_addr, 0, sizeof(my_addr));
+        my_addr.sin_family = AF_INET;
+        my_addr.sin_addr.s_addr = htonl(0x7f000001);        /* use the localhost */
+
+        if ((s = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) {
+                ERRORA(&quot;socket Error\n&quot;, SKYPIAX_P_LOG);
+                return -1;
+        }
+
+        if(*which_port != 0)
+                start_port = *which_port;
+
+        my_addr.sin_port = htons(start_port);
+        //tech_pvt-&gt;tcp_cli_port = start_port;
+        *which_port = start_port;
+        while (bind(s, (struct sockaddr *) &amp;my_addr, sizeof(struct sockaddr)) &lt; 0) {
+                DEBUGA_SKYPE(&quot;*which_port=%d, tech_pvt-&gt;tcp_cli_port=%d, tech_pvt-&gt;tcp_srv_port=%d\n&quot;, SKYPIAX_P_LOG, *which_port, tech_pvt-&gt;tcp_cli_port, tech_pvt-&gt;tcp_srv_port);
+                DEBUGA_SKYPE(&quot;EADDRINUSE=%d, bind errno=%d, error: %s\n&quot;, SKYPIAX_P_LOG, EADDRINUSE, errno, strerror(errno));
+                start_port++;
+                my_addr.sin_port = htons(start_port);
+                *which_port = start_port;
+                DEBUGA_SKYPE(&quot;*which_port=%d, tech_pvt-&gt;tcp_cli_port=%d, tech_pvt-&gt;tcp_srv_port=%d\n&quot;, SKYPIAX_P_LOG, *which_port, tech_pvt-&gt;tcp_cli_port, tech_pvt-&gt;tcp_srv_port);
+
+                if(start_port &gt; 65000){
+                        ERRORA(&quot;NO MORE PORTS! *which_port=%d, tech_pvt-&gt;tcp_cli_port=%d, tech_pvt-&gt;tcp_srv_port=%d\n&quot;, SKYPIAX_P_LOG, *which_port, tech_pvt-&gt;tcp_cli_port, tech_pvt-&gt;tcp_srv_port);
+                        return -1;
+                }
+                //usleep(100);
+        }
+
+        DEBUGA_SKYPE(&quot;SUCCESS! *which_port=%d, tech_pvt-&gt;tcp_cli_port=%d, tech_pvt-&gt;tcp_srv_port=%d\n&quot;, SKYPIAX_P_LOG, *which_port, tech_pvt-&gt;tcp_cli_port, tech_pvt-&gt;tcp_srv_port);
+        return s;
+}
+
</ins><span class="cx"> int skypiax_signaling_read(private_t * tech_pvt)
</span><span class="cx"> {
</span><span class="cx">         char read_from_pipe[4096];
</span><span class="lines">@@ -49,9 +90,9 @@
</span><span class="cx"> 
</span><span class="cx">                 if (read_from_pipe[i] == '\0') {
</span><span class="cx"> 
</span><del>-                        if (!strstr(message, &quot;DURATION&quot;)) {
</del><ins>+                        //if (!strstr(message, &quot;DURATION&quot;)) {
</ins><span class="cx">                                 DEBUGA_SKYPE(&quot;READING: |||%s||| \n&quot;, SKYPIAX_P_LOG, message);
</span><del>-                        }
</del><ins>+                        //}
</ins><span class="cx"> 
</span><span class="cx">                         if (!strcasecmp(message, &quot;ERROR 68&quot;)) {
</span><span class="cx">                                 DEBUGA_SKYPE
</span><span class="lines">@@ -75,20 +116,48 @@
</span><span class="cx">                                         tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><del>-                        skypiax_strncpy(message_2, message, sizeof(message) - 1);
-                        buf = message;
-                        stringp = &amp;buf;
-                        where = strsep(stringp, &quot; &quot;);
-                        if (!where) {
-                                WARNINGA(&quot;Skype MSG without spaces: %s\n&quot;, SKYPIAX_P_LOG, message);
</del><ins>+                                /*
+                        if (!strncasecmp(message, &quot;ERROR 96 CALL&quot;, 12) ) {
+                                ERRORA(&quot;Skype got ERROR: |||%s|||, we are trying to use this interface to make or receive a call, but another call is half-active on this interface. We abort this attenpt and leave the previous one to continue.\n&quot;, SKYPIAX_P_LOG, message);
+                                tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
+                                DEBUGA_SKYPE(&quot;skype_call now is DOWN\n&quot;, SKYPIAX_P_LOG);
+                                tech_pvt-&gt;skype_call_id[0] = '\0';
+
+                                if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+                                        tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
+                                        return CALLFLOW_INCOMING_HANGUP;
+                                } else {
+                                        tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
+                                }
</ins><span class="cx">                         }
</span><del>-                        if (!strcasecmp(message, &quot;ERROR&quot;)) {
-                                if (!strncasecmp(message, &quot;ERROR 592 ALTER CALL&quot;, 19)) {
</del><ins>+                                */
+                        /*
+                        if (!strncasecmp(message, &quot;ERROR 99 CALL&quot;, 12) ) {
+                                //TODO: let's kill the call
+                                ERRORA(&quot;Skype got ERROR: |||%s|||, another call is active on this interface\n\n\n&quot;, SKYPIAX_P_LOG, message);
+                                //tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
+                                //DEBUGA_SKYPE(&quot;skype_call now is DOWN\n&quot;, SKYPIAX_P_LOG);
+                                //tech_pvt-&gt;skype_call_id[0] = '\0';
+
+                                        tech_pvt-&gt;interface_state = SKYPIAX_STATE_ERROR_DOUBLE_CALL;
+                        }
+                        */
+
+
+                        if (!strncasecmp(message, &quot;ERROR&quot;, 4)) {
+                                if (!strncasecmp(message, &quot;ERROR 96 CALL&quot;, 12) ) {
+                                        DEBUGA_SKYPE(&quot;Skype got ERROR: |||%s|||, we are trying to use this interface to make or receive a call, but another call is half-active on this interface. Let's the previous one to continue.\n&quot;, SKYPIAX_P_LOG, message);
+                                } else if (!strncasecmp(message, &quot;ERROR 99 CALL&quot;, 12) ) {
+                                        ERRORA(&quot;Skype got ERROR: |||%s|||, another call is active on this interface\n\n\n&quot;, SKYPIAX_P_LOG, message);
+                                        tech_pvt-&gt;interface_state = SKYPIAX_STATE_ERROR_DOUBLE_CALL;
+                                } else if (!strncasecmp(message, &quot;ERROR 592 ALTER CALL&quot;, 19)) {
</ins><span class="cx">                                         ERRORA(&quot;Skype got ERROR about TRANSFERRING, no problem: |||%s|||\n&quot;, SKYPIAX_P_LOG, message);
</span><ins>+                                } else if (!strncasecmp(message, &quot;ERROR 559 CALL&quot;, 13)) {
+                                        DEBUGA_SKYPE(&quot;Skype got ERROR about a failed action (probably TRYING to HANGUP A CALL), no problem: |||%s|||\n&quot;, SKYPIAX_P_LOG, message);
</ins><span class="cx">                                 } else {
</span><del>-                                        DEBUGA_SKYPE(&quot;Skype got ERROR: |||%s|||\n&quot;, SKYPIAX_P_LOG, message);
</del><ins>+                                        ERRORA(&quot;Skype got ERROR: |||%s|||\n&quot;, SKYPIAX_P_LOG, message);
</ins><span class="cx">                                         tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
</span><del>-                                        DEBUGA_SKYPE(&quot;skype_call now is DOWN\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                                        ERRORA(&quot;skype_call now is DOWN\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">                                         tech_pvt-&gt;skype_call_id[0] = '\0';
</span><span class="cx"> 
</span><span class="cx">                                         if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
</span><span class="lines">@@ -99,6 +168,25 @@
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><ins>+
+
+
+
+                        skypiax_strncpy(message_2, message, sizeof(message) - 1);
+                        buf = message;
+                        stringp = &amp;buf;
+                        where = strsep(stringp, &quot; &quot;);
+                        if (!where) {
+                                WARNINGA(&quot;Skype MSG without spaces: %s\n&quot;, SKYPIAX_P_LOG, message);
+                        }
+
+
+
+
+
+
+
+
</ins><span class="cx">                         if (!strcasecmp(message, &quot;CURRENTUSERHANDLE&quot;)) {
</span><span class="cx">                                 skypiax_strncpy(obj, where, sizeof(obj) - 1);
</span><span class="cx">                                 where = strsep(stringp, &quot; &quot;);
</span><span class="lines">@@ -163,7 +251,8 @@
</span><span class="cx">                                 //SKYPIAX_P_LOG, message, obj, id, prop, value, where ? where : &quot;NULL&quot;);
</span><span class="cx"> 
</span><span class="cx">                                 if (!strcasecmp(prop, &quot;PARTNER_HANDLE&quot;)) {
</span><del>-                                        if (!strlen(tech_pvt-&gt;skype_call_id)) {
</del><ins>+                                        if (!strlen(tech_pvt-&gt;skype_call_id) || !strlen(tech_pvt-&gt;session_uuid_str)) {
+                                        //if (!strlen(tech_pvt-&gt;skype_call_id)) {
</ins><span class="cx">                                                 /* we are NOT inside an active call */
</span><span class="cx">                                                 DEBUGA_SKYPE(&quot;Call %s TRY ANSWER\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="cx">                                                 skypiax_answer(tech_pvt, id, value);
</span><span class="lines">@@ -171,7 +260,7 @@
</span><span class="cx">                                                 /* we are inside an active call */
</span><span class="cx">                                                 if (!strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
</span><span class="cx">                                                         /* this is the call in which we are calling out */
</span><del>-                                                        DEBUGA_SKYPE(&quot;Call %s NOTHING\n&quot;, SKYPIAX_P_LOG, id);
</del><ins>+                                                        DEBUGA_SKYPE(&quot;Call %s DO NOTHING\n&quot;, SKYPIAX_P_LOG, id);
</ins><span class="cx">                                                 } else {
</span><span class="cx">                                                         skypiax_sleep(400000);        //0.4 seconds
</span><span class="cx">                                                         DEBUGA_SKYPE(&quot;Call %s TRY TRANSFER\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="lines">@@ -208,12 +297,25 @@
</span><span class="cx">                                                 DEBUGA_SKYPE(&quot;We called a Skype contact and he answered us on skype_call: %s.\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><ins>+
+                                if (!strcasecmp(prop, &quot;DURATION&quot;) &amp;&amp; (tech_pvt-&gt;interface_state == SKYPIAX_STATE_ERROR_DOUBLE_CALL)) {
+                                        char msg_to_skype[1024];
+                                        skypiax_strncpy(tech_pvt-&gt;skype_call_id, id, sizeof(tech_pvt-&gt;skype_call_id) - 1);
+                                        ERRORA(&quot;We are in a double call situation, trying to get out hanging up call id: %s.\n&quot;, SKYPIAX_P_LOG, id);
+                                        sprintf(msg_to_skype, &quot;ALTER CALL %s HANGUP&quot;, id);
+                                        skypiax_signaling_write(tech_pvt, msg_to_skype);
+                                        skypiax_sleep(10000);
+                                        //return CALLFLOW_INCOMING_HANGUP;
+                                }
+
</ins><span class="cx">                                 if (!strcasecmp(prop, &quot;STATUS&quot;)) {
</span><span class="cx"> 
</span><span class="cx">                                         if (!strcasecmp(value, &quot;RINGING&quot;)) {
</span><span class="cx">                                                 char msg_to_skype[1024];
</span><del>-                                                if (!strlen(tech_pvt-&gt;skype_call_id)) {
</del><ins>+                                                if ( (tech_pvt-&gt;interface_state != SKYPIAX_STATE_SELECTED &amp;&amp; tech_pvt-&gt;interface_state != SKYPIAX_STATE_DIALING ) &amp;&amp; (!strlen(tech_pvt-&gt;skype_call_id) || !strlen(tech_pvt-&gt;session_uuid_str)) ) {
</ins><span class="cx">                                                         /* we are NOT inside an active call */
</span><ins>+
+                                                                DEBUGA_SKYPE(&quot;NO ACTIVE calls in this moment, skype_call %s is RINGING, to ask PARTNER_HANDLE\n&quot;, SKYPIAX_P_LOG, id);
</ins><span class="cx">                                                         sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_HANDLE&quot;, id);
</span><span class="cx">                                                         skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="cx">                                                         skypiax_sleep(10000);
</span><span class="lines">@@ -227,6 +329,7 @@
</span><span class="cx">                                                                 DEBUGA_SKYPE(&quot;Our remote party in skype_call %s is RINGING\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="cx">                                                                 remote_party_is_ringing(tech_pvt);
</span><span class="cx">                                                         } else {
</span><ins>+                                                                DEBUGA_SKYPE(&quot;We are in another call, but skype_call %s is RINGING on us, let's ask PARTNER_HANDLE, so maybe we'll TRANSFER\n&quot;, SKYPIAX_P_LOG, id);
</ins><span class="cx">                                                                 sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_HANDLE&quot;, id);
</span><span class="cx">                                                                 skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="cx">                                                                 skypiax_sleep(10000);
</span><span class="lines">@@ -237,7 +340,10 @@
</span><span class="cx">                                                 tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
</span><span class="cx">                                                 tech_pvt-&gt;interface_state = SKYPIAX_STATE_DIALING;
</span><span class="cx">                                                 DEBUGA_SKYPE(&quot;Our remote party in skype_call %s is EARLYMEDIA\n&quot;, SKYPIAX_P_LOG, id);
</span><del>-                                                start_audio_threads(tech_pvt);
</del><ins>+                                                if (start_audio_threads(tech_pvt)){
+                                                        ERRORA(&quot;start_audio_threads FAILED\n&quot;, SKYPIAX_P_LOG);
+                                                        return CALLFLOW_INCOMING_HANGUP;
+                                                }
</ins><span class="cx">                                                 skypiax_sleep(1000);
</span><span class="cx">                                                 sprintf(msg_to_skype, &quot;ALTER CALL %s SET_INPUT PORT=\&quot;%d\&quot;&quot;, id, tech_pvt-&gt;tcp_cli_port);
</span><span class="cx">                                                 skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="lines">@@ -251,9 +357,9 @@
</span><span class="cx">                                                 //DEBUGA_SKYPE(&quot;skype_call %s now is DOWN\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="cx">                                                 //usleep(150000);//150msec, let's give the TCP sockets time to timeout
</span><span class="cx">                                                 if (!strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
</span><del>-                                                        tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
</del><ins>+                                                        //tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
</ins><span class="cx">                                                         DEBUGA_SKYPE(&quot;skype_call %s is MY call, now I'm going DOWN\n&quot;, SKYPIAX_P_LOG, id);
</span><del>-                                                        tech_pvt-&gt;skype_call_id[0] = '\0';
</del><ins>+                                                        //tech_pvt-&gt;skype_call_id[0] = '\0';
</ins><span class="cx">                                                         if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
</span><span class="cx">                                                                 //tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
</span><span class="cx">                                                                 return CALLFLOW_INCOMING_HANGUP;
</span><span class="lines">@@ -311,6 +417,9 @@
</span><span class="cx">                                         } else if (!strcasecmp(value, &quot;INPROGRESS&quot;)) {
</span><span class="cx">                                                 char msg_to_skype[1024];
</span><span class="cx"> 
</span><ins>+                                                if (!strlen(tech_pvt-&gt;session_uuid_str)) {
+                                                        DEBUGA_SKYPE(&quot;no tech_pvt-&gt;session_uuid_str\n&quot;, SKYPIAX_P_LOG);
+                                                }
</ins><span class="cx">                                                 if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
</span><span class="cx">                                                         if (!strlen(tech_pvt-&gt;session_uuid_str) || !strlen(tech_pvt-&gt;skype_call_id)
</span><span class="cx">                                                                 || !strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
</span><span class="lines">@@ -320,7 +429,11 @@
</span><span class="cx">                                                                 if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_EARLYMEDIA) {
</span><span class="cx">                                                                         tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_INPROGRESS;
</span><span class="cx">                                                                         tech_pvt-&gt;interface_state = SKYPIAX_STATE_UP;
</span><del>-                                                                        start_audio_threads(tech_pvt);
</del><ins>+
+                                                if (start_audio_threads(tech_pvt)){
+                                                        ERRORA(&quot;start_audio_threads FAILED\n&quot;, SKYPIAX_P_LOG);
+                                                        return CALLFLOW_INCOMING_HANGUP;
+                                                }
</ins><span class="cx">                                                                         skypiax_sleep(1000);        //FIXME
</span><span class="cx">                                                                         sprintf(msg_to_skype, &quot;ALTER CALL %s SET_INPUT PORT=\&quot;%d\&quot;&quot;, id, tech_pvt-&gt;tcp_cli_port);
</span><span class="cx">                                                                         skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="lines">@@ -330,7 +443,7 @@
</span><span class="cx">                                                                 }
</span><span class="cx">                                                                 tech_pvt-&gt;skype_callflow = SKYPIAX_STATE_UP;
</span><span class="cx">                                                                 if (!strlen(tech_pvt-&gt;session_uuid_str)) {
</span><del>-                                                                        DEBUGA_SKYPE(&quot;New Inbound Channel!\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                                                                        DEBUGA_SKYPE(&quot;New Inbound Channel!\n\n\n\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">                                                                         new_inbound_channel(tech_pvt);
</span><span class="cx">                                                                 } else {
</span><span class="cx">                                                                         DEBUGA_SKYPE(&quot;Outbound Channel Answered!\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -413,13 +526,14 @@
</span><span class="cx">         unsigned int fd;
</span><span class="cx">         short srv_in[SAMPLES_PER_FRAME];
</span><span class="cx">         short srv_out[SAMPLES_PER_FRAME / 2];
</span><del>-        struct sockaddr_in my_addr;
</del><ins>+        //struct sockaddr_in my_addr;
</ins><span class="cx">         struct sockaddr_in remote_addr;
</span><span class="cx">         //int exit = 0;
</span><span class="cx">         unsigned int kill_cli_size;
</span><span class="cx">         short kill_cli_buff[SAMPLES_PER_FRAME];
</span><span class="cx">         short totalbuf[SAMPLES_PER_FRAME];
</span><span class="cx"> 
</span><ins>+#ifdef  NOTDEF
</ins><span class="cx">         memset(&amp;my_addr, 0, sizeof(my_addr));
</span><span class="cx">         my_addr.sin_family = AF_INET;
</span><span class="cx">         my_addr.sin_addr.s_addr = htonl(0x7f000001);        /* use the localhost */
</span><span class="lines">@@ -427,13 +541,23 @@
</span><span class="cx"> 
</span><span class="cx">         if ((s = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) {
</span><span class="cx">                 ERRORA(&quot;socket Error\n&quot;, SKYPIAX_P_LOG);
</span><ins>+                tech_pvt-&gt;tcp_srv_thread = NULL;
</ins><span class="cx">                 return NULL;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (bind(s, (struct sockaddr *) &amp;my_addr, sizeof(struct sockaddr)) &lt; 0) {
</span><del>-                ERRORA(&quot;bind Error\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                ERRORA(&quot;bind error: %s\n&quot;, SKYPIAX_P_LOG, strerror(errno));
+                tech_pvt-&gt;tcp_srv_thread = NULL;
</ins><span class="cx">                 return NULL;
</span><span class="cx">         }
</span><ins>+#endif //NOTDEF
+
+        s = skypiax_socket_create_and_bind(tech_pvt, &amp;tech_pvt-&gt;tcp_srv_port);
+        if(s &lt; 0)
+        {
+                ERRORA(&quot;skypiax_socket_create_and_bind error!\n&quot;, SKYPIAX_P_LOG);
+                return NULL;
+        }
</ins><span class="cx">         DEBUGA_SKYPE(&quot;started tcp_srv_thread thread.\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx"> 
</span><span class="cx">         listen(s, 6);
</span><span class="lines">@@ -546,7 +670,7 @@
</span><span class="cx">                                                 } else if (len == 0) {
</span><span class="cx">                                                         skypiax_sleep(1000);
</span><span class="cx">                                                 } else {
</span><del>-                                                        ERRORA(&quot;len=%d, expected 320\n&quot;, SKYPIAX_P_LOG, len);
</del><ins>+                                                        DEBUGA_SKYPE(&quot;len=%d, expected 320\n&quot;, SKYPIAX_P_LOG, len);
</ins><span class="cx">                                                 }
</span><span class="cx"> 
</span><span class="cx">                                         } else {
</span><span class="lines">@@ -578,6 +702,7 @@
</span><span class="cx"> 
</span><span class="cx">         DEBUGA_SKYPE(&quot;incoming audio server (I am it) EXITING\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         skypiax_close_socket(s);
</span><ins>+        tech_pvt-&gt;tcp_srv_thread = NULL;
</ins><span class="cx">         return NULL;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -585,7 +710,7 @@
</span><span class="cx"> {
</span><span class="cx">         private_t *tech_pvt = obj;
</span><span class="cx">         int s;
</span><del>-        struct sockaddr_in my_addr;
</del><ins>+        //struct sockaddr_in my_addr;
</ins><span class="cx">         struct sockaddr_in remote_addr;
</span><span class="cx">         unsigned int got;
</span><span class="cx">         unsigned int len;
</span><span class="lines">@@ -600,6 +725,7 @@
</span><span class="cx">         unsigned int sin_size;
</span><span class="cx"> #endif /* WIN32 */
</span><span class="cx"> 
</span><ins>+#ifdef NOTDEF
</ins><span class="cx">         memset(&amp;my_addr, 0, sizeof(my_addr));
</span><span class="cx">         my_addr.sin_family = AF_INET;
</span><span class="cx">         my_addr.sin_addr.s_addr = htonl(0x7f000001);        /* use the localhost */
</span><span class="lines">@@ -607,14 +733,29 @@
</span><span class="cx"> 
</span><span class="cx">         if ((s = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0) {
</span><span class="cx">                 ERRORA(&quot;socket Error\n&quot;, SKYPIAX_P_LOG);
</span><ins>+                tech_pvt-&gt;tcp_cli_thread = NULL;
</ins><span class="cx">                 return NULL;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (bind(s, (struct sockaddr *) &amp;my_addr, sizeof(struct sockaddr)) &lt; 0) {
</span><del>-                ERRORA(&quot;bind Error\n&quot;, SKYPIAX_P_LOG);
</del><ins>+                //ERRORA(&quot;bind Error\n&quot;, SKYPIAX_P_LOG);
+                ERRORA(&quot;bind error: %s\n&quot;, SKYPIAX_P_LOG, strerror(errno));
</ins><span class="cx">                 skypiax_close_socket(s);
</span><ins>+                tech_pvt-&gt;tcp_cli_thread = NULL;
</ins><span class="cx">                 return NULL;
</span><span class="cx">         }
</span><ins>+
+#endif // NOTDEF
+
+        s = skypiax_socket_create_and_bind(tech_pvt, &amp;tech_pvt-&gt;tcp_cli_port);
+        if(s &lt; 0)
+        {
+                ERRORA(&quot;skypiax_socket_create_and_bind error!\n&quot;, SKYPIAX_P_LOG);
+                return NULL;
+        }
+
+
+
</ins><span class="cx">         DEBUGA_SKYPE(&quot;started tcp_cli_thread thread.\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx"> 
</span><span class="cx">         listen(s, 6);
</span><span class="lines">@@ -764,6 +905,7 @@
</span><span class="cx"> 
</span><span class="cx">         DEBUGA_SKYPE(&quot;outbound audio server (I am it) EXITING\n&quot;, SKYPIAX_P_LOG);
</span><span class="cx">         skypiax_close_socket(s);
</span><ins>+        tech_pvt-&gt;tcp_cli_thread = NULL;
</ins><span class="cx">         return NULL;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>