Update pandora
[m6w6/libmemcached] / libmemcached / memcached_io.h
1 /*
2 * Summary: Server IO, Not public!
3 *
4 * Copy: See Copyright for the status of this software.
5 *
6 * Author: Brian Aker
7 */
8
9 #ifndef LIBMEMCACHED_MEMCACHED_IO_H
10 #define LIBMEMCACHED_MEMCACHED_IO_H
11
12 #if defined(BUILDING_LIBMEMCACHED)
13
14 #include "libmemcached/memcached.h"
15
16 #define MAX_UDP_DATAGRAM_LENGTH 1400
17 #define UDP_DATAGRAM_HEADER_LENGTH 8
18 #define UDP_REQUEST_ID_MSG_SIG_DIGITS 10
19 #define UDP_REQUEST_ID_THREAD_MASK 0xFFFF << UDP_REQUEST_ID_MSG_SIG_DIGITS
20 #define get_udp_datagram_request_id(A) ntohs((A)->request_id)
21 #define get_udp_datagram_seq_num(A) ntohs((A)->sequence_number)
22 #define get_udp_datagram_num_datagrams(A) ntohs((A)->num_datagrams)
23 #define get_msg_num_from_request_id(A) ( (A) & (~(UDP_REQUEST_ID_THREAD_MASK)) )
24 #define get_thread_id_from_request_id(A) ( (A) & (UDP_REQUEST_ID_THREAD_MASK) ) >> UDP_REQUEST_ID_MSG_SIG_DIGITS
25 #define generate_udp_request_thread_id(A) (A) << UDP_REQUEST_ID_MSG_SIG_DIGITS
26 #define UDP_REQUEST_ID_MAX_THREAD_ID get_thread_id_from_request_id(0xFFFF)
27
28 struct udp_datagram_header_st {
29 uint16_t request_id;
30 uint16_t sequence_number;
31 uint16_t num_datagrams;
32 uint16_t reserved;
33 };
34
35 ssize_t memcached_io_write(memcached_server_st *ptr,
36 const void *buffer, size_t length, char with_flush);
37 void memcached_io_reset(memcached_server_st *ptr);
38 memcached_return memcached_io_read(memcached_server_st *ptr,
39 void *buffer, size_t length, ssize_t *nread);
40 /* Read a line (terminated by '\n') into the buffer */
41 memcached_return memcached_io_readline(memcached_server_st *ptr,
42 char *buffer_ptr,
43 size_t size);
44 memcached_return memcached_io_close(memcached_server_st *ptr);
45 /* Read n bytes of data from the server and store them in dta */
46 memcached_return memcached_safe_read(memcached_server_st *ptr,
47 void *dta,
48 size_t size);
49 /* Read a single response from the server */
50 memcached_return memcached_read_one_response(memcached_server_st *ptr,
51 char *buffer, size_t buffer_length,
52 memcached_result_st *result);
53 memcached_return memcached_io_init_udp_header(memcached_server_st *ptr,
54 uint16_t thread_id);
55
56 memcached_server_st *memcached_io_get_readable_server(memcached_st *memc);
57
58 #endif /* BUILDING_LIBMEMCACHED */
59 #endif /* LIBMEMCACHED_MEMCACHED_IO_H */