Exemple #1
0
void
parcBuffer_AssertValid(const PARCBuffer *buffer)
{
    char *explanation = _parcBuffer_CheckValidity(buffer);

    trapIllegalValueIf(explanation != NULL, "PARCBuffer@%p %s.", (void *) buffer, explanation);
}
ssize_t
ccnxCodecSchemaV1FixedHeaderEncoder_EncodeHeader(CCNxCodecTlvEncoder *fixedHeaderEncoder, const CCNxCodecSchemaV1FixedHeader *header)
{
    assertNotNull(fixedHeaderEncoder, "Parameter fixedHeaderEncoder must be non-null");
    assertNotNull(header, "Parameter header must be non-null");
    trapIllegalValueIf(header->version != 1, "Header wrong version, must be 1");

    CCNxCodecSchemaV1InterestHeader copy;

    memcpy(&copy, header, sizeof(CCNxCodecSchemaV1InterestHeader));

    copy.packetLength = htons(header->packetLength);

    switch (header->packetType) {
        case CCNxCodecSchemaV1Types_PacketType_Interest:
            copy.returnCode = 0;
            break;

        case CCNxCodecSchemaV1Types_PacketType_InterestReturn:
            // nothing to do, all fields used
            break;

        default:
            copy.hopLimit = 0;
            copy.returnCode = 0;
            copy.flags = 0;
            break;
    }

    ccnxCodecTlvEncoder_AppendRawArray(fixedHeaderEncoder, sizeof(CCNxCodecSchemaV1FixedHeader), (uint8_t *) &copy);
    return sizeof(CCNxCodecSchemaV1FixedHeader);
}
Exemple #3
0
void
parcStdlibMemory_Deallocate(void **pointer)
{
#ifndef PARCLibrary_DISABLE_VALIDATION
    trapIllegalValueIf(_parcStdlibMemory_OutstandingAllocations == 0,
                       "parcStdlibMemory_Deallocate invoked with nothing left to free (double free somewhere?)\n");
#endif
    free(*pointer);
    *pointer = NULL;

#ifdef PARCLibrary_DISABLE_ATOMICS
    parcAtomicInteger_Uint32Decrement(&_parcStdlibMemory_OutstandingAllocations);
#else
    __sync_sub_and_fetch(&_parcStdlibMemory_OutstandingAllocations, 1);
#endif
}
Exemple #4
0
void
internal_parc_initializeLibevent(void)
{
    if (_libeventInitialized) {
        return;
    }
    _libeventInitialized = 1;

    // 0x AA BB CC XX
    // AA = major
    // BB = minor
    // CC = patchlevel
    //
    uint32_t version = event_get_version_number();
    trapIllegalValueIf(version < 0x02001000UL,
                       "Libevent version must be at least 2.0.16, got %s",
                       event_get_version());

    // Make sure libevent uses our memory allocator.
    // Libevent allocates an internal object the first time a base is allocated
    // that it never releases.  In order to ensure our outstanding memory counters
    // start at zero we trigger this allocation before interposing our memory allocator.
    //
    // Create a scheduler event base, an event, then free both of them.
    //
    struct event_base *evbase = event_base_new();
    assertNotNull(evbase, "Libevent event_base_new returned NULL");
    struct event *event = event_new(evbase, -1, 0, NULL, NULL);
    assertNotNull(event, "Libevent event_new returned NULL");
    event_del(event);
    event_base_free(evbase);

    event_set_mem_functions(internal_parc_alloc,
                            internal_parc_realloc,
                            internal_parc_free);
}
Exemple #5
0
void
parcFile_AssertValid(const PARCFile *instance)
{
    trapIllegalValueIf(instance == NULL, "Parameter must be a non-null pointer to a valid PARCFile.");
    trapIllegalValueIf(instance->pathName == NULL, "PARCFile cannot have a NULL path-name");
}
void
ccnxInterestPayloadId_AssertValid(const CCNxInterestPayloadId *id)
{
    trapIllegalValueIf(ccnxInterestPayloadId_IsValid(id) == false, "CCNxName instance is not valid.");
}
void
rtaCommandCreateProtocolStack_AssertValid(const RtaCommandCreateProtocolStack *instance)
{
    const char *assessment = rtaCommandCreateProtocolStack_AssessValidity(instance);
    trapIllegalValueIf(assessment != NULL, "%s", assessment);
}