示例#1
0
static void cleanup(void* vsm)
{
    struct SessionManager* sm = (struct SessionManager*) vsm;
    uint64_t nowSecs = Time_currentTimeSeconds(sm->eventBase);
    for (uint32_t i = 0; i < sm->ifaceMap.count; i++) {
        if (sm->ifaceMap.values[i].lastMessageTime < (nowSecs - SESSION_TIMEOUT_SECONDS)) {
            struct Allocator* ifAllocator = sm->ifaceMap.values[i].iface.allocator;
            ifAllocator->free(ifAllocator);
            Map_OfSessionsByIp6_remove(i, &sm->ifaceMap);
            i--;
        }
    }
}
示例#2
0
static void cleanup(void* vsm)
{
    struct SessionManager* sm = (struct SessionManager*) vsm;
    uint64_t cutoffTime =
        Time_currentTimeMilliseconds(sm->eventBase) - (SESSION_TIMEOUT_SECONDS * 1000);
    for (uint32_t i = 0; i < sm->ifaceMap.count; i++) {
        struct SessionManager_Session* sess = &sm->ifaceMap.values[i]->pub;

        // Received a message since cutoff time.
        if (sess->timeOfLastIn > cutoffTime) { continue; }

        // Received a message (ever) or session is not older than cutoff time.
        if (sess->timeOfLastIn || sess->timeOfCreation > cutoffTime) { continue; }

        struct Allocator* ifAllocator = sess->external.allocator;
        Map_OfSessionsByIp6_remove(i, &sm->ifaceMap);
        Allocator_free(ifAllocator);
        i--;
    }
}