Example #1
0
//--------------------------------------------------------------------------------------------------
static void DeleteFdMonitor
(
    FdMonitor_t*            fdMonitorPtr        ///< [in] Pointer to the FD Monitor to be deleted.
)
//--------------------------------------------------------------------------------------------------
{
    event_PerThreadRec_t*   perThreadRecPtr = thread_GetEventRecPtr();

    LE_ASSERT(perThreadRecPtr == fdMonitorPtr->threadRecPtr);

    // Remove the FD Monitor from the thread's FD Monitor List.
    le_dls_Remove(&perThreadRecPtr->fdMonitorList, &fdMonitorPtr->link);

    LOCK

    // Delete the Safe References used for the FD Monitor and any of its Handler objects.
    le_ref_DeleteRef(FdMonitorRefMap, fdMonitorPtr->safeRef);

    UNLOCK

    // Tell epoll(7) to stop monitoring this fd.
    StopMonitoringFd(fdMonitorPtr);

    // Release the object back to it's pool.
    le_mem_Release(fdMonitorPtr);
}
Example #2
0
//--------------------------------------------------------------------------------------------------
static void DeleteFdMonitor
(
    FdMonitor_t*            fdMonitorPtr        ///< [in] Pointer to the FD Monitor to be deleted.
)
//--------------------------------------------------------------------------------------------------
{
    int i;
    event_PerThreadRec_t*   perThreadRecPtr = thread_GetEventRecPtr();

    LE_ASSERT(perThreadRecPtr == fdMonitorPtr->threadRecPtr);

    // Remove the FD Monitor from the thread's FD Monitor List.
    le_dls_Remove(&perThreadRecPtr->fdMonitorList, &fdMonitorPtr->link);

    LOCK

    // Delete the Safe References used for the FD Monitor and any of its Handler objects.
    le_ref_DeleteRef(FdMonitorRefMap, fdMonitorPtr->safeRef);
    for (i = 0; i < LE_EVENT_NUM_FD_EVENT_TYPES; i++)
    {
        void* safeRef = fdMonitorPtr->handlerArray[i].safeRef;
        if (safeRef != NULL)
        {
            le_ref_DeleteRef(HandlerRefMap, safeRef);
        }
    }

    UNLOCK

    // Tell epoll(7) to stop monitoring this fd.
    StopMonitoringFd(fdMonitorPtr);

    // Release the object back to it's pool.
    le_mem_Release(fdMonitorPtr);
}
Example #3
0
//--------------------------------------------------------------------------------------------------
static void DispatchToHandler
(
    void* param1Ptr,    ///< FD Monitor safe reference.
    void* param2Ptr     ///< FD event type.
)
//--------------------------------------------------------------------------------------------------
{
    le_event_FdEventType_t eventType = (le_event_FdEventType_t)param2Ptr;
    event_PerThreadRec_t* perThreadRecPtr = thread_GetEventRecPtr();

    LOCK

    // Get a pointer to the FD Monitor object for this fd.
    FdMonitor_t* fdMonitorPtr = le_ref_Lookup(FdMonitorRefMap, param1Ptr);

    UNLOCK

    // If the FD Monitor object has been deleted, we can just ignore this.
    if (fdMonitorPtr != NULL)
    {
        LE_ASSERT(perThreadRecPtr == fdMonitorPtr->threadRecPtr);

        Handler_t* handlerPtr = &(fdMonitorPtr->handlerArray[eventType]);

        if (handlerPtr->handlerFunc != NULL)
        {
            // Set the thread's Context Pointer.
            event_SetCurrentContextPtr(handlerPtr->contextPtr);

            // Call the handler function.
            handlerPtr->handlerFunc(fdMonitorPtr->fd);
        }
        else
        {
            TRACE("Discarding event %s for FD Monitor %s (fd %d).",
                  GetFdEventTypeName(eventType),
                  fdMonitorPtr->name,
                  fdMonitorPtr->fd);

            // If this is a write hang-up, then we need to tell epoll to stop monitoring
            // this fd, because otherwise we could end up wasting power and spamming the
            // log with debug messages while we detect and discard this event over and over.
            if (eventType == LE_EVENT_FD_WRITE_HANG_UP)
            {
                StopMonitoringFd(fdMonitorPtr);
            }
        }
    }
    else
    {
        TRACE("Discarding event %s for non-existent FD Monitor.", GetFdEventTypeName(eventType));
    }
}