- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
- return MEMCACHED_WRITE_FAILURE;
+ if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
+ {
+ rc= MEMCACHED_WRITE_FAILURE;
+ goto error;
+ }
+
+ to_write= (ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1;
+
+ rc= memcached_do(&ptr->hosts[server_key], buffer, send_length, to_write);
+ if (rc != MEMCACHED_SUCCESS)
+ goto error;
+
+ if ((ptr->flags & MEM_BUFFER_REQUESTS))
+ {
+ rc= MEMCACHED_BUFFERED;
+ }
+ else
+ {
+ rc= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ if (rc == MEMCACHED_DELETED)
+ rc= MEMCACHED_SUCCESS;
+ }