freeswitch
freeswitch copied to clipboard
use esl lib connect freeswitch then recv esl event problem
A client-side ESL library for calling freeswitch is written in C + +
esl_ connect_ timeout(&_ evtEslHandle, _ eslHost.c_ str(), _ eslPort, _ eslUsername.c_ str(), _ eslPassword.c_ str(), 3000);
After the connection to freeswitch 1.10.1 is successful, call the ESL interface and subscribe to the event method:
esl_ events(&(fsApi->_ evtEslHandle), ESL_ EVENT_ TYPE_ PLAIN, "CHANNEL_ EXECUTE_ COMPLETE BACKGROUND_ JOB CHANNEL_ ORIGINATE CHANNEL_ PROGRESS_ MEDIA CHANNEL_ PROGRESS CHANNEL_ ANSWER DETECTED_ SPEECH DTMF CHANNEL_ HANGUP HEARTBEAT CUSTOM pti ptisdp spandsp::txfaxresult spandsp::rxfaxresult");
The program opens a thread to call the ESL interface
esl_ recv_ event_ timed(&(fsApi->_ evtEslHandle),3000, 1, NULL);
When receiving freeswitch events, it is found that when the concurrency is large and the running time is long (about a week), there will be receiving events, but the events can not be received (the delay is very large), but after about 5 minutes, the events can be automatically recovered. What is the problem? Is it free switch's ESL library bug? How to solve this problem? thank you!
Freeswitch version: 1.10.1
Attached receive event thread code block:
void* FsApi::workThreadProc(void param) { FsApi fsApi = (FsApi*)param; time_t tm = time(NULL); for (;;) { if (fsApi->eslConnect()) { if (fsApi->_workExit) break;
fsApi->_workReady = true;
if (fsApi->OnInitFs)
{
fsApi->OnInitFs();
}
esl_events(&(fsApi->_evtEslHandle), ESL_EVENT_TYPE_PLAIN, "CHANNEL_EXECUTE_COMPLETE BACKGROUND_JOB CHANNEL_ORIGINATE CHANNEL_PROGRESS_MEDIA CHANNEL_PROGRESS CHANNEL_ANSWER DETECTED_SPEECH DTMF CHANNEL_HANGUP HEARTBEAT CUSTOM pti ptisdp spandsp::txfaxresult spandsp::rxfaxresult");
if (fsApi->OnReady)
fsApi->OnReady(true);
for (;;)
{
if (!fsApi->_workReady)
{
break;
}
//esl_status_t status = esl_recv_event_timed(&(fsApi->_evtEslHandle), 40000, 1, NULL);
esl_status_t status = esl_recv_event_timed(&(fsApi->_evtEslHandle), fsApi>GetFsEslHeartbeatInterval()*1000, 1, NULL);
if (status == ESL_SUCCESS)
{
esl_event_t *e = fsApi->_evtEslHandle.last_ievent ? fsApi->_evtEslHandle.last_ievent : fsApi->_evtEslHandle.last_event;
if(e!=NULL)
{
fsApi->DetectEslHandle(e);
if (IsShowTipLog(tm, 20))
{
const char* unique_id = esl_event_get_header(e, "Unique-ID");
LOG4CPLUS_INFO(fsApi->_logger, __FUNCTION__ << " Tips event->event_id:" << e->event_id << " :" << FsApi::PrintFsApiEventType(e->event_id) << " unique_id:" << (unique_id==NULL?" ":unique_id));
}
#ifdef USE_ESLMSG_PROC CEslMsgProc::OnProcEslRecvData(fsApi, e);
#else fsApi->eslEventProc(e); #endif } else { LOG4CPLUS_WARN(fsApi->_logger, FUNCTION << " evtEslHandle esl_recv_event_timed e==NULL!");
}
continue;
}
else if (status == ESL_BREAK)
{
//LOG4CPLUS_INFO(fsApi->_logger, __FUNCTION__ << " evtEslHandle esl_recv_event_timed timeout break!");
continue;
}
else
{
//is reset socket
if (fsApi->ResetEslHandle())
{
continue;
}
//
LOG4CPLUS_WARN(fsApi->_logger, __FUNCTION__ << " evtEslHandle return status:" << status << " break!");
}
break;
}
}
fsApi->DetectEslHandle(NULL, false);
fsApi->_workReady = false;
if (fsApi->OnReady)
fsApi->OnReady(false);
if (fsApi->_workExit)
break;
fsApi->eslDisConnect();
cross_sleep(5000);
}
fsApi->eslDisConnect();
return 0;
}