memcache/connection.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 Aug 2008 03:14:07 +0300
changeset 47 a5c09677ca6f
parent 43 e5b714190dee
child 49 10c7dce1a043
permissions -rw-r--r--
add the coro_test.c file, and update .hgignore a bit
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"
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    11
#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
    12
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
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
    14
    // 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
    15
    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
    16
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    // 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
    18
    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
    19
    
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
    // 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
    21
    int fd;
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    23
    // socket events
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    24
    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
    25
    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
    26
    struct event ev_write;
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    27
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    28
    // socket bufferevent
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    29
    struct bufferevent *bev;
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    30
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    31
    // have we succesfully connected yet?
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    32
    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
    33
    
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    // the request (if any) that we are currently processing - NULL for idle connections
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
    struct memcache_req *req;
41
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    36
540737bf6bac sending requests, and partial support for receiving -- incomplete, not tested
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    37
    // 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
    38
    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
    39
};
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
/*
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
 * 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
    43
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
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
    45
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
 * 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
    48
 *
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
 * 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
    50
 */
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
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
    52
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
/*
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    54
 * 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
    55
 */
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    56
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
    57
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    58
/*
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
 * 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
    60
 */
43
e5b714190dee the request/reply code should be complete now, but still needs testing
Tero Marttila <terom@fixme.fi>
parents: 41
diff changeset
    61
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
    62
39
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    63
/*
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    64
 * 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
    65
 */
0e21a65074a6 memcache connect error handling and req queuein
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    66
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
    67
38
9894df13b779 added the beginnings of the memcache client module (only up to connect() yet)
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
#endif /* MEMCACHE_CONNECTION_H */