Ejemplo n.º 1
0
int
athenaTransportLinkAdapter_CloseByName(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *linkName)
{
    if (athenaTransportLinkAdapter->listenerList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->listenerList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->listenerList, index);
            if (strcmp(athenaTransportLink_GetName(athenaTransportLink), linkName) == 0) {
                athenaTransportLink_Close(athenaTransportLink);
                return 0;
            }
        }
    }
    if (athenaTransportLinkAdapter->instanceList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->instanceList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, index);
            if (athenaTransportLink) {
                if (strcmp(athenaTransportLink_GetName(athenaTransportLink), linkName) == 0) {
                    athenaTransportLink_Close(athenaTransportLink);
                    return 0;
                }
            }
        }
    }
    errno = ENOENT;
    return -1;
}
Ejemplo n.º 2
0
void
athenaTransportLinkAdapter_Destroy(AthenaTransportLinkAdapter **athenaTransportLinkAdapter)
{
    // release listener instances
    if ((*athenaTransportLinkAdapter)->listenerList) {
        for (int index = 0; index < parcArrayList_Size((*athenaTransportLinkAdapter)->listenerList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get((*athenaTransportLinkAdapter)->listenerList, index);
            athenaTransportLink_Close(athenaTransportLink);
        }
    }
    // release live instances
    if ((*athenaTransportLinkAdapter)->instanceList) {
        for (int index = 0; index < parcArrayList_Size((*athenaTransportLinkAdapter)->instanceList); index++) {
            AthenaTransportLink *athenaTransportLink = parcArrayList_Get((*athenaTransportLinkAdapter)->instanceList, index);
            if (athenaTransportLink) {
                athenaTransportLink_Close(athenaTransportLink);
            }
        }
    }
    parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->moduleList));
    parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->instanceList));
    parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->listenerList));
    if ((*athenaTransportLinkAdapter)->pollfdReceiveList) {
        parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdReceiveList));
        parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdSendList));
        parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdTransportLink));
    }
    parcLog_Release(&((*athenaTransportLinkAdapter)->log));
    parcMemory_Deallocate(athenaTransportLinkAdapter);
}
Ejemplo n.º 3
0
CCNxMetaMessage *
athenaTransportLink_Receive(AthenaTransportLink *athenaTransportLink)
{
    CCNxMetaMessage *ccnxMetaMessage = NULL;
    if (athenaTransportLink->receiveMethod) {
        if (athenaTransportLink_GetEvent(athenaTransportLink) & AthenaTransportLinkEvent_Closing) {
            athenaTransportLink->stats.messageFromLink_DroppedNoConnection++;
            errno = ENOTCONN;
            return NULL;
        }
        if (athenaTransportLink_GetEvent(athenaTransportLink) & AthenaTransportLinkEvent_Error) {
            athenaTransportLink_Close(athenaTransportLink);
            athenaTransportLink->stats.messageFromLink_DroppedNoConnection++;
            errno = ENOTCONN;
            return NULL;
        }
        // Turn off the Receive event flag since we're servicing it
        athenaTransportLink_ClearEvent(athenaTransportLink, AthenaTransportLinkEvent_Receive);
        ccnxMetaMessage = athenaTransportLink->receiveMethod(athenaTransportLink);
        if (ccnxMetaMessage == NULL) {
            athenaTransportLink->stats.messageFromLink_Empty++;
            errno = ENOMSG;
        } else {
            athenaTransportLink->stats.messageFromLink_Received++;
        }
    }
    return ccnxMetaMessage;
}
Ejemplo n.º 4
0
AthenaTransportLink *
athenaTransportLinkModule_Open(AthenaTransportLinkModule *athenaTransportLinkModule, PARCURI *connectionURI)
{
    AthenaTransportLink *athenaTransportLink = athenaTransportLinkModule->openMethod(athenaTransportLinkModule, connectionURI);
    if (athenaTransportLink) {
        athenaTransportLink_SetAddLinkCallback(athenaTransportLink,
                                               (AthenaTransportLink_AddLinkCallback *) _athenaTransportLinkModule_AddLink,
                                               athenaTransportLinkModule);

        int result = _athenaTransportLinkModule_AddLink(athenaTransportLinkModule, athenaTransportLink);
        if (result == -1) {
            int addLinkError = errno;
            parcLog_Error(athenaTransportLinkModule_GetLogger(athenaTransportLinkModule),
                          "Adding link %s failed: %s", athenaTransportLink_GetName(athenaTransportLink), strerror(errno));
            athenaTransportLink_Close(athenaTransportLink);
            errno = addLinkError;
            return NULL;
        }

        athenaTransportLink_SetRemoveLinkCallback(athenaTransportLink,
                                                  (AthenaTransportLink_RemoveLinkCallback *) _athenaTransportLinkModule_RemoveLink,
                                                  athenaTransportLinkModule);
    }
    return athenaTransportLink;
}
Ejemplo n.º 5
0
void
athenaTransportLinkModule_Destroy(AthenaTransportLinkModule **athenaTransportLinkModule)
{
    int index = (int) parcArrayList_Size((*athenaTransportLinkModule)->instanceList);
    while (index-- > 0) {
        AthenaTransportLink *transportLink;
        transportLink = parcArrayList_Get((*athenaTransportLinkModule)->instanceList, 0);
        athenaTransportLink_Close(transportLink);
    }
    parcArrayList_Destroy(&((*athenaTransportLinkModule)->instanceList));
    parcMemory_Deallocate(&((*athenaTransportLinkModule)->name));
    parcLog_Release(&((*athenaTransportLinkModule)->log));
    parcMemory_Deallocate(athenaTransportLinkModule);
}
Ejemplo n.º 6
0
PARCBitVector *
athenaTransportLinkAdapter_Close(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, PARCBitVector *linkVector)
{
    PARCBitVector *resultVector = parcBitVector_Create();
    int nextLinkToClose = 0;
    while ((nextLinkToClose = parcBitVector_NextBitSet(linkVector, nextLinkToClose)) >= 0) {
        AthenaTransportLink *athenaTransportLink = parcArrayList_Get(athenaTransportLinkAdapter->instanceList, nextLinkToClose);
        if (athenaTransportLink) {
            athenaTransportLink_Close(athenaTransportLink);
            parcBitVector_Set(resultVector, nextLinkToClose);
            nextLinkToClose++;
        }
    }
    return resultVector;
}
Ejemplo n.º 7
0
int
athenaTransportLinkAdapter_Poll(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, int timeout)
{
    struct pollfd *pollfdReceiveList = athenaTransportLinkAdapter->pollfdReceiveList;
    struct pollfd *pollfdSendList = athenaTransportLinkAdapter->pollfdSendList;
    int pollfdListSize = athenaTransportLinkAdapter->pollfdListSize;
    AthenaTransportLinkModule *athenaTransportLinkModule;
    int events = 0;

    // Allow instances which have not registered an eventfd to mark their events
    if (athenaTransportLinkAdapter->moduleList) {
        for (int index = 0; index < parcArrayList_Size(athenaTransportLinkAdapter->moduleList); index++) {
            athenaTransportLinkModule = parcArrayList_Get(athenaTransportLinkAdapter->moduleList, index);
            events += athenaTransportLinkModule_Poll(athenaTransportLinkModule, timeout);
        }
    }

    if (events) { // if we have existing events, poll doesn't need to block
        timeout = 0;
    }

    int result = poll(pollfdReceiveList, pollfdListSize, timeout);
    if (result < 0) {
        parcLog_Error(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter),
                      "Receive list poll error: (%d) %s", errno, strerror(errno));
    } else {
        for (int index = 0; index < pollfdListSize; index++) {
            if (pollfdReceiveList[index].revents) {
                AthenaTransportLink *athenaTransportLink = athenaTransportLinkAdapter->pollfdTransportLink[index];
                if (athenaTransportLink) {
                    if (pollfdReceiveList[index].revents & (POLLERR | POLLHUP)) {
                        athenaTransportLink_SetEvent(athenaTransportLink, AthenaTransportLinkEvent_Error);
                        athenaTransportLink_Close(athenaTransportLink);
                    }
                    if (pollfdReceiveList[index].revents & POLLIN) {
                        athenaTransportLink_SetEvent(athenaTransportLink, AthenaTransportLinkEvent_Receive);
                    } else {
                        athenaTransportLink_ClearEvent(athenaTransportLink, AthenaTransportLinkEvent_Receive);
                    }
                }
            }
        }
    }

    result = poll(pollfdSendList, pollfdListSize, 0);
    if (result < 0) {
        parcLog_Error(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter),
                      "Send list poll error: (%d) %s", errno, strerror(errno));
    } else {
        for (int index = 0; index < pollfdListSize; index++) {
            if (pollfdSendList[index].revents) {
                AthenaTransportLink *athenaTransportLink = athenaTransportLinkAdapter->pollfdTransportLink[index];
                if (athenaTransportLink) {
                    if (pollfdSendList[index].revents & (POLLNVAL | POLLHUP | POLLERR)) {
                        continue;
                    }
                    if (pollfdSendList[index].revents & (POLLERR | POLLHUP)) {
                        athenaTransportLink_SetEvent(athenaTransportLink, AthenaTransportLinkEvent_Error);
                        athenaTransportLink_Close(athenaTransportLink);
                    }
                    if (pollfdSendList[index].revents & POLLOUT) {
                        athenaTransportLink_SetEvent(athenaTransportLink, AthenaTransportLinkEvent_Send);
                    } else {
                        athenaTransportLink_ClearEvent(athenaTransportLink, AthenaTransportLinkEvent_Send);
                    }
                }
            }
        }
        //events += result; // don't register send events
    }
    return events;
}
Ejemplo n.º 8
0
static void
_closeConnection(void **link)
{
    AthenaTransportLink *athenaTransportLink = (AthenaTransportLink *) *link;
    athenaTransportLink_Close(athenaTransportLink);
}