多线程开发的主要的工作就是就是使用多个 eXosip_t
int i,j;
TRACE_INITIALIZE (6, NULL);
m_ctx1 = eXosip_malloc();
m_ctx1 = eXosip_malloc();
if (m_ctx1==NULL || m_ctx2==NULL)
{
FLOG("eXosip_malloc failed\n");
return -1;
}
i=eXosip_init(m_ctx1);
j=eXosip_init(m_ctx2);
if (i!=0 || j!=0)
{
FLOG("eXosip_init failed\n");
return -1;
}
i = eXosip_listen_addr(m_ctx, IPPROTO_TCP, NULL, 5060, AF_INET, 0);
j = eXosip_listen_addr(m_ctx, IPPROTO_UDP, NULL, 5061, AF_INET, 0);
if (i!=0)
{
eXosip_quit(m_ctx1);
FLOG ("could not initialize transport layer\n");
return -1;
}
if (j!=0)
{
eXosip_quit(m_ctx2);
FLOG ("could not initialize transport layer\n");
return -1;
}
void* eventLoop1(void*)
{
/* use events to print some info */
eXosip_event_t *je;
osip_message_t *ack = NULL;
osip_message_t *answer = NULL;
for (;;)
{
je = eXosip_event_wait (m_ctx1, 0, 50);
eXosip_lock (m_ctx1);
eXosip_default_action (m_ctx1, je);
eXosip_unlock (m_ctx1);
if (je == NULL)
continue;
/* your code here */
eXosip_event_free (je);
}
}
void* eventLoop2(void*)
{
/* use events to print some info */
eXosip_event_t *je;
osip_message_t *ack = NULL;
osip_message_t *answer = NULL;
for (;;)
{
je = eXosip_event_wait (m_ctx2, 0, 50);
eXosip_lock (m_ctx2);
eXosip_default_action (m_ctx2, je);
eXosip_unlock (m_ctx2);
if (je == NULL)
continue;
/* your code here */
eXosip_event_free (je);
}
}