SessionHandler::Result SessionHandler::processInput()

in src/dxapi/native/tickdb/session_handler.cpp [500:585]


SessionHandler::Result SessionHandler::processInput()
{
    auto ioStream = ioStream_;
    if (interrupted_ || NULL == ioStream) {
        return FINISHED;
    }

    try {
        byte buf[0x80];
        auto nRead = ioStream->tryRead(buf, sizeof(int32_t), SH_READ_TIMEOUT_US);

        if (0 != nRead) {
            assert(nRead <= sizeof(int32_t));
            if (nRead < sizeof(int32_t)) {
                ioStream->read(buf + nRead, sizeof(int32_t) - nRead, sizeof(int32_t) - nRead);
            }

            unsigned command = _loadBE<uint32_t>(buf);

            switch (command) {
#define CMD(X) case X: \
DBGLOG(LOGHDR ".processInput(" #X ")", ID); \
    return receive_##X();

            CMD(STREAM_PROPERTY_CHANGED)

            CMD(STREAM_DELETED)

            CMD(STREAM_CREATED)

            CMD(STREAM_RENAMED)

            CMD(STREAMS_DEFINITION)

            CMD(STREAM_PROPERTY)

            CMD(SESSION_CLOSED)

            CMD(STREAMS_CHANGED)

            default:
                format_string(&errorText_, "Unexpected token received from the server: %08X", command);
                DBGLOG(LOGHDR ".processResponse(..): unrecognized token: %08X", ID, command);
                cleanup();
                return FINISHED;
            }

            return OK;
        }

        return NO_DATA;
    }
#undef CMD

    catch (const IOStreamDisconnectException &) {
        DBGLOG(LOGHDR ".processInput(): WARNING: disconnected from the server side", ID);
        format_string(&errorText_, "disconnected by server");
        closeConnection();
        return FINISHED;
    }

    catch (const IOStreamException &e) {
        DBGLOG(LOGHDR ".processInput(): WARNING: Other socket exception", ID);
        format_string(&errorText_, "IOStream exception: %s", e.what());
        closeConnection();
        return FINISHED;
    }

    catch (const std::runtime_error &e) {
        DBGLOG(LOGHDR ".processInput(): ERR: Runtime error caught, ignored: %s", ID, e.what());
        //format_string(&errorText_, "std::exception: %s", e.what());
        return OK;
    }

    catch (const std::exception &e) {
        DBGLOG(LOGHDR ".processInput(): Exception: %s", ID, e.what());
        format_string(&errorText_, "std::exception: %s", e.what());
        return FINISHED;
    }

    catch (...) {
        DBGLOG(LOGHDR ".processInput(): Unknown exception", ID);
        format_string(&errorText_, "Unknown exception");
        return FINISHED;
    }
}