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"
24 #include "libmemcached/socket.hpp"
27 * I don't really need the following two functions as function pointers
28 * in the instance handle, but I don't want to put them in the global
29 * namespace for those linking statically (personally I don't like that,
30 * but some people still do). If it ever shows up as a performance thing
31 * I'll look into optimizing this ;-)
33 typedef bool (*drain_func
)(memcached_protocol_client_st
*client
);
34 typedef protocol_binary_response_status (*spool_func
)(memcached_protocol_client_st
*client
,
35 const void *data
, size_t length
);
38 * Definition of the per instance structure.
40 struct memcached_protocol_st
{
41 memcached_binary_protocol_callback_st
*callback
;
42 memcached_protocol_recv_func recv
;
43 memcached_protocol_send_func send
;
46 * I really don't need these as funciton pointers, but I don't want
47 * to clutter the namespace if someone links statically.
53 * To avoid keeping a buffer in each client all the time I have a
54 * bigger buffer in the instance that I read to initially, and then
55 * I try to parse and execute as much from the buffer. If I wasn't able
56 * to process all data I'll keep that in a per-connection buffer until
57 * the next time I can read from the socket.
59 uint8_t *input_buffer
;
60 size_t input_buffer_size
;
63 /* @todo use multiple sized buffers */
64 cache_t
*buffer_cache
;
68 /* Pointer to the data */
70 /* The offset to the first byte into the buffer that is used */
72 /* The offset into the buffer for the first free byte */
74 /* The number of bytes in the buffer */
76 /* Pointer to the next buffer in the chain */
77 struct chunk_st
*next
;
80 #define CHUNK_BUFFERSIZE 2048
82 typedef memcached_protocol_event_t (*process_data
)(struct memcached_protocol_client_st
*client
,
83 ssize_t
*length
, void **endptr
);
105 struct memcached_protocol_client_st
{
107 memcached_protocol_st
*root
;
108 memcached_socket_t sock
;
111 /* Linked list of data to send */
112 struct chunk_st
*output
;
113 struct chunk_st
*output_tail
;
116 * While we process input data, this is where we spool incomplete commands
117 * if we need to receive more data....
118 * @todo use the buffercace
120 uint8_t *input_buffer
;
121 size_t input_buffer_size
;
122 size_t input_buffer_offset
;
124 /* The callback to the protocol handler to use (ascii or binary) */
128 * Should the spool data discard the data to send or not? (aka noreply in
129 * the ascii protocol..
133 /* Members used by the binary protocol */
134 protocol_binary_request_header
*current_command
;
136 /* Members used by the ascii protocol */
137 enum ascii_cmd ascii_command
;
140 #include "ascii_handler.h"
141 #include "binary_handler.h"