Beispiel #1
0
void
sxe_sync_ev_init(unsigned concurrency, void (*send_event)(void * sync, void * user_data))
{
    unsigned short port;

    SXEE82("sxe_sync_ev_init(concurrency=%u,send_event=%p)", concurrency, send_event);
    sxe_sync_ev_pool                 = sxe_pool_new("http_sync_ev", concurrency, sizeof(SXE_SYNC_EV), 2);
    sxe_sync_ev_sock                 = sxe_sync_ev_socket();
    sxe_sync_generic_event           = send_event;
    sxe_sync_ev_addr.sin_family      = AF_INET;
    sxe_sync_ev_addr.sin_addr.s_addr = inet_addr("127.0.0.1");

    for (port = 1025; ; port++) {
        sxe_sync_ev_addr.sin_port = htons(port);

        if (bind(sxe_sync_ev_sock, (struct sockaddr *)&sxe_sync_ev_addr, sizeof(sxe_sync_ev_addr)) >= 0) {
            break;
        }

        SXEA12(port < USHRT_MAX, "Not able to bind any port between 1024 and %hu: %s", port,   /* Coverage Exclusion - Assert      */
               sxe_socket_get_last_error_as_str());
    }                                                                                          /* Coverage Exclusion - Not Reached */

    SXEL81("Listening on port %hu", port);
    ev_io_init(&sxe_sync_ev_io, sxe_sync_ev_read, _open_osfhandle(sxe_sync_ev_sock, 0), EV_READ);
    ev_io_start(ev_default_loop(0), &sxe_sync_ev_io);
    SXER80("return");
}
Beispiel #2
0
static void
test_pool_3_timeout(void * array, unsigned array_index, void * caller_info)
{
    SXEE82("test_pool_3_timeout(array=%p,array_index=%u)", array, array_index);
    SXE_UNUSED_PARAMETER(caller_info);
    sxe_pool_set_indexed_element_state(array, array_index, 0, 1);
    sxe_pool_set_indexed_element_state(array, array_index, 1, 0);
    SXER80("return");
}
Beispiel #3
0
SXE_RETURN
sha1_from_hex(SOPHOS_SHA1 * sha1, const char * sha1_in_hex)
{
    SXE_RETURN result;

    SXEE82("sxe_sha1_from_hex(sha1=%p,sha1_in_hex='%s'", sha1, sha1_in_hex);
    result = sxe_hex_to_bytes((unsigned char *)sha1, sha1_in_hex, SHA1_IN_HEX_LENGTH);
    SXER81("return %s", sxe_return_to_string(result));
    return result;
}
Beispiel #4
0
SXE_RETURN
md5_from_hex(SOPHOS_MD5 * md5, const char * md5_in_hex)
{
    SXE_RETURN result;

    SXEE82("(md5=%p,md5_in_hex='%s'", md5, md5_in_hex);
    result = sxe_hex_to_bytes((unsigned char *)md5, md5_in_hex, MD5_IN_HEX_LENGTH);
    SXER81("return %s", sxe_return_to_string(result));
    return result;
}
Beispiel #5
0
void
sxe_ring_buffer_add(void * base, const char * buf, unsigned len)
{
    unsigned available_space;

    SXEE82("sxe_ring_buffer_add(buf=%p,len=%u)", buf, len);
    SXEL92("Current: %p, Itteration: %u", SXE_RING_BUFFER_CURRENT, SXE_RING_BUFFER_ITERATION);

    SXEA10(len <= SXE_RING_BUFFER_SIZE, "The item we're will fit in the whole array");

    available_space = (SXE_RING_BUFFER_END - SXE_RING_BUFFER_CURRENT + 1);
    SXEL91("There is %u space between the current pointer and the end of the array", available_space);

    if (available_space >= len) { // Can we fit it on the end of the array?
        SXEL92("Adding %u bytes at %p", len, SXE_RING_BUFFER_CURRENT);
        memcpy(SXE_RING_BUFFER_CURRENT, buf, len);

        SXE_RING_BUFFER_CURRENT = SXE_RING_BUFFER_CURRENT + len;
        if (SXE_RING_BUFFER_CURRENT == (SXE_RING_BUFFER_END + 1)) {
            SXEL90("Wrote to the last byte in the array, wrapping pointer");
            SXE_RING_BUFFER_ITERATION++;
            SXE_RING_BUFFER_CURRENT = SXE_RING_BUFFER_ARRAY_BASE;
            SXE_RING_BUFFER_WRITEN_END = SXE_RING_BUFFER_END;
        }
        else {
            if (SXE_RING_BUFFER_WRITEN_END < SXE_RING_BUFFER_CURRENT) {
                SXE_RING_BUFFER_WRITEN_END = SXE_RING_BUFFER_CURRENT - 1;
            }
        }
    }
    else { // else we have to wrap around the ring
        memcpy(SXE_RING_BUFFER_CURRENT, buf, available_space);
        SXE_RING_BUFFER_WRITEN_END = SXE_RING_BUFFER_END;
        SXE_RING_BUFFER_ITERATION++;
        SXE_RING_BUFFER_CURRENT = SXE_RING_BUFFER_ARRAY_BASE;
        memcpy(SXE_RING_BUFFER_CURRENT, buf + available_space, (len - available_space));
        SXE_RING_BUFFER_CURRENT = SXE_RING_BUFFER_CURRENT + (len - available_space);
    }

    SXEL93("Current: %p, Writen End %p, Itteration: %u", SXE_RING_BUFFER_CURRENT, SXE_RING_BUFFER_WRITEN_END, SXE_RING_BUFFER_ITERATION);
    SXER80("return");
}
Beispiel #6
0
static void
sxe_sync_ev_read(EV_P_ ev_io * io, int revents)
{
    SXE_SYNC_EV   * handle;

    SXEE82("sxe_sync_ev_read(io=%p,revents=%d)", io, revents);
#if EV_MULTIPLICITY
    SXE_UNUSED_ARGUMENT(loop);
#endif
    SXE_UNUSED_ARGUMENT(io);
    SXE_UNUSED_ARGUMENT(revents);

    while(recvfrom(sxe_sync_ev_sock, &handle, sizeof(handle), 0, NULL, NULL) == sizeof(handle)) {
        (*sxe_sync_generic_event)(handle, handle->user_data);
    }

    SXEA11(sxe_socket_get_last_error() == SXE_SOCKET_ERROR(EWOULDBLOCK), "Unexpected error receiving from sync socket: %s",
           sxe_socket_get_last_error_as_str());
    SXER80("return");
}
Beispiel #7
0
static void
test_pool_2_timeout(void * array, unsigned array_index, void * caller_info)
{
    SXEE82("test_pool_2_timeout(array=%p,array_index=%u)", array, array_index);
    SXE_UNUSED_PARAMETER(caller_info);
    test_pool_2_timeout_call_count ++;

    if (1 == test_pool_2_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_USED,   TEST_STATE_FREE);
    }

    if (2 == test_pool_2_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_ABUSED, TEST_STATE_USED);
    }

    if (3 == test_pool_2_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_USED,   TEST_STATE_FREE);
    }

    SXER80("return");
}