Merge trunk
[awesomized/libmemcached] / libmemcached / protocol / common.h
1 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 #ifndef MEMCACHED_PROTOCOL_INTERNAL_H
3 #define MEMCACHED_PROTOCOL_INTERNAL_H
4
5 #include "config.h"
6 #include <stdbool.h>
7 #include <assert.h>
8 #include <netinet/in.h>
9
10 #ifdef linux
11 /* /usr/include/netinet/in.h defines macros from ntohs() to _bswap_nn to
12 * optimize the conversion functions, but the prototypes generate warnings
13 * from gcc. The conversion methods isn't the bottleneck for my app, so
14 * just remove the warnings by undef'ing the optimization ..
15 */
16 #undef ntohs
17 #undef ntohl
18 #undef htons
19 #undef htonl
20
21 #endif
22
23
24 /* Define this here, which will turn on the visibilty controls while we're
25 * building libmemcached.
26 */
27 #define BUILDING_LIBMEMCACHED 1
28
29 #include <libmemcached/protocol_handler.h>
30 #include <libmemcached/protocol/cache.h>
31
32 struct memcached_binary_protocol_st {
33 struct memcached_binary_protocol_callback_st *callback;
34 memcached_binary_protocol_recv_func recv;
35 memcached_binary_protocol_send_func send;
36 char *input_buffer;
37 size_t input_buffer_size;
38 bool pedantic;
39 /* @todo use multiple sized buffers */
40 cache_t *buffer_cache;
41 };
42
43
44 struct chunk_st {
45 /* Pointer to the data */
46 char *data;
47 /* The offset to the first byte into the buffer that is used */
48 size_t offset;
49 /* The offset into the buffer for the first free byte */
50 size_t nbytes;
51 /* The number of bytes in the buffer */
52 size_t size;
53 /* Pointer to the next buffer in the chain */
54 struct chunk_st *next;
55 };
56
57 #define CHUNK_BUFFERSIZE 2048
58
59 struct memcached_binary_protocol_client_st {
60 struct memcached_binary_protocol_st *root;
61 int sock;
62 int error;
63
64 /* Linked list of data to send */
65 struct chunk_st *output;
66 struct chunk_st *output_tail;
67
68
69
70 char *input_buffer;
71 size_t input_buffer_size;
72 size_t input_buffer_offset;
73 char *curr_input;
74
75
76 struct chunk_st *input;
77 /* Pointer to the last chunk to avoid the need to traverse the complete list */
78 struct chunk_st *input_tail;
79 size_t bytes_available;
80
81 protocol_binary_request_header *current_command;
82 bool quiet;
83 };
84
85 LIBMEMCACHED_LOCAL
86 bool memcached_binary_protocol_pedantic_check_request(protocol_binary_request_header *request);
87
88 LIBMEMCACHED_LOCAL
89 bool memcached_binary_protocol_pedantic_check_response(protocol_binary_request_header *request,
90 protocol_binary_response_header *response);
91
92
93 #endif