Hi!
It's already implemented - if module's command handler returns NXMOD_COMMAND_ACCEPTED_ASYNC, main session processing thread will not delete message. Also, session's usage counter increased in this case, so it is guaranteed that session object passed to handler will be valid. When your module finishes async command processing, it must delete message and call method decRefCount() on session object. My code to start async command processing in the module looks like following:
and then somewhere in the command handler:
Best regards,
Victor
It's already implemented - if module's command handler returns NXMOD_COMMAND_ACCEPTED_ASYNC, main session processing thread will not delete message. Also, session's usage counter increased in this case, so it is guaranteed that session object passed to handler will be valid. When your module finishes async command processing, it must delete message and call method decRefCount() on session object. My code to start async command processing in the module looks like following:
Code Select
typedef struct
{
void (*m_handler)(CSCPMessage *, ClientSession *);
CSCPMessage *m_msg;
ClientSession *m_session;
} PROCESSING_THREAD_DATA;
static THREAD_RESULT THREAD_CALL ProcessingThread(void *arg)
{
PROCESSING_THREAD_DATA *data = (PROCESSING_THREAD_DATA *)arg;
data->m_handler(data->m_msg, data->m_session);
delete data->m_msg;
data->m_session->decRefCount();
free(data);
return THREAD_OK;
}
static void StartCommandHandler(void (*pfHandler)(CSCPMessage *, ClientSession *),
CSCPMessage *msg, ClientSession *session)
{
PROCESSING_THREAD_DATA *data;
data = (PROCESSING_THREAD_DATA *)malloc(sizeof(PROCESSING_THREAD_DATA));
data->m_handler = pfHandler;
data->m_msg = msg;
data->m_session = session;
ThreadCreate(ProcessingThread, 0, data);
}
and then somewhere in the command handler:
Code Select
StartCommandHandler(GetSnapshot, msg, session);
return NXMOD_COMMAND_ACCEPTED_ASYNC;
Best regards,
Victor