memcache_test.c
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 21:30:32 +0300
changeset 41 540737bf6bac
parent 38 9894df13b779
child 44 03a7e064f833
permissions -rw-r--r--
sending requests, and partial support for receiving -- incomplete, not tested

#include <event2/event.h>
#include <event2/event_compat.h>
#include <event2/event_struct.h>

#include "memcache.h"
#include "config.h"
#include "common.h"

static struct memcache *mc;
static struct config_endpoint server_endpoint;

int _memcache_cb (struct memcache_req *req, void *arg) {
    return 0;
}

void begin_test () {
    if ((mc = memcache_alloc(&_memcache_cb)) == NULL)
        ERROR("memcache_alloc");
    
    endpoint_init(&server_endpoint, 11211);
    
    if (endpoint_parse(&server_endpoint, "localhost"))
        ERROR("config_endpoint_parse");

    if (memcache_add_server(mc, &server_endpoint, 1))
        ERROR("memcache_add_server");
    
    // XXX: we should have a connect() running now

error:
    return;
}

int main (int argc, char **argv) {
    // libevent init
    struct event_base *ev_base = event_init();

    if (!ev_base)
        FATAL("event_init");
    
    begin_test();

    // run the libevent mainloop
    if (event_base_dispatch(ev_base))
        WARNING("event_dispatch");

    INFO("SHUTDOWN");
    
    // clean up
    event_base_free(ev_base);
    
    // successfull exit
    return 0;
}