Fix compilation on Linux (lacks ntohll etc)
[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 /* Define this here, which will turn on the visibilty controls while we're
11 * building libmemcached.
12 */
13 #define BUILDING_LIBMEMCACHED 1
14
15 #include <libmemcached/byteorder.h>
16 #include <libmemcached/protocol_handler.h>
17 #include <libmemcached/protocol/cache.h>
18
19 struct memcached_binary_protocol_st {
20 struct memcached_binary_protocol_callback_st *callback;
21 memcached_binary_protocol_recv_func recv;
22 memcached_binary_protocol_send_func send;
23 char *input_buffer;
24 size_t input_buffer_size;
25 bool pedantic;
26 /* @todo use multiple sized buffers */
27 cache_t *buffer_cache;
28 };
29
30
31 struct chunk_st {
32 /* Pointer to the data */
33 char *data;
34 /* The offset to the first byte into the buffer that is used */
35 size_t offset;
36 /* The offset into the buffer for the first free byte */
37 size_t nbytes;
38 /* The number of bytes in the buffer */
39 size_t size;
40 /* Pointer to the next buffer in the chain */
41 struct chunk_st *next;
42 };
43
44 #define CHUNK_BUFFERSIZE 2048
45
46 struct memcached_binary_protocol_client_st {
47 struct memcached_binary_protocol_st *root;
48 int sock;
49 int error;
50
51 /* Linked list of data to send */
52 struct chunk_st *output;
53 struct chunk_st *output_tail;
54
55
56
57 char *input_buffer;
58 size_t input_buffer_size;
59 size_t input_buffer_offset;
60 char *curr_input;
61
62
63 struct chunk_st *input;
64 /* Pointer to the last chunk to avoid the need to traverse the complete list */
65 struct chunk_st *input_tail;
66 size_t bytes_available;
67
68 protocol_binary_request_header *current_command;
69 bool quiet;
70 };
71
72 LIBMEMCACHED_LOCAL
73 bool memcached_binary_protocol_pedantic_check_request(protocol_binary_request_header *request);
74
75 LIBMEMCACHED_LOCAL
76 bool memcached_binary_protocol_pedantic_check_response(protocol_binary_request_header *request,
77 protocol_binary_response_header *response);
78
79
80 #endif