- return MEMCACHED_WRITE_FAILURE;
- if ((sent_length= send(ptr->hosts[server_key].fd, buffer, write_length, 0)) == -1)
- return MEMCACHED_WRITE_FAILURE;
- assert(write_length == sent_length);
-
- if ((sent_length= send(ptr->hosts[server_key].fd, value, value_length, 0)) == -1)
- return MEMCACHED_WRITE_FAILURE;
- assert(value_length == sent_length);
+ {
+ rc= MEMCACHED_WRITE_FAILURE;
+ goto error;
+ }
+
+ /*
+ We have to flush after sending the command. Memcached is not smart enough
+ to just keep reading from the socket :(
+ */
+ if ((sent_length= memcached_io_write(ptr, server_key, buffer, write_length, 1)) == -1)
+ {
+ rc= MEMCACHED_WRITE_FAILURE;
+ goto error;
+ }
+
+ if ((sent_length= memcached_io_write(ptr, server_key, value, value_length, 0)) == -1)
+ {
+ rc= MEMCACHED_WRITE_FAILURE;
+ goto error;
+ }
+
+ if ((sent_length= memcached_io_write(ptr, server_key, "\r\n", 2, 1)) == -1)
+ {
+ rc= MEMCACHED_WRITE_FAILURE;
+ goto error;
+ }
+
+ if ((ptr->flags & MEM_NO_BLOCK) && verb == SET_OP)
+ {
+ rc= MEMCACHED_SUCCESS;
+ ptr->stack_responses++;
+ }
+ else
+ {
+ rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
+ }