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 +--------------------------------------------------------------------+
18 #include "mem_config.h"
21 #include "libmemcachedprotocol-0.0/handler.h"
22 #include "libmemcachedprotocol/cache.h"
23 #include "libmemcached/byteorder.h"
26 * I don't really need the following two functions as function pointers
27 * in the instance handle, but I don't want to put them in the global
28 * namespace for those linking statically (personally I don't like that,
29 * but some people still do). If it ever shows up as a performance thing
30 * I'll look into optimizing this ;-)
32 typedef bool (*drain_func
)(memcached_protocol_client_st
*client
);
33 typedef protocol_binary_response_status (*spool_func
)(memcached_protocol_client_st
*client
,
34 const void *data
, size_t length
);
37 * Definition of the per instance structure.
39 struct memcached_protocol_st
{
40 memcached_binary_protocol_callback_st
*callback
;
41 memcached_protocol_recv_func recv
;
42 memcached_protocol_send_func send
;
45 * I really don't need these as funciton pointers, but I don't want
46 * to clutter the namespace if someone links statically.
52 * To avoid keeping a buffer in each client all the time I have a
53 * bigger buffer in the instance that I read to initially, and then
54 * I try to parse and execute as much from the buffer. If I wasn't able
55 * to process all data I'll keep that in a per-connection buffer until
56 * the next time I can read from the socket.
58 uint8_t *input_buffer
;
59 size_t input_buffer_size
;
62 /* @todo use multiple sized buffers */
63 cache_t
*buffer_cache
;
67 /* Pointer to the data */
69 /* The offset to the first byte into the buffer that is used */
71 /* The offset into the buffer for the first free byte */
73 /* The number of bytes in the buffer */
75 /* Pointer to the next buffer in the chain */
76 struct chunk_st
*next
;
79 #define CHUNK_BUFFERSIZE 2048
81 typedef memcached_protocol_event_t (*process_data
)(struct memcached_protocol_client_st
*client
,
82 ssize_t
*length
, void **endptr
);
104 struct memcached_protocol_client_st
{
106 memcached_protocol_st
*root
;
107 memcached_socket_t sock
;
110 /* Linked list of data to send */
111 struct chunk_st
*output
;
112 struct chunk_st
*output_tail
;
115 * While we process input data, this is where we spool incomplete commands
116 * if we need to receive more data....
117 * @todo use the buffercace
119 uint8_t *input_buffer
;
120 size_t input_buffer_size
;
121 size_t input_buffer_offset
;
123 /* The callback to the protocol handler to use (ascii or binary) */
127 * Should the spool data discard the data to send or not? (aka noreply in
128 * the ascii protocol..
132 /* Members used by the binary protocol */
133 protocol_binary_request_header
*current_command
;
135 /* Members used by the ascii protocol */
136 enum ascii_cmd ascii_command
;
139 #include "ascii_handler.h"
140 #include "binary_handler.h"