Esempio n. 1
0
static void
_metisCliSession_ReadCallback(PARCEventQueue *event, PARCEventType type, void *cliSessionVoid)
{
    assertTrue(type == PARCEventType_Read, "Illegal type: expected read event, got %d\n", type);
    _MetisCommandLineInterface_Session *session = (_MetisCommandLineInterface_Session *) cliSessionVoid;
    PARCEventBuffer *input = parcEventBuffer_GetQueueBufferInput(event);

    while (parcEventBuffer_GetLength(input) > 0) {
        size_t readLength = 0;
        char *cmdline = parcEventBuffer_ReadLine(input, &readLength);
        if (cmdline == NULL) {
            // we have run out of input, we're done
            parcEventBuffer_Destroy(&input);
            return;
        }

        // we have a whole command line
        bool success = _metisCliSession_ProcessCommand(session, cmdline);
        parcEventBuffer_FreeLine(input, &cmdline);

        if (!success) {
            // the session is dead
            parcEventBuffer_Destroy(&input);
            return;
        }

        _metisCliSession_DisplayPrompt(session);
    }
    parcEventBuffer_Destroy(&input);
}
Esempio n. 2
0
int
rtaComponent_PutMessage(PARCEventQueue *queue, TransportMessage *tm)
{
    RtaConnection *conn = rtaConnection_GetFromTransport(tm);
    assertNotNull(conn, "Got null connection from transport message\n");

    if (rtaConnection_GetState(conn) != CONN_CLOSED) {
        PARCEventBuffer *out = parcEventBuffer_GetQueueBufferOutput(queue);
        int res;

        rtaConnection_IncrementMessagesInQueue(conn);

        if (DEBUG_OUTPUT) {
            printf("%s  queue %-12s tm %p\n",
                   __func__,
                   rtaProtocolStack_GetQueueName(rtaConnection_GetStack(conn), queue),
                   (void *) tm);
        }

        res = parcEventBuffer_Append(out, (void *)&tm, sizeof(&tm));
        assertTrue(res == 0, "%s parcEventBuffer_Append returned error\n", __func__);
        parcEventBuffer_Destroy(&out);
        return 1;
    } else {
        // should increment a drop counter (case 908)
        transportMessage_Destroy(&tm);

        return 0;
    }
}
Esempio n. 3
0
/**
 * @function conn_readcb
 * @abstract Event callback for reads
 * @discussion
 *   Will read messages off the input.  Continues reading as long as we
 *   can get a header to determine the next message length or as long as we
 *   can read a complete message.
 *
 *   This function manipulates the read low water mark.  (1) read a fixed header plus complete message,
 *   then set the low water mark to FIXED_HEADER_LEN.  (2) read a fixed header, but not a complete
 *   message, then set low water mark to the total mesage length.  Using the low water mark like this
 *   means the buffer event will only trigger on meaningful byte boundaries when we can get actual
 *   work done.
 *
 * @param <#param1#>
 * @return <#return#>
 */
