memcache/connection.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 Aug 2008 00:29:39 +0300
changeset 43 e5b714190dee
parent 41 540737bf6bac
child 49 10c7dce1a043
permissions -rw-r--r--
the request/reply code should be complete now, but still needs testing
#ifndef MEMCACHE_CONNECTION_H
#define MEMCACHE_CONNECTION_H

#include <sys/queue.h>

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

#include "server.h"
#include "command.h"

struct memcache_conn {
    // the server we are connected to
    struct memcache_server *server;

    // we are a member of struct memcache_server.conn_list
    LIST_ENTRY(memcache_conn) connlist_node;
    
    // our socket fd
    int fd;

    // socket events
    struct event ev_connect;
    struct event ev_read;
    struct event ev_write;

    // socket bufferevent
    struct bufferevent *bev;

    // have we succesfully connected yet?
    int is_connected;
    
    // the request (if any) that we are currently processing - NULL for idle connections
    struct memcache_req *req;

    // used to track our commands
    struct memcache_cmd cmd;
};

/*
 * Allocate a memcache_conn struct, and initiate the connect
 */
struct memcache_conn *memcache_conn_open (struct memcache_server *server);

/*
 * Attempt to connect to the server.
 *
 * Assumes we are not already connecting/connected
 */
int memcache_conn_connect (struct memcache_conn *conn);

/*
 * Check if the given connection is available, that is, connected and not busy
 */
int memcache_conn_is_available (struct memcache_conn *conn);

/*
 * The given connection must be idle, whereupon the given request is processed.
 */
void memcache_conn_do_req (struct memcache_conn *conn, struct memcache_req *req);

/*
 * Free all resources associated with a closed/failed connection
 */
void memcache_conn_free (struct memcache_conn *conn);

#endif /* MEMCACHE_CONNECTION_H */