seli.c
来自「基于h323协议的软phone」· C语言 代码 · 共 594 行 · 第 1/2 页
C
594 行
if (status == RV_OK)
userFd->callback = callbackFunc;
}
}
return status;
}
int seliSetMaxDescs(IN int maxDescs)
{
return RvSelectSetMaxFileDescriptors(maxDescs);
}
int seliGetMaxDescs(void)
{
RvUint32 maxFds;
maxFds = RvSelectGetMaxFileDescriptors();
if (maxFds == 0)
return RV_ERROR_UNKNOWN;
else
return (int)maxFds;
}
/* The following functions are only relevant for systems supporting the select() interface */
#ifdef fd_set
RvStatus seliSelectEventsRegistration(
IN int fdSetLen,
OUT int *num,
OUT fd_set *rdSet,
OUT fd_set *wrSet,
OUT fd_set *exSet,
OUT RvUint32 *timeOut)
{
RvSelectEngine* selectEngine;
RvStatus status;
RV_UNUSED_ARG(exSet);
/* Find the select engine for this thread at first */
status = ThreadInstanceGetObject(seliInstanceIndex, (void**)&selectEngine);
if (status != RV_OK)
return status;
/* Get fd_set bits from the select engine */
status = RvSelectGetSelectFds(selectEngine, num, rdSet, wrSet);
if (status != RV_OK)
return status;
/* We'll need to check the timeout as well... */
if (timerQueueInstanceIndex == RV_UINT32_MAX)
{
/* We need to find out the timer queue */
status = ThreadInstanceFindIndex(RV_THREAD_INSTANCE_TIMERS, &timerQueueInstanceIndex);
}
if (timerQueueInstanceIndex != RV_UINT32_MAX)
{
RvInt64 nextEvent = 0;
status = ThreadInstanceGetObject(timerQueueInstanceIndex, (void**)&timerQueue);
if (status == RV_OK)
status = RvTimerQueueNextEvent(timerQueue, &nextEvent);
if (status == RV_OK)
{
if (nextEvent > 0)
timeOut = (RvUint32)Rv64Divide(nextEvent, RV_TIME64_NSECPERMSEC);
else
timeOut = 0;
}
status = RV_OK; /* Make sure we select() */
}
return status;
}
RvStatus seliSelectEventsHandling(
IN fd_set *rdSet,
IN fd_set *wrSet,
IN fd_set *exSet,
IN int num,
IN int numEvents)
{
RvSelectEngine* selectEngine;
RvStatus status;
RV_UNUSED_ARG(exSet);
/* Find the select engine for this thread at first */
status = ThreadInstanceGetObject(seliInstanceIndex, (void**)&selectEngine);
if (status != RV_OK)
return status;
return RvSelectHandleSelectFds(selectEngine, rdSet, wrSet, num, numEvents);
}
#endif /* fd_set */
/* The following functions are only relevant for systems supporting the poll() interface */
#ifdef pollfd
RvStatus seliPollEventsRegistration(
IN int len,
OUT struct pollfd *pollFdSet,
OUT int *num,
OUT UINT32 *timeOut)
{
RvSelectEngine* selectEngine;
RvStatus status;
RV_UNUSED_ARG(exSet);
/* Find the select engine for this thread at first */
status = ThreadInstanceGetObject(seliInstanceIndex, (void**)&selectEngine);
if (status != RV_OK)
return status;
/* Get pollfd array from the select engine */
*num = len;
status = RvSelectGetPollFds(selectEngine, num, pollFdSet);
if (status != RV_OK)
return status;
/* We'll need to check the timeout as well... */
if (timerQueueInstanceIndex == RV_UINT32_MAX)
{
/* We need to find out the timer queue */
status = ThreadInstanceFindIndex(RV_THREAD_INSTANCE_TIMERS, &timerQueueInstanceIndex);
}
if (timerQueueInstanceIndex != RV_UINT32_MAX)
{
RvInt64 nextEvent = 0;
status = ThreadInstanceGetObject(timerQueueInstanceIndex, (void**)&timerQueue);
if (status == RV_OK)
status = RvTimerQueueNextEvent(timerQueue, &nextEvent);
if (status == RV_OK)
{
if (nextEvent > 0)
timeOut = (RvUint32)(nextEvent / RV_TIME64_NSECPERMSEC);
else
timeOut = 0;
}
status = RV_OK; /* Make sure we poll() */
}
return status;
}
RvStatus seliPollEventsHandling(
IN struct pollfd *pollFdSet,
IN int num,
IN int numEvents)
{
RvSelectEngine* selectEngine;
RvStatus status;
RV_UNUSED_ARG(exSet);
/* Find the select engine for this thread at first */
status = ThreadInstanceGetObject(seliInstanceIndex, (void**)&selectEngine);
if (status != RV_OK)
return status;
return RvSelectHandlePollFds(selectEngine, pollFdSet, num, numEvents);
}
#endif /* pollfd */
#if defined(RV_H323_COMPILE_WITH_DEAD_FUNCTIONS)
/* The following functions are here for backward compatability only.
They have no purpose besides that. */
int seliSetMaxTasks(int maxTasks)
{
RV_UNUSED_ARG(maxTasks);
return RV_TRUE;
}
int seliGetMaxTasks(void)
{
return RV_ERROR_UNKNOWN;
}
#endif /* defined(RV_H323_COMPILE_WITH_DEAD_FUNCTIONS) */
/*-----------------------------------------------------------------------*/
/* STATIC FUNCTIONS */
/*-----------------------------------------------------------------------*/
static RvStatus CreateSelectEngine(
IN const RvChar* objectName,
IN void* context,
IN RvSize_t amountNeeded,
INOUT void** objectPtr,
OUT RvSize_t* amountAllocated,
OUT ThreadInstanceDeleteFunc* deleteFunc)
{
RvSelectEngine* selectEngine;
RvStatus status;
RV_UNUSED_ARG(objectName);
RV_UNUSED_ARG(context);
RV_UNUSED_ARG(amountNeeded);
status = RvMemoryAlloc(NULL, (void**)&selectEngine, sizeof(RvSelectEngine));
if (status != RV_OK)
return status;
status = RvSelectConstruct(selectEngine, 2048);
if (status != RV_OK)
{
RvMemoryFree(selectEngine);
return status;
}
*deleteFunc = DeleteSelectEngine;
*amountAllocated = 0;
*objectPtr = selectEngine;
return RV_OK;
}
static RvStatus DeleteSelectEngine(
IN const RvChar* objectName,
IN void* context,
IN void* objectPtr)
{
RvSelectEngine* selectEngine = (RvSelectEngine *)objectPtr;
RV_UNUSED_ARG(objectName);
RV_UNUSED_ARG(context);
RvSelectDestruct(selectEngine);
return RvMemoryFree(selectEngine);
}
static void seliEventsCB(
IN RvSelectEngine* selectEngine,
IN RvSelectFd* fd,
IN RvSelectEvents selectEvent,
IN RvBool error)
{
SeliUserFd* userFd;
seliCallback cb;
RvSocket* s;
seliEvents seliEvent = (seliEvents)0;
RV_UNUSED_ARG(selectEngine);
userFd = RV_GET_STRUCT(SeliUserFd, fd, fd);
s = RvFdGetSocket(&userFd->fd);
if (selectEvent & RvSelectRead) seliEvent = seliEvRead;
else if (selectEvent & RvSelectWrite) seliEvent = seliEvWrite;
else return;
cb = userFd->callback;
if (cb != NULL)
cb((int)(*s), seliEvent, error);
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?