+#include <poll.h>
+
+typedef enum {
+ MEM_READ,
+ MEM_WRITE,
+} memc_read_or_write;
+
+static ssize_t io_flush(memcached_st *ptr, unsigned int server_key,
+ memcached_return *error);
+
+static memcached_return io_wait(memcached_st *ptr, unsigned int server_key,
+ memc_read_or_write read_or_write)
+{
+ struct pollfd fds[1];
+ short flags= 0;
+ int error;
+
+ if (read_or_write == MEM_WRITE) /* write */
+ flags= POLLOUT | POLLERR;
+ else
+ flags= POLLIN | POLLERR;
+
+ memset(&fds, 0, sizeof(struct pollfd));
+ fds[0].fd= ptr->hosts[server_key].fd;
+ fds[0].events= flags;
+
+ error= poll(fds, 1, ptr->poll_timeout);
+
+ if (error == 1)
+ return MEMCACHED_SUCCESS;
+ else if (error == 0)
+ {
+ return MEMCACHED_TIMEOUT;
+ }
+
+ WATCHPOINT;
+ /* Imposssible for anything other then -1 */
+ WATCHPOINT_ASSERT(error == -1);
+ memcached_quit_server(ptr, server_key, 1);
+
+ return MEMCACHED_FAILURE;
+
+}
+
+void memcached_io_preread(memcached_st *ptr)
+{
+ unsigned int x;
+
+ return;
+
+ for (x= 0; x < ptr->number_of_hosts; x++)
+ {
+ if (memcached_server_response_count(ptr, x) &&
+ ptr->hosts[x].read_data_length < MEMCACHED_MAX_BUFFER )
+ {
+ size_t data_read;
+
+ data_read= read(ptr->hosts[x].fd,
+ ptr->hosts[x].read_ptr + ptr->hosts[x].read_data_length,
+ MEMCACHED_MAX_BUFFER - ptr->hosts[x].read_data_length);
+ if (data_read == -1)
+ continue;
+
+ ptr->hosts[x].read_buffer_length+= data_read;
+ ptr->hosts[x].read_data_length+= data_read;
+ }
+ }
+}