#include <libmemcached/common.h>
#ifdef HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
+# include <sys/socket.h>
#endif
void initialize_binary_request(org::libmemcached::Instance* server, protocol_binary_request_header& header)
*/
memcached_callback_st cb= *instance->root->callbacks;
- memcached_set_processing_input((memcached_st *)instance->root, true);
+ memcached_set_processing_input((Memcached *)instance->root, true);
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- memcached_st *root= (memcached_st *)instance->root;
+ Memcached *root= (Memcached *)instance->root;
memcached_return_t error= memcached_response(instance, buffer, sizeof(buffer), &root->result);
memcached_set_processing_input(root, false);
if (instance->root->poll_timeout == 0) // Mimic 0 causes timeout behavior (not all platforms do this)
{
- instance->io_wait_count.timeouts++;
- return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+ return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_literal_param("poll_timeout() was set to zero"));
}
size_t loop_max= 5;
if (active_fd == 0)
{
- instance->io_wait_count.timeouts++;
- return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+ return memcached_set_error(*instance, MEMCACHED_TIMEOUT, MEMCACHED_AT, memcached_literal_param("No active_fd were found"));
}
// Only an error should result in this code being called.
}
}
+void org::libmemcached::Instance::reset_socket()
+{
+ if (fd != INVALID_SOCKET)
+ {
+ (void)closesocket(fd);
+ fd= INVALID_SOCKET;
+ }
+}
+
void org::libmemcached::Instance::close_socket()
{
if (fd != INVALID_SOCKET)
{
+ int shutdown_options= SHUT_RD;
+ if (options.is_shutting_down == false)
+ {
+ shutdown_options= SHUT_RDWR;
+ }
+
/* in case of death shutdown to avoid blocking at close() */
- if (shutdown(fd, SHUT_RD) == SOCKET_ERROR and get_socket_errno() != ENOTCONN)
+ if (shutdown(fd, shutdown_options) == SOCKET_ERROR and get_socket_errno() != ENOTCONN)
{
WATCHPOINT_NUMBER(fd);
WATCHPOINT_ERRNO(get_socket_errno());
WATCHPOINT_ASSERT(get_socket_errno());
}
- if (closesocket(fd) == SOCKET_ERROR)
- {
- WATCHPOINT_ERRNO(get_socket_errno());
- }
+ reset_socket();
state= MEMCACHED_SERVER_STATE_NEW;
- fd= INVALID_SOCKET;
}
state= MEMCACHED_SERVER_STATE_NEW;
major_version= minor_version= micro_version= UINT8_MAX;
}
-org::libmemcached::Instance* memcached_io_get_readable_server(memcached_st *memc, memcached_return_t&)
+org::libmemcached::Instance* memcached_io_get_readable_server(Memcached *memc, memcached_return_t&)
{
#define MAX_SERVERS_TO_POLL 100
struct pollfd fds[MAX_SERVERS_TO_POLL];