be strict about port numbers being in in_port_t not uint32_t
[m6w6/libmemcached] / libmemcached / io.h
1 /* LibMemcached
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Summary: Server IO, Not public!
9 *
10 */
11
12 #ifndef LIBMEMCACHED_MEMCACHED_IO_H
13 #define LIBMEMCACHED_MEMCACHED_IO_H
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #if defined(BUILDING_LIBMEMCACHED)
20
21 #include "libmemcached/memcached.h"
22
23 #define MAX_UDP_DATAGRAM_LENGTH 1400
24 #define UDP_DATAGRAM_HEADER_LENGTH 8
25 #define UDP_REQUEST_ID_MSG_SIG_DIGITS 10
26 #define UDP_REQUEST_ID_THREAD_MASK 0xFFFF << UDP_REQUEST_ID_MSG_SIG_DIGITS
27 #define get_udp_datagram_request_id(A) ntohs((A)->request_id)
28 #define get_udp_datagram_seq_num(A) ntohs((A)->sequence_number)
29 #define get_udp_datagram_num_datagrams(A) ntohs((A)->num_datagrams)
30 #define get_msg_num_from_request_id(A) ( (A) & (~(UDP_REQUEST_ID_THREAD_MASK)) )
31 #define get_thread_id_from_request_id(A) ( (A) & (UDP_REQUEST_ID_THREAD_MASK) ) >> UDP_REQUEST_ID_MSG_SIG_DIGITS
32 #define generate_udp_request_thread_id(A) (A) << UDP_REQUEST_ID_MSG_SIG_DIGITS
33 #define UDP_REQUEST_ID_MAX_THREAD_ID get_thread_id_from_request_id(0xFFFF)
34
35 struct udp_datagram_header_st
36 {
37 uint16_t request_id;
38 uint16_t sequence_number;
39 uint16_t num_datagrams;
40 uint16_t reserved;
41 };
42
43 LIBMEMCACHED_LOCAL
44 ssize_t memcached_io_write(memcached_server_st *ptr,
45 const void *buffer, size_t length, char with_flush);
46
47 LIBMEMCACHED_LOCAL
48 void memcached_io_reset(memcached_server_st *ptr);
49
50 LIBMEMCACHED_LOCAL
51 memcached_return_t memcached_io_read(memcached_server_st *ptr,
52 void *buffer, size_t length, ssize_t *nread);
53
54 /* Read a line (terminated by '\n') into the buffer */
55 LIBMEMCACHED_LOCAL
56 memcached_return_t memcached_io_readline(memcached_server_st *ptr,
57 char *buffer_ptr,
58 size_t size);
59
60 LIBMEMCACHED_LOCAL
61 memcached_return_t memcached_io_close(memcached_server_st *ptr);
62
63 /* Read n bytes of data from the server and store them in dta */
64 LIBMEMCACHED_LOCAL
65 memcached_return_t memcached_safe_read(memcached_server_st *ptr,
66 void *dta,
67 size_t size);
68
69 /* Read a single response from the server */
70 LIBMEMCACHED_LOCAL
71 memcached_return_t memcached_read_one_response(memcached_server_st *ptr,
72 char *buffer, size_t buffer_length,
73 memcached_result_st *result);
74
75 LIBMEMCACHED_LOCAL
76 memcached_return_t memcached_io_init_udp_header(memcached_server_st *ptr,
77 uint16_t thread_id);
78
79 LIBMEMCACHED_LOCAL
80 memcached_server_st *memcached_io_get_readable_server(memcached_st *memc);
81
82 #endif /* BUILDING_LIBMEMCACHED */
83
84 #ifdef __cplusplus
85 }
86 #endif
87
88 #endif /* LIBMEMCACHED_MEMCACHED_IO_H */