static void
_conn_readcb(PARCEventQueue *event, PARCEventType type, void *ioOpsVoid)
{
    MetisIoOperations *ops = (MetisIoOperations *) ioOpsVoid;
    _MetisStreamState *stream = (_MetisStreamState *) metisIoOperations_GetClosure(ops);

    PARCEventBuffer *input = parcEventBuffer_GetQueueBufferInput(event);

    // drain the input buffer
    while (parcEventBuffer_GetLength(input) >= metisTlv_FixedHeaderLength() && parcEventBuffer_GetLength(input) >= stream->nextMessageLength) {
        // this may set the stream->nextMessageLength
        MetisMessage *message = _single_read(input, stream);

        if (message) {
            metisForwarder_Receive(stream->metis, message);
        }
    }

    if (stream->nextMessageLength == 0) {
        // we don't have the next header, so set it to the header length
        metisStreamBuffer_SetWatermark(event, true, false, metisTlv_FixedHeaderLength(), 0);
    } else {
        // set it to the packet length
        metisStreamBuffer_SetWatermark(event, true, false, stream->nextMessageLength, 0);
    }
    parcEventBuffer_Destroy(&input);
}
Esempio n. 4
0
LONGBOW_TEST_CASE(Global, metisMessage_ReadFromBuffer)
{
    char message_str[] = "\x00Once upon a time, in a stack far away, a dangling pointer found its way to the top of the heap.";

    PARCEventBuffer *buff = parcEventBuffer_Create();
    parcEventBuffer_Append(buff, message_str, sizeof(message_str));

    PARCLogReporter *reporter = parcLogReporterTextStdout_Create();
    MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock());
    parcLogReporter_Release(&reporter);
    MetisMessage *message = metisMessage_ReadFromBuffer(1, 2, buff, sizeof(message_str), logger);
    metisLogger_Release(&logger);

    assertNotNull(message, "Got null from metisMessage_CreateFromBuffer");

    assertTrue(parcEventBuffer_GetLength(message->messageBytes) == sizeof(message_str),
               "Length of internal buffer wrong, expected %zu got %zu",
               sizeof(message_str),
               parcEventBuffer_GetLength(message->messageBytes));

    uint8_t *p = parcEventBuffer_Pullup(message->messageBytes, sizeof(message_str));
    assertTrue(memcmp(p, message_str, sizeof(message_str)) == 0, "Internal buffer contents does not match test");
    assertTrue(message->ingressConnectionId == 1, "IngressConnectionId wrong, expected %d got %u", 1, message->ingressConnectionId);
    assertTrue(message->receiveTime == 2, "receiveTime wrong, expected %u got %" PRIu64, 2, message->receiveTime);
    assertTrue(parcEventBuffer_GetLength(buff) == 0, "Origin buffer not drained, expected 0, got %zu", parcEventBuffer_GetLength(buff));

    metisMessage_Release(&message);
    parcEventBuffer_Destroy(&buff);
}
Esempio n. 5
0
TransportMessage *
rtaComponent_GetMessage(PARCEventQueue *queue)
{
    PARCEventBuffer *in = parcEventBuffer_GetQueueBufferInput(queue);

    while (parcEventBuffer_GetLength(in) >= sizeof(TransportMessage *)) {
        ssize_t len;
        TransportMessage *tm;
        RtaConnection *conn;

        len = parcEventBuffer_Read(in, (void *)&tm, sizeof(&tm));

        assertTrue(len == sizeof(TransportMessage *),
                   "parcEventBuffer_Read returned error");

        // Is the transport message for an open connection?
        conn = rtaConnection_GetFromTransport(tm);
        assertNotNull(conn, "%s GetInfo returnd null connection\n", __func__);

        if (DEBUG_OUTPUT) {
            printf("%s queue %-12s tm %p\n",
                   __func__,
                   rtaProtocolStack_GetQueueName(rtaConnection_GetStack(conn), queue),
                   (void *) tm);
        }

        (void) rtaConnection_DecrementMessagesInQueue(conn);

        if (rtaConnection_GetState(conn) != CONN_CLOSED) {
            parcEventBuffer_Destroy(&in);
            return tm;
        }

        // it's a closed connection

        if (DEBUG_OUTPUT) {
            printf("%s clearing connection %p reference in transport\n",
                   __func__, (void *) conn);
        }

        // should increment a drop counter (case 908)
        transportMessage_Destroy(&tm);
    }

    parcEventBuffer_Destroy(&in);
    return NULL;
}
Esempio n. 6
0
void
metisHopByHopFragmenter_Release(MetisHopByHopFragmenter **fragmenterPtr)
{
    MetisHopByHopFragmenter *fragmenter = *fragmenterPtr;
    parcEventBuffer_Destroy(&fragmenter->currentReceiveBuffer);
    parcRingBuffer1x1_Release(&fragmenter->sendQueue);
    parcRingBuffer1x1_Release(&fragmenter->receiveQueue);
    metisLogger_Release(&fragmenter->logger);
    parcMemory_Deallocate((void **) fragmenterPtr);
}
Esempio n. 7
0
/**
 * @function metisStreamConnection_Send
 * @abstract Non-destructive send of the message.
 * @discussion
 *   Send uses metisMessage_CopyToStreamBuffer, which is a non-destructive write.
 *   The send may fail if there's no buffer space in the output queue.
 *
 * @param dummy is ignored.  A stream has only one peer.
 * @return <#return#>
 */
