ci: bsds: rebuild packages after reconfiguration
[m6w6/libmemcached] / include / libmemcachedprotocol-0.0 / handler.h
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #include <sys/types.h>
19 #ifndef HAVE_SSIZE_T
20 typedef long int ssize_t;
21 #endif
22
23 #ifndef __cplusplus
24 # include <stdbool.h>
25 # include <stdint.h>
26 # include <stddef.h>
27 #else
28 # include <cstdint>
29 #endif
30
31 #include "libmemcached-1.0/visibility.h"
32 #include "libmemcached-1.0/platform.h"
33 #include "libmemcachedprotocol-0.0/binary.h"
34 #include "libmemcachedprotocol-0.0/callback.h"
35
36 /* Forward declarations */
37 /*
38 * You should only access memcached_protocol_st from one thread!,
39 * and never assume anything about the internal layout / sizes of the
40 * structures.
41 */
42 typedef struct memcached_protocol_st memcached_protocol_st;
43 typedef struct memcached_protocol_client_st memcached_protocol_client_st;
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 /**
50 * Function the protocol handler should call to receive data.
51 * This function should behave exactly like read(2)
52 *
53 * @param cookie a cookie used to represent a given client
54 * @param fd the filedescriptor associated with the client
55 * @param buf destination buffer
56 * @param nbuf number of bytes to receive
57 * @return the number of bytes copied into buf
58 * or -1 upon error (errno should contain more information)
59 */
60 typedef ssize_t (*memcached_protocol_recv_func)(const void *cookie, memcached_socket_t fd,
61 void *buf, size_t nbuf);
62
63 /**
64 * Function the protocol handler should call to send data.
65 * This function should behave exactly like write(2)
66 *
67 * @param cookie a cookie used to represent a given client
68 * @param fd the filedescriptor associated with the client
69 * @param buf the source buffer
70 * @param nbuf number of bytes to send
71 * @return the number of bytes sent
72 * or -1 upon error (errno should contain more information)
73 */
74 typedef ssize_t (*memcached_protocol_send_func)(const void *cookie, memcached_socket_t fd,
75 const void *buf, size_t nbuf);
76
77 /**
78 * Create an instance of the protocol handler
79 *
80 * @return NULL if allocation of an instance fails
81 */
82 LIBMEMCACHED_API
83 memcached_protocol_st *memcached_protocol_create_instance(void);
84
85 /**
86 * Get the callbacks associated with a protocol handler instance
87 * @return the callbacks currently used
88 */
89 LIBMEMCACHED_API
90 memcached_binary_protocol_callback_st *
91 memcached_binary_protocol_get_callbacks(memcached_protocol_st *instance);
92
93 /**
94 * Set the callbacks to be used by the given protocol handler instance
95 * @param instance the instance to update
96 * @param callback the callbacks to use
97 */
98 LIBMEMCACHED_API
99 void memcached_binary_protocol_set_callbacks(memcached_protocol_st *instance,
100 memcached_binary_protocol_callback_st *callback);
101
102 /**
103 * Should the library inspect the packages being sent and received and verify
104 * that they are according to the specification? If it encounters an invalid
105 * packet, it will return an EINVAL packet.
106 *
107 * @param instance the instance to update
108 * @param enable true if you want the library to check packages, false otherwise
109 */
110 LIBMEMCACHED_API
111 void memcached_binary_protocol_set_pedantic(memcached_protocol_st *instance, bool enable);
112
113 /**
114 * Is the library inpecting each package?
115 * @param instance the instance to check
116 * @return true it the library is inspecting each package, false otherwise
117 */
118 LIBMEMCACHED_API
119 bool memcached_binary_protocol_get_pedantic(memcached_protocol_st *instance);
120
121 /**
122 * Destroy an instance of the protocol handler
123 *
124 * @param instance The instance to destroy
125 */
126 LIBMEMCACHED_API
127 void memcached_protocol_destroy_instance(memcached_protocol_st *instance);
128
129 /**
130 * Set the IO functions used by the instance to send and receive data. The
131 * functions should behave like recv(3socket) and send(3socket).
132 *
133 * @param instance the instance to specify the IO functions for
134 * @param recv the function to call for reciving data
135 * @param send the function to call for sending data
136 */
137 LIBMEMCACHED_API
138 void memached_protocol_set_io_functions(memcached_protocol_st *instance,
139 memcached_protocol_recv_func recv,
140 memcached_protocol_send_func send);
141
142 /**
143 * Create a new client instance and associate it with a socket
144 * @param instance the protocol instance to bind the client to
145 * @param sock the client socket
146 * @return NULL if allocation fails, otherwise an instance
147 */
148 LIBMEMCACHED_API
149 memcached_protocol_client_st *memcached_protocol_create_client(memcached_protocol_st *instance,
150 memcached_socket_t sock);
151
152 /**
153 * Destroy a client handle.
154 * The caller needs to close the socket accociated with the client
155 * <b>before</b> calling this function. This function invalidates the
156 * client memory area.
157 *
158 * @param client the client to destroy
159 */
160 LIBMEMCACHED_API
161 void memcached_protocol_client_destroy(memcached_protocol_client_st *client);
162
163 LIBMEMCACHED_API
164 void memcached_protocol_client_set_verbose(struct memcached_protocol_client_st *client, bool arg);
165
166 /**
167 * Error event means that the client encountered an error with the
168 * connection so you should shut it down
169 */
170 #define MEMCACHED_PROTOCOL_ERROR_EVENT 1
171 /**
172 * Please notify when there is more data available to read
173 */
174 #define MEMCACHED_PROTOCOL_READ_EVENT 2
175 /**
176 * Please notify when it is possible to send more data
177 */
178 #define MEMCACHED_PROTOCOL_WRITE_EVENT 4
179 /**
180 * Backed paused the execution for this client
181 */
182 #define MEMCACHED_PROTOCOL_PAUSE_EVENT 8
183
184 /**
185 * The different events the client is interested in. This is a bitmask of
186 * the constants defined above.
187 */
188 typedef uint32_t memcached_protocol_event_t;
189
190 /**
191 * Let the client do some work. This might involve reading / sending data
192 * to/from the client, or perform callbacks to execute a command.
193 * @param client the client structure to work on
194 * @return The next event the protocol handler will be notified for
195 */
196 LIBMEMCACHED_API
197 memcached_protocol_event_t memcached_protocol_client_work(memcached_protocol_client_st *client);
198
199 /**
200 * Get the socket attached to a client handle
201 * @param client the client to query
202 * @return the socket handle
203 */
204 LIBMEMCACHED_API
205 memcached_socket_t memcached_protocol_client_get_socket(memcached_protocol_client_st *client);
206
207 /**
208 * Get the error id socket attached to a client handle
209 * @param client the client to query for an error code
210 * @return the OS error code from the client
211 */
212 LIBMEMCACHED_API
213 int memcached_protocol_client_get_errno(memcached_protocol_client_st *client);
214
215 /**
216 * Get a raw response handler for the given cookie
217 * @param cookie the cookie passed along into the callback
218 * @return the raw reponse handler you may use if you find
219 * the generic callback too limiting
220 */
221 LIBMEMCACHED_API
222 memcached_binary_protocol_raw_response_handler
223 memcached_binary_protocol_get_raw_response_handler(const void *cookie);
224
225 #ifdef __cplusplus
226 }
227 #endif