*/
memcached_callback_st cb= *ptr->root->callbacks;
+ memcached_set_processing_input((memcached_st *)ptr->root, true);
+
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
memcached_return_t error;
+ memcached_st *root= (memcached_st *)ptr->root;
error= memcached_response(ptr, buffer, sizeof(buffer),
- &ptr->root->result);
+ &root->result);
+
+ memcached_set_processing_input(root, false);
+
if (error == MEMCACHED_SUCCESS)
{
for (unsigned int x= 0; x < cb.number_of_callback; x++)
{
- error= (*cb.callback[x])(ptr->root, &ptr->root->result, cb.context);
+ error= (*cb.callback[x])(ptr->root, &root->result, cb.context);
if (error != MEMCACHED_SUCCESS)
break;
}
return false;
}
+static inline void memcached_io_cork_push(memcached_server_st *ptr)
+{
+#ifdef CORK
+ if (ptr->root->flags.cork == false || ptr->state.is_corked)
+ return;
+
+ int enable= 1;
+ int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK,
+ &enable, (socklen_t)sizeof(int));
+ if (! err)
+ ptr->state.is_corked= true;
+
+ WATCHPOINT_ASSERT(ptr->state.is_corked == true);
+#else
+ (void)ptr;
+#endif
+}
+
+static inline void memcached_io_cork_pop(memcached_server_st *ptr)
+{
+#ifdef CORK
+ if (ptr->root->flags.cork == false || ptr->state.is_corked == false)
+ return;
+
+ int enable= 0;
+ int err= setsockopt(ptr->fd, IPPROTO_TCP, CORK,
+ &enable, (socklen_t)sizeof(int));
+ if (! err)
+ ptr->state.is_corked= false;
+
+ WATCHPOINT_ASSERT(ptr->state.is_corked == false);
+#else
+ (void)ptr;
+#endif
+}
+
#ifdef UNUSED
void memcached_io_preread(memcached_st *ptr)
{
original_length= length;
buffer_ptr= buffer;
+ /* more writable data is coming if a flush isn't required, so delay send */
+ if (! with_flush)
+ {
+ memcached_io_cork_push(ptr);
+ }
+
while (length)
{
char *write_ptr;
memcached_return_t rc;
WATCHPOINT_ASSERT(ptr->fd != -1);
if (io_flush(ptr, &rc) == -1)
+ {
return -1;
+ }
+
+ memcached_io_cork_pop(ptr);
}
return (ssize_t) original_length;
struct pollfd fds[MAX_SERVERS_TO_POLL];
unsigned int host_index= 0;
- for (unsigned int x= 0;
+ for (uint32_t x= 0;
x< memcached_server_count(memc) && host_index < MAX_SERVERS_TO_POLL;
++x)
{
- if (memc->hosts[x].read_buffer_length > 0) /* I have data in the buffer */
- return &memc->hosts[x];
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, x);
+
+ if (instance->read_buffer_length > 0) /* I have data in the buffer */
+ return instance;
- if (memcached_server_response_count(&memc->hosts[x]) > 0)
+ if (memcached_server_response_count(instance) > 0)
{
fds[host_index].events = POLLIN;
fds[host_index].revents = 0;
- fds[host_index].fd = memc->hosts[x].fd;
+ fds[host_index].fd = instance->fd;
++host_index;
}
}
if (host_index < 2)
{
/* We have 0 or 1 server with pending events.. */
- for (unsigned int x= 0; x< memcached_server_count(memc); ++x)
- if (memcached_server_response_count(&memc->hosts[x]) > 0)
- return &memc->hosts[x];
+ for (uint32_t x= 0; x< memcached_server_count(memc); ++x)
+ {
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, x);
+
+ if (memcached_server_response_count(instance) > 0)
+ {
+ return instance;
+ }
+ }
return NULL;
}
{
if (fds[x].revents & POLLIN)
{
- for (unsigned int y= 0; y < memcached_server_count(memc); ++y)
+ for (uint32_t y= 0; y < memcached_server_count(memc); ++y)
{
- if (memc->hosts[y].fd == fds[x].fd)
- return &memc->hosts[y];
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, y);
+
+ if (instance->fd == fds[x].fd)
+ return instance;
}
}
}