Ejemplo 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);
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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;
}