memcache/server.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 10:13:38 +0300
changeset 40 9cecd22e643a
parent 39 0e21a65074a6
child 43 e5b714190dee
permissions -rw-r--r--
*queuing, and add missing file
#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
 */
void memcache_server_conn_dead (struct memcache_server *server, struct memcache_conn *conn);

#endif /* MEMCACHE_SERVER_H */