-void memcached_server_add(memcached_st *ptr, char *server_name, unsigned int port)
-{
-}
-
-static memcached_return memcached_connect(memcached_st *ptr)
-{
- int rc;
- struct sockaddr_in localAddr, servAddr;
- struct hostent *h;
- char *server_name= "localhost";
-
- if (ptr->connected)
- return MEMCACHED_SUCCESS;
-
-
- if ((h= gethostbyname(server_name)) == NULL)
- {
- fprintf(stderr, "unknown host '%s'\n", server_name);
- return MEMCACHED_HOST_LOCKUP_FAILURE;
- }
-
- servAddr.sin_family= h->h_addrtype;
- memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
- servAddr.sin_port = htons(MEMCACHED_DEFAULT_PORT);
-
- /* Create the socket */
- if ((ptr->fd= socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- fprintf(stderr, "cannot open socket");
- return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
- }
-
-
- /* bind any port number */
- localAddr.sin_family = AF_INET;
- localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
- localAddr.sin_port = htons(0);
-
- if (bind(ptr->fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0)
- {
- fprintf(stderr, "cannot bind port TCP %u\n", MEMCACHED_DEFAULT_PORT);
- return(MEMCACHED_CONNECTION_BIND_FAILURE);
- }
-
- /* connect to server */
- if (connect(ptr->fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
- {
- fprintf(stderr, "cannot connect to host '%s'\n", server_name);
- return MEMCACHED_HOST_LOCKUP_FAILURE;
- }
-
- ptr->connected= 1;
-
- return MEMCACHED_SUCCESS;
-}
-
-static memcached_return memcached_response(memcached_st *ptr,
- char *buffer, size_t buffer_length)
-{
- size_t send_length;
- send_length= read(ptr->fd, buffer, buffer_length);
-
- /* This should never happen, if it does it means that key must now be quite large. */
- assert(send_length != buffer_length);
-
- if (send_length)
- switch(buffer[0])
- {
- 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);
-
- if (expiration)
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s %u\r\n", key_length, key, expiration);
- else
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s\r\n", key_length, key);
- if ((write(ptr->fd, buffer, send_length) == -1))
- {
- fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
-}
-
-memcached_return memcached_increment(memcached_st *ptr, char *key, size_t key_length,
- unsigned int count)
-{
- return MEMCACHED_SUCCESS;
-}
-
-memcached_return memcached_decrement(memcached_st *ptr, char *key, size_t key_length,
- unsigned int count)
-{
- return MEMCACHED_SUCCESS;
-}
-
-memcached_return memcached_stat(memcached_st *ptr, memcached_stat_st *stat)
-{
- 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,
- "stats \r\n");
- if ((send(ptr->fd, buffer, send_length, 0) == -1))
- {
- fprintf(stderr, "failed on stats\n");
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- while((send_length= read(ptr->fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE)) > 0)
- {
- if (send_length && buffer[0] == 'D') /* DELETED */
- return MEMCACHED_SUCCESS;
- else if (send_length && buffer[0] == 'N') /* NOT FOUND */
- return MEMCACHED_NOTFOUND;
- else if (send_length && buffer[0] == 'E') /* PROTOCOL ERROR */
- return MEMCACHED_PROTOCOL_ERROR;
- else if (send_length && buffer[0] == 'C') /* CLIENT ERROR */
- return MEMCACHED_CLIENT_ERROR;
- else if (send_length && buffer[0] == 'S') /* SERVER ERROR */
- return MEMCACHED_SERVER_ERROR;
- else if (send_length) /* UNKNOWN READ FAILURE */
- {
- fprintf(stderr, "UNKNOWN %.*s\n", send_length, buffer);
- return MEMCACHED_UNKNOWN_READ_FAILURE;
- }
- else
- return MEMCACHED_READ_FAILURE;
- }
-}
-
-memcached_return memcached_flush(memcached_st *ptr, time_t expiration)
-{
- size_t send_length;
- memcached_return rc;
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-
- rc= memcached_connect(ptr);
-
- if (expiration)
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "flush_all %u\r\n", expiration);
- else
- send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "flush_all\r\n");
- if ((send(ptr->fd, buffer, send_length, 0) == -1))
- {
- fprintf(stderr, "failed flush_all TCP\n");
-
- return MEMCACHED_WRITE_FAILURE;
- }
-
- return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
-}
-
-char *memcached_version(memcached_st *ptr, memcached_return *error)
-{
- return MEMCACHED_SUCCESS;
-}
-
-memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity)
-{
- return MEMCACHED_SUCCESS;
-}
-
-memcached_return memcached_quit(memcached_st *ptr)
-{
- return MEMCACHED_SUCCESS;
-}
-
-
-char *memcached_get(memcached_st *ptr, char *key, size_t key_length,
- size_t *value_length,
- uint16_t *flags,
- memcached_return *error)