#include <ctype.h>
#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
/*
** **********************************************************************
** INTERNAL INTERFACE
size_t nbytes)
{
(void)cookie;
- return send(fd, buf, nbytes, 0);
+ return send(fd, buf, nbytes, MSG_NOSIGNAL);
}
/**
*/
static bool drain_output(struct memcached_protocol_client_st *client)
{
- ssize_t len;
+ if (client->is_verbose)
+ {
+ fprintf(stderr, "%s:%d %s mute:%d output:%s length:%d\n", __FILE__, __LINE__, __func__, (int)client->mute,
+ client->output ? "yes" : "no",
+ client->output ? (int)(client->output->nbytes - client->output->offset) : 0);
+ }
/* Do we have pending data to send? */
while (client->output != NULL)
{
- len= client->root->send(client,
+ ssize_t len= client->root->send(client,
client->sock,
client->output->data + client->output->offset,
client->output->nbytes - client->output->offset);
const void *data,
size_t length)
{
+ if (client->is_verbose)
+ {
+ fprintf(stderr, "%s:%d %s mute:%d length:%d\n", __FILE__, __LINE__, __func__, (int)client->mute, (int)length);
+ }
+
if (client->mute)
{
return PROTOCOL_BINARY_RESPONSE_SUCCESS;
{
if (*client->root->input_buffer == (uint8_t)PROTOCOL_BINARY_REQ)
{
+ if (client->is_verbose)
+ {
+ fprintf(stderr, "%s:%d PROTOCOL: memcached_binary_protocol_process_data\n", __FILE__, __LINE__);
+ }
client->work= memcached_binary_protocol_process_data;
}
else if (client->root->callback->interface_version == 1)
{
+ if (client->is_verbose)
+ {
+ fprintf(stderr, "%s:%d PROTOCOL: memcached_ascii_protocol_process_data\n", __FILE__, __LINE__);
+ }
+
/*
* The ASCII protocol can only be used if the implementors provide
* an implementation for the version 1 of the interface..
}
else
{
+ if (client->is_verbose)
+ {
+ fprintf(stderr, "%s:%d PROTOCOL: Unsupported protocol\n", __FILE__, __LINE__);
+ }
+
/* Let's just output a warning the way it is supposed to look like
* in the ASCII protocol...
*/
const char *err= "CLIENT_ERROR: Unsupported protocol\r\n";
client->root->spool(client, err, strlen(err));
client->root->drain(client);
+
return MEMCACHED_PROTOCOL_ERROR_EVENT; /* Unsupported protocol */
}
{
free(ret);
ret= NULL;
+
return NULL;
}
{
free(ret->input_buffer);
free(ret);
+ ret= NULL;
}
}
struct memcached_protocol_client_st *memcached_protocol_create_client(struct memcached_protocol_st *instance, memcached_socket_t sock)
{
- struct memcached_protocol_client_st *ret= calloc(1, sizeof(*ret));
+ struct memcached_protocol_client_st *ret= calloc(1, sizeof(memcached_protocol_client_st));
if (ret != NULL)
{
ret->root= instance;
free(client);
}
+void memcached_protocol_client_set_verbose(struct memcached_protocol_client_st *client, bool arg)
+{
+ if (client)
+ {
+ client->is_verbose= arg;
+ }
+}
+
memcached_protocol_event_t memcached_protocol_client_work(struct memcached_protocol_client_st *client)
{
/* Try to send data and read from the socket */
memcached_protocol_event_t ret= MEMCACHED_PROTOCOL_READ_EVENT;
if (client->output)
+ {
ret|= MEMCACHED_PROTOCOL_READ_EVENT;
+ }
return ret;
}