#include <stdlib.h>
#include <sys/types.h>
-#include <sys/socket.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
* @return the number of bytes transferred of -1 upon error
*/
static ssize_t default_recv(const void *cookie,
- int sock,
+ memcached_socket_t sock,
void *buf,
size_t nbytes)
{
* @return the number of bytes transferred of -1 upon error
*/
static ssize_t default_send(const void *cookie,
- int fd,
+ memcached_socket_t fd,
const void *buf,
size_t nbytes)
{
if (len == -1)
{
- if (errno == EWOULDBLOCK)
+ if (get_socket_errno() == EWOULDBLOCK)
{
return true;
}
- else if (errno != EINTR)
+ else if (get_socket_errno() != EINTR)
{
- client->error= errno;
+ client->error= get_socket_errno();
return false;
}
}
return NULL;
}
- ret->offset = ret->nbytes = 0;
- ret->next = NULL;
- ret->size = CHUNK_BUFFERSIZE;
+ ret->offset= ret->nbytes= 0;
+ ret->next= NULL;
+ ret->size= CHUNK_BUFFERSIZE;
ret->data= (void*)(ret + 1);
if (client->output == NULL)
{
- client->output = client->output_tail = ret;
+ client->output= client->output_tail= ret;
}
else
{
return PROTOCOL_BINARY_RESPONSE_SUCCESS;
}
- size_t offset = 0;
+ size_t offset= 0;
struct chunk_st *chunk= client->output;
while (offset < length)
}
}
- size_t bulk = length - offset;
+ size_t bulk= length - offset;
if (bulk > chunk->size - chunk->nbytes)
{
- bulk = chunk->size - chunk->nbytes;
+ bulk= chunk->size - chunk->nbytes;
}
memcpy(chunk->data + chunk->nbytes, data, bulk);
* so the implementors needs to provide an implementation of that interface
*
*/
-static enum MEMCACHED_PROTOCOL_EVENT determine_protocol(struct memcached_protocol_client_st *client, ssize_t *length, void **endptr)
+static memcached_protocol_event_t determine_protocol(struct memcached_protocol_client_st *client, ssize_t *length, void **endptr)
{
if (*client->root->input_buffer == (uint8_t)PROTOCOL_BINARY_REQ)
{
const char *err= "CLIENT_ERROR: Unsupported protocol\r\n";
client->root->spool(client, err, strlen(err));
client->root->drain(client);
- return ERROR_EVENT; /* Unsupported protocol */
+ return MEMCACHED_PROTOCOL_ERROR_EVENT; /* Unsupported protocol */
}
return client->work(client, length, endptr);
return NULL;
}
- ret->buffer_cache = cache_create("protocol_handler",
+ ret->buffer_cache= cache_create("protocol_handler",
CHUNK_BUFFERSIZE + sizeof(struct chunk_st),
0, NULL, NULL);
- if (ret->buffer_cache == NULL)
+ if (ret->buffer_cache == NULL)
{
free(ret->input_buffer);
free(ret);
free(instance);
}
-struct memcached_protocol_client_st *memcached_protocol_create_client(struct memcached_protocol_st *instance, int sock)
+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));
if (ret != NULL)
free(client);
}
-enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_protocol_client_st *client)
+memcached_protocol_event_t memcached_protocol_client_work(struct memcached_protocol_client_st *client)
{
/* Try to send data and read from the socket */
bool more_data= true;
}
void *endptr;
- if (client->work(client, &len, &endptr) == ERROR_EVENT)
+ memcached_protocol_event_t events= client->work(client, &len, &endptr);
+ if (events == MEMCACHED_PROTOCOL_ERROR_EVENT)
{
- return ERROR_EVENT;
+ return MEMCACHED_PROTOCOL_ERROR_EVENT;
}
if (len > 0)
if (client->input_buffer == NULL)
{
client->error= ENOMEM;
- return ERROR_EVENT;
+ return MEMCACHED_PROTOCOL_ERROR_EVENT;
}
memcpy(client->input_buffer, endptr, (size_t)len);
client->input_buffer_offset= (size_t)len;
{
/* Connection closed */
drain_output(client);
- return ERROR_EVENT;
+ return MEMCACHED_PROTOCOL_ERROR_EVENT;
}
else
{
- if (errno != EWOULDBLOCK)
+ if (get_socket_errno() != EWOULDBLOCK)
{
- client->error= errno;
+ client->error= get_socket_errno();
/* mark this client as terminated! */
- return ERROR_EVENT;
+ return MEMCACHED_PROTOCOL_ERROR_EVENT;
}
- more_data = false;
+ more_data= false;
}
} while (more_data);
if (!drain_output(client))
{
- return ERROR_EVENT;
+ return MEMCACHED_PROTOCOL_ERROR_EVENT;
}
- return (client->output) ? READ_WRITE_EVENT : READ_EVENT;
+ memcached_protocol_event_t ret= MEMCACHED_PROTOCOL_READ_EVENT;
+ if (client->output)
+ ret|= MEMCACHED_PROTOCOL_READ_EVENT;
+
+ return ret;
}