Пример #1
0
void *moloch_http_create_server(char *hostnames, int defaultPort, int maxConns, int maxOutstandingRequests, int compress)
{
    MolochHttp_t *server = MOLOCH_TYPE_ALLOC0(MolochHttp_t);

    DLL_INIT(r_, &server->requestQ[0]);
    DLL_INIT(r_, &server->requestQ[1]);
    DLL_INIT(e_, &server->connQ);

    server->names = g_strsplit(hostnames, ",", 0);
    uint32_t i;
    for (i = 0; server->names[i]; i++) {
        if (strncmp(server->names[i], "http://", 7) == 0) {
            char *tmp = g_strdup(server->names[i] + 7);
            g_free(server->names[i]);
            server->names[i] = tmp;
        } else if (strncmp(server->names[i], "https://", 8) == 0) {
            LOG("https not supported yet %s", server->names[i]);
            exit(0);
        }
    }
    server->namesCnt = i;
    server->port = defaultPort;
    server->maxConns = maxConns;
    server->maxOutstandingRequests = maxOutstandingRequests;
    server->compress = compress;

    server->syncConn = moloch_http_create(server, TRUE);
    for (i = 0; i < server->maxConns; i++) {
        MolochConn_t *conn = moloch_http_create(server, FALSE);
        DLL_PUSH_TAIL(e_, &server->connQ, conn);
    }

    return server;
}
Пример #2
0
void moloch_http_do_requests(MolochHttp_t *server)
{
    // Something waiting
    while (DLL_COUNT(r_, &server->requestQ)) {

        // No free connections
        if (DLL_COUNT(e_, &server->connQ) == 0) {

            // Not at our max, create one a second
            if (server->numConns < server->maxConns && time(0) - server->lastFailedConnect > 0) {
                moloch_http_create(server, FALSE);
            }
            return;
        }

        // Have a free conn and a request
        MolochConn_t *conn;
        DLL_POP_HEAD(e_, &server->connQ, conn);
        DLL_POP_HEAD(r_, &server->requestQ, conn->request);
        server->inProgress++;
        if (!moloch_http_process_send(conn, FALSE)) {
            server->inProgress--;
            LOG("ERROR - %p: Couldn't send %.*s", (void*)conn, conn->request->key_len, conn->request->key);
            DLL_PUSH_HEAD(r_, &server->requestQ, conn->request);

            moloch_http_free_conn(conn, FALSE);
        }
    }
}
Пример #3
0
void *moloch_http_create_server(char *hostname, int defaultPort, int maxConns, int maxOutstandingRequests, int compress)
{
    MolochHttp_t *server = MOLOCH_TYPE_ALLOC0(MolochHttp_t);

    DLL_INIT(r_, &server->requestQ[0]);
    DLL_INIT(r_, &server->requestQ[1]);
    DLL_INIT(e_, &server->connQ);
    server->name = strdup(hostname);
    server->port = defaultPort;
    server->maxConns = maxConns;
    server->maxOutstandingRequests = maxOutstandingRequests;
    server->compress = compress;

    server->syncConn = moloch_http_create(server);
    uint32_t i;
    for (i = 0; i < server->maxConns; i++) {
        MolochConn_t *conn = moloch_http_create(server);
        DLL_PUSH_TAIL(e_, &server->connQ, conn);
    }

    return server;
}
Пример #4
0
unsigned char *moloch_http_send_sync(void *serverV, char *method, char *key, uint32_t key_len, char *data, uint32_t data_len, char *headers, size_t *return_len)
{
    MolochRequest_t     *request;
    gboolean             sent = FALSE;
    MolochHttp_t        *server = serverV;

    request = MOLOCH_TYPE_ALLOC(MolochRequest_t);
    request->key_len  = MIN(key_len, sizeof(request->key)-1);
    memcpy(request->key, key, request->key_len);
    request->key[request->key_len] = 0;
    strncpy(request->method, method, sizeof(request->method));
    request->method[sizeof(request->method)-1] = 0;
    request->data_len = data_len;
    request->data     = data;
    request->func     = 0;
    request->uw       = 0;
    request->compress = 0;
    if (headers)
        strcpy(request->headers, headers);
    else
        request->headers[0] = 0;

    if (return_len)
        *return_len = 0;

    if (!server->syncConn)
        server->syncConn = moloch_http_create(server, TRUE);

    server->syncConn->request = request;
    sent = moloch_http_process_send(server->syncConn, TRUE);

    if (sent)  {
        if (return_len)
            *return_len = server->syncConn->hp_len;
        return (unsigned char*)server->syncConn->hp_data;
    }

    return 0;
}