Change hosts over to realloc array
[awesomized/libmemcached] / include / memcached.h
1 #include <brian.h>
2 /*
3 * Summary: interface for memcached server
4 * Description: main include file for libmemcached
5 *
6 * Copy: See Copyright for the status of this software.
7 *
8 * Author: Brian Aker
9 */
10
11 #ifndef __MEMCACHED_H__
12 #define __MEMCACHED_H__
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <netdb.h>
22 #include <unistd.h>
23 #include <limits.h>
24 #include <assert.h>
25 #include <time.h>
26 #include <errno.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef struct memcached_st memcached_st;
33 typedef struct memcached_stat_st memcached_stat_st;
34 typedef struct memcached_host_st memcached_host_st;
35
36 #define MEMCACHED_DEFAULT_PORT 11211
37 #define MEMCACHED_DEFAULT_COMMAND_SIZE 350
38 #define HUGE_STRING_LEN 8196
39
40 typedef enum {
41 MEMCACHED_SUCCESS,
42 MEMCACHED_FAILURE,
43 MEMCACHED_HOST_LOCKUP_FAILURE,
44 MEMCACHED_CONNECTION_FAILURE,
45 MEMCACHED_CONNECTION_BIND_FAILURE,
46 MEMCACHED_WRITE_FAILURE,
47 MEMCACHED_READ_FAILURE,
48 MEMCACHED_UNKNOWN_READ_FAILURE,
49 MEMCACHED_PROTOCOL_ERROR,
50 MEMCACHED_CLIENT_ERROR,
51 MEMCACHED_SERVER_ERROR,
52 MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE,
53 MEMCACHED_DATA_EXISTS,
54 MEMCACHED_DATA_DOES_NOT_EXIST,
55 MEMCACHED_NOTSTORED,
56 MEMCACHED_NOTFOUND,
57 MEMCACHED_MEMORY_ALLOCATION_FAILURE,
58 MEMCACHED_PARTIAL_READ,
59 } memcached_return;
60
61 typedef enum {
62 MEMCACHED_NOT_ALLOCATED= 0,
63 MEMCACHED_ALLOCATED= 1,
64 } memcached_allocated;
65
66 struct memcached_host_st {
67 char *hostname;
68 unsigned int port;
69 int fd;
70 };
71
72 struct memcached_stat_st {
73 unsigned int pid;
74 unsigned int uptime;
75 unsigned int threads;
76 time_t time;
77 char version[8];
78 unsigned int pointer_size;
79 unsigned int rusage_user;
80 unsigned int rusage_system;
81 unsigned int rusage_user_seconds;
82 unsigned int rusage_user_microseconds;
83 unsigned int rusage_system_seconds;
84 unsigned int rusage_system_microseconds;
85 unsigned int curr_items;
86 unsigned int total_items;
87 unsigned long long bytes;
88 unsigned int curr_connections;
89 unsigned int total_connections;
90 unsigned int connection_structures;
91 unsigned long long cmd_get;
92 unsigned long long cmd_set;
93 unsigned long long get_hits;
94 unsigned long long get_misses;
95 unsigned long long evictions;
96 unsigned long long bytes_read;
97 unsigned long long bytes_written;
98 unsigned int limit_maxbytes;
99 };
100
101 struct memcached_st {
102 memcached_allocated is_allocated;
103 memcached_host_st *hosts;
104 unsigned int number_of_hosts;
105 char connected;
106 };
107
108 /* Public API */
109 memcached_st *memcached_init(memcached_st *ptr);
110 void memcached_deinit(memcached_st *ptr);
111
112 memcached_return memcached_set(memcached_st *ptr, char *key, size_t key_length,
113 char *value, size_t value_length,
114 time_t expiration,
115 uint16_t flags);
116 memcached_return memcached_add(memcached_st *ptr, char *key, size_t key_length,
117 char *value, size_t value_length,
118 time_t expiration,
119 uint16_t flags);
120 memcached_return memcached_replace(memcached_st *ptr, char *key, size_t key_length,
121 char *value, size_t value_length,
122 time_t expiration,
123 uint16_t flags);
124 memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_length,
125 time_t expiration);
126 memcached_return memcached_increment(memcached_st *ptr, char *key, size_t key_length,
127 unsigned int count);
128 memcached_return memcached_decrement(memcached_st *ptr, char *key, size_t key_length,
129 unsigned int count);
130 memcached_stat_st **memcached_stat(memcached_st *ptr, memcached_return *error);
131 memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
132 char *hostname, unsigned int port);
133 memcached_return memcached_flush(memcached_st *ptr, time_t expiration);
134 memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
135 memcached_return memcached_quit(memcached_st *ptr, char *hostname, unsigned port);
136 char *memcached_get(memcached_st *ptr, char *key, size_t key_length,
137 size_t *value_length,
138 uint16_t *flags,
139 memcached_return *error);
140 memcached_return memcached_server_add(memcached_st *ptr, char *hostname, unsigned int port);
141 char *memcached_strerror(memcached_st *ptr, memcached_return rc);
142
143 /* These are all private, do not use. */
144 memcached_return memcached_connect(memcached_st *ptr);
145 memcached_return memcached_response(memcached_st *ptr,
146 char *buffer,
147 size_t buffer_length);
148
149 #ifdef __cplusplus
150 }
151 #endif
152
153 #endif /* __MEMCACHED_H__ */