最近在研究sip相關的一些東西,單個idoubs在iphone上能夠正常運行,可是同時運行兩個的話,會有一個註冊不到服務器,抓包跟了很久都不知道是什麼問題,例如如今有兩個idoubs在iphone上,,暫且命名爲idoubs1和idoubs2吧.它們兩個是分別鏈接到不一樣的服務,接收的端口也是不同的. 服務器
若是我先運行idoubs1,正常鏈接以後,再開啓idoubs2,這時idoubs2卻鏈接不上服務器了.實際上idoubs2有發了註冊消息給服務器.服務器也返回了消息給idoubs2.可是sip層中用於接收sip消息的函數 iphone
static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)卻沒有響應,接着,我只能把斷點設到udp層的recvfrom()函數裏面,調試了不少次發現設在recvfrom()函數前面的斷點沒有停,弄了很久也不知道什麼緣由,覺得不是用recvfrom()來接收udp消息的,但那又不可能呀..後來把工程cleanup一遍,recvfrom()前的斷點終於停下來了,把收到的消息打印出來,發現程序是收到了消息的.關鍵是在把消息傳到sip層的時候出了問題. 函數
接着發了在static int tsip_transport_layer_stream_cb(const tnet_transport_event_t* e)這個函數所回調的地方,有個宏定義的信號量,這個宏定義有點奇怪. spa
#define TSK_RUNNABLE_RUN_BEGIN(self) \ TSK_RUNNABLE(self)->running = tsk_true; \ for(;;) { \ tsk_semaphore_decrement(TSK_RUNNABLE(self)->semaphore); \ if(!TSK_RUNNABLE(self)->running && \ (!TSK_RUNNABLE(self)->important || (TSK_RUNNABLE(self)->important && TSK_LIST_IS_EMPTY(TSK_RUNNABLE(self)->objects)))) \ break; #define TSK_RUNNABLE_RUN_END(self) \ } \ TSK_RUNNABLE(self)->running = tsk_false;兩個宏, ,,其實就是把一段代碼拆分到兩個宏定義裏面,而後回調函數就是在兩個宏之間:
TSK_RUNNABLE_RUN_BEGIN(transport); if((curr = TSK_RUNNABLE_POP_FIRST_SAFE(TSK_RUNNABLE(transport)))){ const tnet_transport_event_t *e = (const tnet_transport_event_t*)curr->data; if(transport->callback){ transport->callback(e); } tsk_object_unref(curr); } TSK_RUNNABLE_RUN_END(transport);注意到第一個宏裏面的
tsk_semaphore_decrement()原來doubango裏面udp層和sip層之間是用sem_t信號量來通訊的.由於信號量是能夠實現進程間通訊的,忽然間明白爲何idoubs2的收不到sip消息了,若是信號量的標識符是同樣的話,那idoubs2的消息有可能發到idoubs1那裏去了,,
接着再去查信號量的初始化 調試
找到了這個函數 code
tsk_semaphore_handle_t* tsk_semaphore_create_2(int initial_val) 進程
tsk_semaphore_handle_t* tsk_semaphore_create_2(int initial_val) { SEMAPHORE_T handle = tsk_null; #if TSK_UNDER_WINDOWS handle = CreateSemaphore(NULL, initial_val, 0x7FFFFFFF, NULL); #else handle = tsk_calloc(1, sizeof(SEMAPHORE_S)); #if TSK_USE_NAMED_SEM named_sem_t * nsem = (named_sem_t*)handle; tsk_sprintf(&(nsem->name), "/sem-%d", sem_count++); if((nsem->sem = sem_open(nsem->name, O_CREAT /*| O_EXCL*/, S_IRUSR | S_IWUSR, initial_val)) == SEM_FAILED) { TSK_FREE(nsem->name); #else if(sem_init((SEMAPHORE_T)handle, 0, initial_val)) { #endif TSK_FREE(handle); TSK_DEBUG_ERROR("Failed to initialize the new semaphore (errno=%d).", errno); } #endif if(!handle){ TSK_DEBUG_ERROR("Failed to create new semaphore"); } return handle; }查了一下資料,,定位到
tsk_sprintf(&(nsem->name), "/sem-%d", sem_count++);只要把"/sem-%d" 改爲不同就好了.."/1sem-%d"..
問題就終於解決啦.. ip