in_port_t port;
memcached_socket_t fd;
uint32_t io_bytes_sent; /* # bytes sent since last read */
+ uint32_t request_id;
uint32_t server_failure_counter;
uint64_t server_failure_counter_query_id;
uint32_t weight;
}
protocol_binary_request_incr request= {}; // = {.bytes= {0}};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+ initialize_binary_request(instance, request.message.header);
+
request.message.header.request.opcode= cmd;
request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(instance->root->_namespace)));
request.message.header.request.extlen= 20;
#include <libmemcached/io.h>
#ifdef __cplusplus
#include <libmemcached/string.hpp>
+#include <libmemcached/memcached/protocol_binary.h>
#include <libmemcached/io.hpp>
#include <libmemcached/udp.hpp>
#include <libmemcached/do.hpp>
#include <libmemcached/internal.h>
#include <libmemcached/array.h>
#include <libmemcached/libmemcached_probes.h>
-#include <libmemcached/memcached/protocol_binary.h>
#include <libmemcached/byteorder.h>
#include <libmemcached/initialize_query.h>
#ifdef __cplusplus
bool should_flush= is_buffering ? false : true;
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+ initialize_binary_request(instance, request.message.header);
+
if (reply)
{
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE;
protocol_binary_request_set request= {};
size_t send_length= sizeof(request.bytes);
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+ initialize_binary_request(instance, request.message.header);
+
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_ADD;
request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(memc->_namespace)));
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
{
protocol_binary_request_flush request= {};
- request.message.header.request.magic= (uint8_t)PROTOCOL_BINARY_REQ;
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH;
request.message.header.request.extlen= 4;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
for (uint32_t x= 0; x < memcached_server_count(ptr); x++)
{
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ initialize_binary_request(instance, request.message.header);
if (reply)
{
}
protocol_binary_request_getk request= { }; //= {.bytes= {0}};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+ initialize_binary_request(instance, request.message.header);
if (mget_mode)
{
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ;
Send a noop command to flush the buffers
*/
protocol_binary_request_noop request= {}; //= {.bytes= {0}};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
for (uint32_t x= 0; x < memcached_server_count(ptr); ++x)
{
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ initialize_binary_request(instance, request.message.header);
if (memcached_server_response_count(instance))
{
}
protocol_binary_request_getk request= {};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+ initialize_binary_request(instance, request.message.header);
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
request.message.header.request.keylen= htons((uint16_t)(key_length[x] + memcached_array_size(ptr->_namespace)));
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
#include <libmemcached/common.h>
+void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header& header)
+{
+ server->request_id++;
+ header.request.magic= PROTOCOL_BINARY_REQ;
+ header.request.opaque= htons(server->request_id);
+}
+
enum memc_read_or_write {
MEM_READ,
MEM_WRITE
#pragma once
+void initialize_binary_request(memcached_server_write_instance_st server, protocol_binary_request_header&);
+
bool memcached_io_write(memcached_server_write_instance_st ptr);
ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
if (ptr->root->flags.binary_protocol)
{
protocol_binary_request_quit request= {}; // = {.bytes= {0}};
- request.message.header.request.magic = PROTOCOL_BINARY_REQ;
+
+ initialize_binary_request(ptr, request.message.header);
+
request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT;
request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES;
* as authenticated
*/
protocol_binary_request_no_extras request= { };
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+
+ initialize_binary_request(ptr, request.message.header);
+
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SASL_LIST_MECHS;
if (memcached_io_write(server, request.bytes,
self->port= port;
self->fd= INVALID_SOCKET;
self->io_bytes_sent= 0;
+ self->request_id= 0;
self->server_failure_counter= 0;
self->server_failure_counter_query_id= 0;
self->weight= weight ? weight : 1; // 1 is the default weight value
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
protocol_binary_request_stats request= {}; // = {.bytes= {0}};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+
+ initialize_binary_request(instance, request.message.header);
+
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_STAT;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
protocol_binary_request_set request= {};
size_t send_length= sizeof(request.bytes);
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+ initialize_binary_request(server, request.message.header);
+
request.message.header.request.opcode= get_com_code(verb, reply);
request.message.header.request.keylen= htons((uint16_t)(key_length + memcached_array_size(ptr->_namespace)));
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
time_t expiration)
{
protocol_binary_request_touch request= {}; //{.bytes= {0}};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+
+ initialize_binary_request(instance, request.message.header);
+
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_TOUCH;
request.message.header.request.extlen= 4;
request.message.header.request.keylen= htons((uint16_t)(key_length +memcached_array_size(instance->root->_namespace)));
static inline memcached_return_t memcached_version_binary(memcached_st *ptr)
{
protocol_binary_request_version request= {};
- request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_VERSION;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
{
memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x);
+ initialize_binary_request(instance, request.message.header);
+
if (instance->major_version != UINT8_MAX)
{
continue;