static bool
_metisStreamConnection_Send(MetisIoOperations *ops, const CPIAddress *dummy, MetisMessage *message)
{
    assertNotNull(ops, "Parameter ops must be non-null");
    assertNotNull(message, "Parameter message must be non-null");
    _MetisStreamState *stream = (_MetisStreamState *) metisIoOperations_GetClosure(ops);

    bool success = false;
    if (stream->isUp) {
        PARCEventBuffer *buffer = parcEventBuffer_GetQueueBufferOutput(stream->bufferEventVector);
        size_t buffer_backlog = parcEventBuffer_GetLength(buffer);
        parcEventBuffer_Destroy(&buffer);

        if (buffer_backlog < OUTPUT_QUEUE_BYTES) {
            if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug)) {
                metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug, __func__,
                                "connid %u Writing %zu bytes to buffer with backlog %zu bytes",
                                stream->id,
                                metisMessage_Length(message),
                                buffer_backlog);
            }

            int failure = metisMessage_Write(stream->bufferEventVector, message);
            if (failure == 0) {
                success = true;
            }
        } else {
            if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Warning)) {
                metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Warning, __func__,
                                "connid %u Writing to buffer backlog %zu bytes DROP MESSAGE",
                                stream->id,
                                buffer_backlog);
            }
        }
    } else {
        if (metisLogger_IsLoggable(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Error)) {
            metisLogger_Log(stream->logger, MetisLoggerFacility_IO, PARCLogLevel_Error, __func__,
                            "connid %u tried to send to down connection (isUp %d isClosed %d)",
                            stream->id,
                            stream->isUp,
                            stream->isClosed);
        }
    }

    return success;
}
Esempio n. 8
0
LONGBOW_TEST_CASE(Global, metisMessage_Append)
{
    char message_str[] = "\x00Once upon a time ...";

    PARCEventBuffer *buffer = parcEventBuffer_Create();
    PARCEventBuffer *buff = parcEventBuffer_Create();
    parcEventBuffer_Append(buff, message_str, sizeof(message_str));

    PARCLogReporter *reporter = parcLogReporterTextStdout_Create();
    MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock());
    parcLogReporter_Release(&reporter);
    MetisMessage *message = metisMessage_CreateFromBuffer(1, 2, buff, logger);
    int result = metisMessage_Append(buffer, message);

    assertTrue(result == 0, "Got error from metisMessage_Append");
    metisLogger_Release(&logger);
    metisMessage_Release(&message);
    parcEventBuffer_Destroy(&buffer);
}
Esempio n. 9
0
static void
_metisGenericEther_Destroy(MetisGenericEther **etherPtr)
{
    MetisGenericEther *ether = *etherPtr;

    if (metisLogger_IsLoggable(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug)) {
        metisLogger_Log(ether->logger, MetisLoggerFacility_IO, PARCLogLevel_Debug, __func__,
                        "GenericEther %p destroyed", (void *) ether);
    }

    if (ether->etherSocket > 0) {
        close(ether->etherSocket);
    }

    if (ether->macAddress) {
        parcBuffer_Release(&ether->macAddress);
    }

    metisLogger_Release(&ether->logger);
    parcEventBuffer_Destroy(&ether->workBuffer);
}