- case 'V': /* VALUE */
- return MEMCACHED_SUCCESS;
- case 'O': /* OK */
- return MEMCACHED_SUCCESS;
- case 'S': /* STORED */
- {
- if (buffer[1] == 'T')
- return MEMCACHED_SUCCESS;
- else if (buffer[1] == 'E')
- return MEMCACHED_SERVER_ERROR;
- else
- return MEMCACHED_UNKNOWN_READ_FAILURE;
- }
- case 'D': /* DELETED */
- return MEMCACHED_SUCCESS;
- case 'N': /* NOT_FOUND */
- {
- if (buffer[4] == 'F')
- return MEMCACHED_NOTFOUND;
- else if (buffer[4] == 'S')
- return MEMCACHED_NOTSTORED;
- else
- return MEMCACHED_UNKNOWN_READ_FAILURE;
- }
- case 'E': /* PROTOCOL ERROR */
- return MEMCACHED_PROTOCOL_ERROR;
- case 'C': /* CLIENT ERROR */
- return MEMCACHED_CLIENT_ERROR;
- default:
- return MEMCACHED_UNKNOWN_READ_FAILURE;
- }
-
- return MEMCACHED_READ_FAILURE;
-}
-
-static memcached_return memcached_send(memcached_st *ptr,
- char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags,
- char *verb)
-{
- size_t send_length;
- memcached_return rc;
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-
- rc= memcached_connect(ptr);
-
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %.*s %u %u %u\r\n", verb,
- key_length, key, flags, expiration, value_length);
- if ((send(ptr->fd, buffer, send_length, 0) == -1))
- {
- fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%.*s\r\n",
- value_length, value);
- if ((send(ptr->fd, buffer, send_length, 0) == -1))
- {
- fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- send_length= read(ptr->fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
-
- if (send_length && buffer[0] == 'S') /* STORED */
- return MEMCACHED_SUCCESS;
- else if (send_length && buffer[0] == 'N') /* NOT_STORED */
- return MEMCACHED_NOTSTORED;
- else
- return MEMCACHED_READ_FAILURE;
-}
-
-memcached_return memcached_set(memcached_st *ptr, char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags)
-{
- return memcached_send(ptr, key, key_length, value, value_length,
- expiration, flags, "set");
-}
-
-memcached_return memcached_add(memcached_st *ptr, char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags)
-{
- return memcached_send(ptr, key, key_length, value, value_length,
- expiration, flags, "add");
-}
-
-memcached_return memcached_replace(memcached_st *ptr, char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags)
-{
- return memcached_send(ptr, key, key_length, value, value_length,
- expiration, flags, "replace");
-}
-
-memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_length,
- time_t expiration)
-{
- size_t send_length;
- memcached_return rc;
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-
- rc= memcached_connect(ptr);