memcache/server.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 Aug 2008 03:14:07 +0300
changeset 47 a5c09677ca6f
parent 43 e5b714190dee
child 48 1c67f512779b
permissions -rw-r--r--
add the coro_test.c file, and update .hgignore a bit
#ifndef MEMCACHE_SERVER_H
#define MEMCACHE_SERVER_H

#include <sys/queue.h>

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

struct memcache_server {
    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
    TAILQ_HEAD(memcache_reqqueue_head, memcache_req) 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 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.
 */
int 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 */