memcache/server.h
author Tero Marttila <terom@fixme.fi>
Sat, 30 Aug 2008 19:13:15 +0300
changeset 49 10c7dce1a043
parent 48 1c67f512779b
permissions -rw-r--r--
autogenerate the memcache_test help output, and pipeline memcache requests
#ifndef MEMCACHE_SERVER_H
#define MEMCACHE_SERVER_H

#include <sys/queue.h>

#include "../memcache.h"
#include "request.h"
#include "../config.h"

struct memcache_server {
    // the memcache context we belong to
    struct memcache *mc;
    
    // our endpoint
    struct config_endpoint *endpoint;
    
    // we are a member of struct memcache.server_list
    LIST_ENTRY(memcache_server) serverlist_node;

    // a list of connections for this server
    LIST_HEAD(memcache_connlist_head, memcache_conn) conn_list;

    // a list of enqueued requests waiting for a connection
    struct memcache_reqqueue_head req_queue;

    // how many connections we should have at most
    int max_connections;
};

/*
 * Alloc and return a new memcache_server
 */
struct memcache_server *memcache_server_alloc (struct memcache *mc, struct config_endpoint *endpoint, int max_connections);

/*
 * Attempt to grow the connection pool by one connection. Doesn't do anything if we already have too many connections,
 * otherwise the new connection will be opened and added to the conn_list.
 */
void memcache_server_grow_connpool (struct memcache_server *server);

/*
 * Process the given request on this server.
 */
int memcache_server_add_req (struct memcache_server *server, struct memcache_req *req);

/*
 * The given connection is ready for use
 */
void memcache_server_conn_ready (struct memcache_server *server, struct memcache_conn *conn);

/*
 * The given connection failed/died. This will take care of freeing it/reconnecting it
 */
void memcache_server_conn_dead (struct memcache_server *server, struct memcache_conn *conn);

#endif /* MEMCACHE_SERVER_H */