Updating for vector interface.
[awesomized/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_IO_H__
13 #define __LIBMEMCACHED_IO_H__
14
15 #if defined(BUILDING_LIBMEMCACHED)
16
17 #include "libmemcached/memcached.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
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 struct __write_vector_st
44 {
45 size_t length;
46 const void *buffer;
47 };
48
49
50 LIBMEMCACHED_LOCAL
51 ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
52 struct __write_vector_st *vector,
53 size_t number_of, bool with_flush);
54
55 LIBMEMCACHED_LOCAL
56 ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
57 const void *buffer, size_t length, bool with_flush);
58
59 LIBMEMCACHED_LOCAL
60 void memcached_io_reset(memcached_server_write_instance_st ptr);
61
62 LIBMEMCACHED_LOCAL
63 memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
64 void *buffer, size_t length, ssize_t *nread);
65
66 /* Read a line (terminated by '\n') into the buffer */
67 LIBMEMCACHED_LOCAL
68 memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
69 char *buffer_ptr,
70 size_t size);
71
72 LIBMEMCACHED_LOCAL
73 memcached_return_t memcached_io_close(memcached_server_write_instance_st ptr);
74
75 /* Read n bytes of data from the server and store them in dta */
76 LIBMEMCACHED_LOCAL
77 memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
78 void *dta,
79 size_t size);
80
81 LIBMEMCACHED_LOCAL
82 memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr,
83 uint16_t thread_id);
84
85 LIBMEMCACHED_LOCAL
86 memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif /* BUILDING_LIBMEMCACHED */
93
94 #endif /* __LIBMEMCACHED_IO_H__ */