const char *hostname, unsigned int port, uint32_t weight,
memcached_connection type);
+memcached_return memcached_purge(memcached_server_st *ptr);
+
#endif /* __COMMON_H__ */
};
struct memcached_st {
+ uint8_t purging;
memcached_allocated is_allocated;
memcached_server_st *hosts;
uint32_t number_of_hosts;
uint32_t server_failure_limit;
uint32_t io_msg_watermark;
uint32_t io_bytes_watermark;
- char purging;
};
static memcached_return set_socket_options(memcached_server_st *ptr)
{
+ WATCHPOINT_ASSERT(ptr->fd != -1);
+
if (ptr->type == MEMCACHED_CONNECTION_UDP)
return MEMCACHED_SUCCESS;
}
}
}
+
+ WATCHPOINT_ASSERT(ptr->fd != -1);
return MEMCACHED_SUCCESS;
}
fds[0].fd= ptr->fd;
fds[0].events= flags;
+#ifdef NOT_DONE
/*
** We are going to block on write, but at least on Solaris we might block
** on write if we haven't read anything from our input buffer..
** the test.
*/
if (read_or_write == MEM_WRITE)
- memcached_purge(ptr);
+ {
+ if (memcached_purge(ptr) != MEMCACHED_SUCCESS || memcached_purge(ptr) != MEMCACHED_STORED)
+ return MEMCACHED_FAILURE;
+ }
+#endif
error= poll(fds, 1, ptr->root->poll_timeout);
size_t original_length;
const char* buffer_ptr;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
+
original_length= length;
buffer_ptr= buffer;
memcached_return rc;
ssize_t sent_length;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
sent_length= io_flush(ptr, &rc);
if (sent_length == -1)
return -1;
if (with_flush)
{
memcached_return rc;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
if (io_flush(ptr, &rc) == -1)
return -1;
}
*error= MEMCACHED_SUCCESS;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
+
if (ptr->write_buffer_offset == 0)
return 0;
return_length= 0;
while (write_length)
{
+ WATCHPOINT_ASSERT(ptr->fd != -1);
WATCHPOINT_ASSERT(write_length > 0);
sent_length= 0;
if (ptr->type == MEMCACHED_CONNECTION_UDP)
}
else
{
+#ifdef NOT_DONE
/*
** We might want to purge the input buffer if we haven't consumed
** any output yet... The test for the limits is the purge is inline
** in the purge function to avoid duplicating the logic..
*/
- memcached_purge(ptr);
+ {
+ memcached_return rc;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
+ rc= memcached_purge(ptr);
+
+ if (rc != MEMCACHED_SUCCESS || rc != MEMCACHED_STORED)
+ return -1;
+ }
+#endif
+ WATCHPOINT_ASSERT(ptr->fd != -1);
if ((sent_length= write(ptr->fd, local_write_ptr,
- write_length)) == -1)
+ write_length)) == -1)
{
switch (errno)
{
ssize_t memcached_io_read(memcached_server_st *ptr,
void *buffer, size_t length);
memcached_return memcached_io_close(memcached_server_st *ptr);
-void memcached_purge(memcached_server_st *ptr);
#endif /* __MEMCACHED_IO_H__ */
#include "common.h"
#include "memcached_io.h"
-void memcached_purge(memcached_server_st *ptr)
+memcached_return memcached_purge(memcached_server_st *ptr)
{
+ memcached_return rc;
int32_t timeout;
char buffer[2048];
memcached_result_st result;
+ memcached_result_st *result_ptr;
if (ptr->root->purging || /* already purging */
(memcached_server_response_count(ptr) < ptr->root->io_msg_watermark &&
(ptr->io_bytes_sent > ptr->root->io_bytes_watermark &&
memcached_server_response_count(ptr) < 10))
{
- return;
+ return MEMCACHED_SUCCESS;
}
/* memcached_io_write and memcached_response may call memcached_purge
so we need to be able stop any recursion.. */
ptr->root->purging= 1;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
/* Force a flush of the buffer to ensure that we don't have the n-1 pending
requests buffered up.. */
- memcached_io_write(ptr, NULL, 0, 1);
+ if (memcached_io_write(ptr, NULL, 0, 1) == -1)
+ return MEMCACHED_FAILURE;
+ WATCHPOINT_ASSERT(ptr->fd != -1);
/* we have already incremented the response counter, and memcached_response
will read out all messages.. To avoid memcached_response to wait forever
timeout if there is no data yet */
timeout= ptr->root->poll_timeout;
ptr->root->poll_timeout= 1;
- memcached_response(ptr, buffer, sizeof(buffer), &result);
+ result_ptr= memcached_result_create(ptr->root, &result);
+
+ if (result_ptr == NULL)
+ return MEMCACHED_FAILURE;
+
+ WATCHPOINT_ASSERT(ptr->fd != -1);
+ rc= memcached_response(ptr, buffer, sizeof(buffer), &result);
+ WATCHPOINT_ERROR(rc);
+ WATCHPOINT_ASSERT(ptr->fd != -1);
ptr->root->poll_timeout= timeout;
memcached_server_response_increment(ptr);
ptr->root->purging = 0;
+
+ memcached_result_free(&result);
+
+ return rc;
}