예제 #1
0
/**
 * Default hash key function; returns the first word of the key; useful when key is a SHA1
 *
 * @param key  = Key to hash
 * @param size = Size of key to hash
 *
 * @return Checksum (i.e. hash value) of key
 */
static unsigned
sxe_prehashed_key_hash(const void * key, unsigned size)
{
    SXEE6("sxe_prehashed_key_hash(key=%.*s, size=%u)", size, key, size);
    SXE_UNUSED_PARAMETER(size);
    SXER6("return sum=%u", *(const unsigned *)key);
    return *(const unsigned *)key;
}
예제 #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");
}
예제 #3
0
static void
h_respond(struct SXE_HTTPD_REQUEST *request)
{
    SXE * this = sxe_httpd_request_get_sxe(request);
    SXE_UNUSED_PARAMETER(this);
    SXEE61I("%s()", __func__);
    tap_ev_queue_push(q_httpd, __func__, 1, "request", request);
    SXER60I("return");
}
예제 #4
0
static void
test_dirwatch_event(EV_P_ const char *chfile, int chflags, void * user_data)
{
    SXE_UNUSED_PARAMETER(loop);
    SXEE6("test_dirwatch_event(chfile=%s, chflags=%08x, user_data=%p)", chfile, chflags, user_data);
    tap_ev_push(__func__, 3,
                "chfile", tap_dup(chfile, strlen(chfile)),
                "chflags", chflags,
                "user_data", user_data);
    SXER6("return");
}
예제 #5
0
static void
h_body(struct SXE_HTTPD_REQUEST *request, const char *buf, unsigned used)
{
    SXE * this = sxe_httpd_request_get_sxe(request);
    SXE_UNUSED_PARAMETER(this);
    SXEE63I("%s(buf=%p,used=%u)", __func__, buf, used);
    tap_ev_queue_push(q_httpd, __func__, 4,
                      "request", request,
                      "buf", tap_dup(buf, used),
                      "used", used);
    SXER60I("return");
}
예제 #6
0
static void
h_header(struct SXE_HTTPD_REQUEST *request, const char *key, unsigned klen, const char *val, unsigned vlen)
{
    SXE * this = sxe_httpd_request_get_sxe(request);
    SXE_UNUSED_PARAMETER(this);
    SXEE65I("%s(key=[%.*s],value=[%.*s])", __func__, klen, key, vlen, val);
    tap_ev_queue_push(q_httpd, __func__, 3,
                      "request", request,
                      "key", tap_dup(key, klen),
                      "value", tap_dup(val, vlen));
    SXER60I("return");
}
예제 #7
0
static void
h_request(struct SXE_HTTPD_REQUEST *request, const char *method, unsigned mlen, const char *url, unsigned ulen, const char *version, unsigned vlen)
{
    SXE * this = sxe_httpd_request_get_sxe(request);
    SXE_UNUSED_PARAMETER(this);
    SXEE67I("%s(method=[%.*s],url=[%.*s],version=[%.*s])", __func__, mlen, method, ulen, url, vlen, version);
    tap_ev_queue_push(q_httpd, __func__, 4,
                      "request", request,
                      "url", tap_dup(url, ulen),
                      "method", tap_dup(method, mlen),
                      "version", tap_dup(version, vlen));
    SXER60I("return");
}
예제 #8
0
int
main(int argc, char ** argv)
{
    char buf[1024];
    char cmd[1024];
    char expect[1024];
    int  return_val;
    char cmd_quote;

    SXE_UNUSED_PARAMETER(argc);

    plan_tests(10);
    is(sxe_spawn_init(), SXE_RETURN_OK, "Initialized: sxe-spawn");

    /* Test a basic command */
    return_val = sxe_spawn_backticks("ls", buf, sizeof(buf));
    ok(return_val > 0, "Ran a basic backtick command");

#ifdef WIN32
    cmd_quote = '\"';
#else
    cmd_quote = '\'';
#endif

    /* Try a complex command */
    snprintf(cmd, sizeof(cmd), "perl -e %c print qq{foo\nbar\nbaz} %c | grep bar", cmd_quote, cmd_quote);
    is(sxe_spawn_backticks(cmd, buf, sizeof(buf)), 4, "Ran a perl command");
    is_eq("bar\n", buf, "The strings match");

    /* Do an 'ls' of this file */
    snprintf(cmd,    sizeof(cmd),    "ls %s", argv[0]);
    snprintf(expect, sizeof(expect), "%s\n", argv[0]);
    is(sxe_spawn_backticks(cmd, buf, sizeof(buf)), strlen(expect), "Ran an ls of this file");
    diag("Ran: >%s<\nGot: >%s<\nExpect: >%s<\n", cmd, buf, argv[0]);
    is_eq(expect, buf, "Strings are the same");

    buf[0] = 'X'; buf[1] = 'X'; buf[2] = 'X';

    /* Note: sxe_spawn_backticks asserts if buffer is less than 2 */

    /* buffer is 2 */
    is(sxe_spawn_backticks(cmd, buf, 2), 1, "Ran a basic backtick command");
    is(buf[0], expect[0], "length of 2 buffer[0]");
    is(buf[1], '\0',      "length of 2 buffer[1]");
    is(buf[2], 'X',       "length of 2 buffer[2]");

    return exit_status();
}
예제 #9
0
파일: sxe-dirwatch.c 프로젝트: davidu/sxe
static void
sxe_dirwatch_event(EV_P_ ev_io * io, int revents)
{
    char                   buffer[8192];
    int                    length;
    unsigned               offset;
    struct inotify_event * event;

    SXE_UNUSED_PARAMETER(revents);
    SXEE62("(fd=%d, revents=%08x)", io->fd, revents);
    SXEA11((length = read(io->fd, buffer, sizeof(buffer))) >= 0, "sxe_dirwatch_event: Failed to read events from inotify: %s",
            strerror(errno));

    for (offset = 0; offset < (unsigned)length;)
    {
        SXE_LIST_WALKER walker;
        SXE_DIRWATCH  * dirwatch;
        int             flags = 0;

        SXEA12(length - offset >= sizeof(struct inotify_event),
               "Odd sized chunk left in buffer %u (expected inotify event of %u bytes)",
               length - offset, sizeof(struct inotify_event));
        event = (struct inotify_event *)&buffer[offset];
        offset += sizeof(struct inotify_event);
        SXEA12(length - offset >= event->len, "Chunk left in buffer %u (expected length %u)", length - offset, event->len);
        offset += event->len;
        SXEL63("dirwatch_event: fd=%d flags=%08x file=%s", event->wd, event->mask, event->name);
        sxe_list_walker_construct(&walker, &sxe_dirwatch_list);

        while ((dirwatch = (SXE_DIRWATCH *)sxe_list_walker_step(&walker)) != NULL) {
            if (dirwatch->fd == event->wd) {
                break;
            }
        }

        SXEA11(dirwatch, "No watched directory found with fd %d", event->wd);

        flags |= (event->mask & IN_CREATE)     ? SXE_DIRWATCH_CREATED  : 0;
        flags |= (event->mask & IN_MOVED_TO)   ? SXE_DIRWATCH_CREATED  : 0;
        flags |= (event->mask & IN_MODIFY)     ? SXE_DIRWATCH_MODIFIED : 0;
        flags |= (event->mask & IN_DELETE)     ? SXE_DIRWATCH_DELETED  : 0;
        flags |= (event->mask & IN_MOVED_FROM) ? SXE_DIRWATCH_DELETED  : 0;

        dirwatch->notify(EV_A_ event->name, flags, dirwatch->user_data);
    }

    SXER60("return");
}
예제 #10
0
static void
test_pool_1_timeout(void * array, unsigned array_index, void * caller_info)
{
    SXEE83("test_pool_1_timeout(array=%p,array_index=%u,caller_info=%p)", array, array_index, caller_info);
    SXE_UNUSED_PARAMETER(caller_info);
    test_pool_1_timeout_call_count ++;

    if (1 == test_pool_1_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_ABUSED, TEST_STATE_FREE);
    }

    if (2 == test_pool_1_timeout_call_count) {
        sxe_pool_set_indexed_element_state(array, array_index, TEST_STATE_USED,   TEST_STATE_FREE);
    }

    SXER80("return");
}