memcache/connection.h
author Tero Marttila <terom@fixme.fi>
Sat, 30 Aug 2008 19:13:15 +0300
changeset 49 10c7dce1a043
parent 43 e5b714190dee
permissions -rw-r--r--
autogenerate the memcache_test help output, and pipeline memcache requests
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef MEMCACHE_CONNECTION_H
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define MEMCACHE_CONNECTION_H
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
#include <sys/queue.h>
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include <event2/event.h>
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
#include <event2/event_struct.h>
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
     8
#include <event2/bufferevent.h>
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include "server.h"
49
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    11
#include "request.h"
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    12
#include "command.h"
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
struct memcache_conn {
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
    // the server we are connected to
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
    struct memcache_server *server;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    // we are a member of struct memcache_server.conn_list
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    LIST_ENTRY(memcache_conn) connlist_node;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
    // our socket fd
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
    int fd;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    24
    // socket events
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    25
    struct event ev_connect;
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    26
    struct event ev_read;
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    27
    struct event ev_write;
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    28
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    29
    // socket bufferevent
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    30
    struct bufferevent *bev;
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    31
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    32
    // have we succesfully connected yet?
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    33
    int is_connected;
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    
49
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    35
    /*
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    36
     * The list of requests that we are currently processing, and a pointer to the request that is currently being
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    37
     * sent.
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    38
     *  
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    39
     * New requests are enqueued on the end of this list.
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    40
     */
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    41
    struct memcache_reqqueue_head req_queue;
10c7dce1a043 autogenerate the memcache_test help output, and pipeline memcache requests
Tero Marttila <terom@fixme.fi>
parents: 43
diff changeset
    42
    struct memcache_req *send_req;
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    43
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    44
    // used to track our commands
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    45
    struct memcache_cmd cmd;
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
 * Allocate a memcache_conn struct, and initiate the connect
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
struct memcache_conn *memcache_conn_open (struct memcache_server *server);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
 * Attempt to connect to the server.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
 *
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
 * Assumes we are not already connecting/connected
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
int memcache_conn_connect (struct memcache_conn *conn);
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
/*
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    61
 * Check if the given connection is available, that is, connected and not busy
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    62
 */
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    63
int memcache_conn_is_available (struct memcache_conn *conn);
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    64
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    65
/*
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
 * The given connection must be idle, whereupon the given request is processed.
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
 */
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    68
void memcache_conn_do_req (struct memcache_conn *conn, struct memcache_req *req);
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    70
/*
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    71
 * Free all resources associated with a closed/failed connection
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    72
 */
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    73
void memcache_conn_free (struct memcache_conn *conn);
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    74
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
#endif /* MEMCACHE_CONNECTION_H */