#include "config.h"
#include <assert.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/tcp.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
response_handler(cookie, header, (void*)&response);
/* I need a better way to signal to close the connection */
- return PROTOCOL_BINARY_RESPONSE_EIO;
+ return PROTOCOL_BINARY_RESPONSE_EINTERNAL;
}
static protocol_binary_response_status get_command_handler(const void *cookie,
msg.response.message.body.flags= htonl(item->flags);
char *ptr= (char*)(msg.response.bytes + sizeof(*header) + 4);
uint32_t bodysize= 4;
- msg.response.message.header.response.cas= htonll(item->cas);
+ msg.response.message.header.response.cas= memcached_htonll(item->cas);
if (opcode == PROTOCOL_BINARY_CMD_GETK || opcode == PROTOCOL_BINARY_CMD_GETKQ)
{
memcpy(ptr, item->key, item->nkey);
};
uint16_t keylen= ntohs(header->request.keylen);
- uint64_t initial= ntohll(req->message.body.initial);
- uint64_t delta= ntohll(req->message.body.delta);
+ uint64_t initial= memcached_ntohll(req->message.body.initial);
+ uint64_t delta= memcached_ntohll(req->message.body.delta);
uint32_t expiration= ntohl(req->message.body.expiration);
uint32_t flags= 0;
void *key= req->bytes + sizeof(req->bytes);
if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS)
{
response.message.header.response.bodylen= ntohl(8);
- response.message.body.value= ntohll((*(uint64_t*)item->data));
- response.message.header.response.cas= ntohll(item->cas);
+ response.message.body.value= memcached_ntohll((*(uint64_t*)item->data));
+ response.message.header.response.cas= memcached_ntohll(item->cas);
release_item(item);
if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ ||
.opcode= PROTOCOL_BINARY_CMD_VERSION,
.status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS),
.opaque= header->request.opaque,
+ .cas= 0,
.bodylen= htonl((uint32_t)strlen(versionstring))
}
};
{
protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
uint16_t keylen= ntohs(header->request.keylen);
- uint64_t cas= ntohll(header->request.cas);
+ uint64_t cas= memcached_ntohll(header->request.cas);
void *key= header + 1;
uint32_t vallen= ntohl(header->request.bodylen) - keylen;
void *val= (char*)key + keylen;
.opcode= header->request.opcode,
.status= htons(rval),
.opaque= header->request.opaque,
- .cas= htonll(cas),
+ .cas= memcached_htonll(cas),
}
}
};
struct item* item= get_item(key, keylen);
if (item != NULL)
{
- if (item->cas != ntohll(header->request.cas))
+ if (item->cas != memcached_ntohll(header->request.cas))
{
release_item(item);
response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS);
/* SETQ shouldn't return a message */
if (header->request.opcode == PROTOCOL_BINARY_CMD_SET)
{
- response.message.header.response.cas= htonll(item->cas);
+ response.message.header.response.cas= memcached_htonll(item->cas);
release_item(item);
return response_handler(cookie, header, (void*)&response);
}
/* ADDQ shouldn't return a message */
if (header->request.opcode == PROTOCOL_BINARY_CMD_ADD)
{
- response.message.header.response.cas= htonll(item->cas);
+ response.message.header.response.cas= memcached_htonll(item->cas);
release_item(item);
return response_handler(cookie, header, (void*)&response);
}
struct item* item= get_item(key, keylen);
if (item == NULL)
+ {
response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT);
- else if (header->request.cas == 0 || ntohll(header->request.cas) == item->cas)
+ }
+ else if (header->request.cas == 0 || memcached_ntohll(header->request.cas) == item->cas)
{
release_item(item);
delete_item(key, keylen);
item= create_item(key, keylen, data, datalen, flags, timeout);
+
if (item == NULL)
+ {
response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM);
+ }
else
{
put_item(item);
/* REPLACEQ shouldn't return a message */
if (header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE)
{
- response.message.header.response.cas= htonll(item->cas);
+ response.message.header.response.cas= memcached_htonll(item->cas);
release_item(item);
return response_handler(cookie, header, (void*)&response);
}
}
memcached_binary_protocol_callback_st interface_v0_impl= {
- .interface_version= 0,
+ .interface_version= MEMCACHED_PROTOCOL_HANDLER_V0,
#ifdef FUTURE
/*
- ** There is a number of bugs in the extra options for gcc causing
+ ** There is a number of bugs in the extra options for gcc causing
** warning on these struct initializers. It hurts my heart to remove
** it so I'll just leave it in here so that we can enable it when
** we can drop support for the broken compilers