int main()

in src/tcp-proxy.cpp [806:877]


int main(int argc, char* argv[])
{
    SessionArray server;

    infoOutputFile = stdout;

    server.remoteHostName = "localhost";
    server.remotePort = 8022;
    server.localPort = 8200;
    server.nBytesToPreload = 0;

    for (int i = 1; i < argc; ++i) {
        const char *arg = argv[i];
        const char *parm = i + 1 < argc ? argv[i + 1] : "";
        if (is_arg(-h) || is_arg(--help) || is_arg(/?)) {
            printf("Usage: \n\t-a --host   \thostname\n\t-r --remoteport\tremoteport\n\t-l --localport \tlocalport\n\t-p --preload \tnum_bytes_to_preload\n" );
            exit(0);
        }
        else if (is_arg(--localport) || is_arg(-l)) {
            server.localPort = (uint16)strtol(parm, NULL, 10);
        }
        else if (is_arg(--remoteport) || is_arg(-r)) {
            server.remotePort = (uint16)strtol(parm, NULL, 10);
        }
        else if (is_arg(--host) || is_arg(-a)) {
            server.remoteHostName = parm;
        }
        else if (is_arg(--preload) | is_arg(-p)) {
            server.nBytesToPreload = strtoull(parm, NULL, 10);
        }
        else {
            continue; // If command not recognized, do not skip 1 extra field
        }
        ++i; // Skip parameter
    }

    iprintf("TCP proxy is listening at localhost:%d, redirecting to %s:%d, preload size: %llu\n",
        server.localPort, server.remoteHostName.c_str(), server.remotePort, (ulonglong)server.nBytesToPreload);

    if (!server.open()) {
        err("Unable to start TCP server");
        return -1;
    }

    iprintf("READY.\n");

    IterationResult ir;
    uint64 tIdleStarted = time_ns();
    while (ir = server.select_iteration(), !ITERATION_FINISHED(ir))
    {
        if (IR::IDLE == ir) {
            uint64 tIdle = time_ns();
            if (tIdleStarted > tIdle) tIdleStarted = tIdle;
            tIdle -= tIdleStarted;
            if (tIdle > 100000000) {
                size_t sz = server.size();
                if (sz > 1) {
                    printf("\r%llu sessions idle for %llums  \r", (ulonglong)sz - 1, (ulonglong)tIdle / 1000000);
                }
                else {
                    printf("\rIdle for %llums                  \r", (ulonglong)tIdle / 1000000);
                }
            }
        }
        else {
            tIdleStarted = UINT64_MAX;
        }
    }

    iprintf("FINISHED.\n");
    return 0;
}