projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
bootstrap: add arch linux
[awesomized/libmemcached]
/
libmemcached
/
io.cc
diff --git
a/libmemcached/io.cc
b/libmemcached/io.cc
index 1cd03769fadfe932fc6d69c1de8a3c3ed1168d69..e9d3ad39465b5838c8eac83cada203d46913582c 100644
(file)
--- a/
libmemcached/io.cc
+++ b/
libmemcached/io.cc
@@
-43,7
+43,7
@@
# include <sys/socket.h>
#endif
# include <sys/socket.h>
#endif
-void initialize_binary_request(
org::libmemcached::Instance
* server, protocol_binary_request_header& header)
+void initialize_binary_request(
memcached_instance_st
* server, protocol_binary_request_header& header)
{
server->request_id++;
header.request.magic= PROTOCOL_BINARY_REQ;
{
server->request_id++;
header.request.magic= PROTOCOL_BINARY_REQ;
@@
-61,7
+61,7
@@
enum memc_read_or_write {
*
* @param instance the server to pack
*/
*
* @param instance the server to pack
*/
-static bool repack_input_buffer(
org::libmemcached::Instance
* instance)
+static bool repack_input_buffer(
memcached_instance_st
* instance)
{
if (instance->read_ptr != instance->read_buffer)
{
{
if (instance->read_ptr != instance->read_buffer)
{
@@
-99,7
+99,7
@@
static bool repack_input_buffer(org::libmemcached::Instance* instance)
case EWOULDBLOCK:
#endif
case EAGAIN:
case EWOULDBLOCK:
#endif
case EAGAIN:
-#ifdef
TARGET_OS_LINUX
+#ifdef
__linux
case ERESTART:
#endif
break; // No IO is fine, we can just move on
case ERESTART:
#endif
break; // No IO is fine, we can just move on
@@
-134,7
+134,7
@@
static bool repack_input_buffer(org::libmemcached::Instance* instance)
* @param instance the server to star processing iput messages for
* @return true if we processed anything, false otherwise
*/
* @param instance the server to star processing iput messages for
* @return true if we processed anything, false otherwise
*/
-static bool process_input_buffer(
org::libmemcached::Instance
* instance)
+static bool process_input_buffer(
memcached_instance_st
* instance)
{
/*
** We might be able to process some of the response messages if we
{
/*
** We might be able to process some of the response messages if we
@@
-176,8
+176,8
@@
static bool process_input_buffer(org::libmemcached::Instance* instance)
return false;
}
return false;
}
-static memcached_return_t io_wait(
org::libmemcached::Instance
* instance,
- const
memc_read_or_write read_or_write
)
+static memcached_return_t io_wait(
memcached_instance_st
* instance,
+ const
short events
)
{
/*
** We are going to block on write, but at least on Solaris we might block
{
/*
** We are going to block on write, but at least on Solaris we might block
@@
-187,7
+187,7
@@
static memcached_return_t io_wait(org::libmemcached::Instance* instance,
** The test is moved down in the purge function to avoid duplication of
** the test.
*/
** The test is moved down in the purge function to avoid duplication of
** the test.
*/
- if (
read_or_write == MEM_WRITE
)
+ if (
events & POLLOUT
)
{
if (memcached_purge(instance) == false)
{
{
if (memcached_purge(instance) == false)
{
@@
-197,12
+197,11
@@
static memcached_return_t io_wait(org::libmemcached::Instance* instance,
struct pollfd fds;
fds.fd= instance->fd;
struct pollfd fds;
fds.fd= instance->fd;
- fds.events=
POLLIN
;
+ fds.events=
events
;
fds.revents= 0;
fds.revents= 0;
- if (
read_or_write == MEM_WRITE
) /* write */
+ if (
fds.events & POLLOUT
) /* write */
{
{
- fds.events= POLLOUT;
instance->io_wait_count.write++;
}
else
instance->io_wait_count.write++;
}
else
@@
-265,7
+264,7
@@
static memcached_return_t io_wait(org::libmemcached::Instance* instance,
assert_msg(active_fd == -1 , "poll() returned an unexpected value");
switch (local_errno)
{
assert_msg(active_fd == -1 , "poll() returned an unexpected value");
switch (local_errno)
{
-#ifdef
TARGET_OS_LINUX
+#ifdef
__linux
case ERESTART:
#endif
case EINTR:
case ERESTART:
#endif
case EINTR:
@@
-296,7
+295,7
@@
static memcached_return_t io_wait(org::libmemcached::Instance* instance,
memcached_literal_param("number of attempts to call io_wait() failed"));
}
memcached_literal_param("number of attempts to call io_wait() failed"));
}
-static bool io_flush(
org::libmemcached::Instance
* instance,
+static bool io_flush(
memcached_instance_st
* instance,
const bool with_flush,
memcached_return_t& error)
{
const bool with_flush,
memcached_return_t& error)
{
@@
-343,6
+342,7
@@
static bool io_flush(org::libmemcached::Instance* instance,
}
ssize_t sent_length= ::send(instance->fd, local_write_ptr, write_length, flags);
}
ssize_t sent_length= ::send(instance->fd, local_write_ptr, write_length, flags);
+ int local_errno= get_socket_errno(); // We cache in case memcached_quit_server() modifies errno
if (sent_length == SOCKET_ERROR)
{
if (sent_length == SOCKET_ERROR)
{
@@
-371,7
+371,7
@@
static bool io_flush(org::libmemcached::Instance* instance,
continue;
}
continue;
}
- memcached_return_t rc= io_wait(instance,
MEM_WRITE
);
+ memcached_return_t rc= io_wait(instance,
POLLOUT
);
if (memcached_success(rc))
{
continue;
if (memcached_success(rc))
{
continue;
@@
-382,14
+382,14
@@
static bool io_flush(org::libmemcached::Instance* instance,
}
memcached_quit_server(instance, true);
}
memcached_quit_server(instance, true);
- error= memcached_set_errno(*instance,
get_socket_errno()
, MEMCACHED_AT);
+ error= memcached_set_errno(*instance,
local_errno
, MEMCACHED_AT);
return false;
}
case ENOTCONN:
case EPIPE:
default:
memcached_quit_server(instance, true);
return false;
}
case ENOTCONN:
case EPIPE:
default:
memcached_quit_server(instance, true);
- error= memcached_set_errno(*instance,
get_socket_errno()
, MEMCACHED_AT);
+ error= memcached_set_errno(*instance,
local_errno
, MEMCACHED_AT);
WATCHPOINT_ASSERT(instance->fd == INVALID_SOCKET);
return false;
}
WATCHPOINT_ASSERT(instance->fd == INVALID_SOCKET);
return false;
}
@@
-407,17
+407,24
@@
static bool io_flush(org::libmemcached::Instance* instance,
return true;
}
return true;
}
-memcached_return_t memcached_io_wait_for_write(org::libmemcached::Instance* instance)
+memcached_return_t memcached_io_wait_for_write(memcached_instance_st* instance)
+{
+ return io_wait(instance, POLLOUT);
+}
+
+memcached_return_t memcached_io_wait_for_read(memcached_instance_st* instance)
{
{
- return io_wait(instance,
MEM_WRITE
);
+ return io_wait(instance,
POLLIN
);
}
}
-static memcached_return_t _io_fill(
org::libmemcached::Instance
* instance)
+static memcached_return_t _io_fill(
memcached_instance_st
* instance)
{
ssize_t data_read;
do
{
data_read= ::recv(instance->fd, instance->read_buffer, MEMCACHED_MAX_BUFFER, MSG_NOSIGNAL);
{
ssize_t data_read;
do
{
data_read= ::recv(instance->fd, instance->read_buffer, MEMCACHED_MAX_BUFFER, MSG_NOSIGNAL);
+ int local_errno= get_socket_errno(); // We cache in case memcached_quit_server() modifies errno
+
if (data_read == SOCKET_ERROR)
{
switch (get_socket_errno())
if (data_read == SOCKET_ERROR)
{
switch (get_socket_errno())
@@
-430,12
+437,12
@@
static memcached_return_t _io_fill(org::libmemcached::Instance* instance)
case EWOULDBLOCK:
#endif
case EAGAIN:
case EWOULDBLOCK:
#endif
case EAGAIN:
-#ifdef
TARGET_OS_LINUX
+#ifdef
__linux
case ERESTART:
#endif
{
memcached_return_t io_wait_ret;
case ERESTART:
#endif
{
memcached_return_t io_wait_ret;
- if (memcached_success(io_wait_ret= io_wait(instance,
MEM_READ
)))
+ if (memcached_success(io_wait_ret= io_wait(instance,
POLLIN
)))
{
continue;
}
{
continue;
}
@@
-456,7
+463,7
@@
static memcached_return_t _io_fill(org::libmemcached::Instance* instance)
case ECONNREFUSED:
default:
memcached_quit_server(instance, true);
case ECONNREFUSED:
default:
memcached_quit_server(instance, true);
- memcached_set_errno(*instance,
get_socket_errno()
, MEMCACHED_AT);
+ memcached_set_errno(*instance,
local_errno
, MEMCACHED_AT);
break;
}
break;
}
@@
-488,7
+495,7
@@
static memcached_return_t _io_fill(org::libmemcached::Instance* instance)
return MEMCACHED_SUCCESS;
}
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_read(
org::libmemcached::Instance
* instance,
+memcached_return_t memcached_io_read(
memcached_instance_st
* instance,
void *buffer, size_t length, ssize_t& nread)
{
assert(memcached_is_udp(instance->root) == false);
void *buffer, size_t length, ssize_t& nread)
{
assert(memcached_is_udp(instance->root) == false);
@@
-540,7
+547,7
@@
memcached_return_t memcached_io_read(org::libmemcached::Instance* instance,
return MEMCACHED_SUCCESS;
}
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_slurp(
org::libmemcached::Instance
* instance)
+memcached_return_t memcached_io_slurp(
memcached_instance_st
* instance)
{
assert_msg(instance, "Programmer error, invalid Instance");
assert(memcached_is_udp(instance->root) == false);
{
assert_msg(instance, "Programmer error, invalid Instance");
assert(memcached_is_udp(instance->root) == false);
@@
-568,10
+575,10
@@
memcached_return_t memcached_io_slurp(org::libmemcached::Instance* instance)
case EWOULDBLOCK:
#endif
case EAGAIN:
case EWOULDBLOCK:
#endif
case EAGAIN:
-#ifdef
TARGET_OS_LINUX
+#ifdef
__linux
case ERESTART:
#endif
case ERESTART:
#endif
- if (memcached_success(io_wait(instance,
MEM_READ
)))
+ if (memcached_success(io_wait(instance,
POLLIN
)))
{
continue;
}
{
continue;
}
@@
-597,7
+604,7
@@
memcached_return_t memcached_io_slurp(org::libmemcached::Instance* instance)
return MEMCACHED_CONNECTION_FAILURE;
}
return MEMCACHED_CONNECTION_FAILURE;
}
-static bool _io_write(
org::libmemcached::Instance
* instance,
+static bool _io_write(
memcached_instance_st
* instance,
const void *buffer, size_t length, bool with_flush,
size_t& written)
{
const void *buffer, size_t length, bool with_flush,
size_t& written)
{
@@
-650,13
+657,13
@@
static bool _io_write(org::libmemcached::Instance* instance,
return true;
}
return true;
}
-bool memcached_io_write(
org::libmemcached::Instance
* instance)
+bool memcached_io_write(
memcached_instance_st
* instance)
{
size_t written;
return _io_write(instance, NULL, 0, true, written);
}
{
size_t written;
return _io_write(instance, NULL, 0, true, written);
}
-ssize_t memcached_io_write(
org::libmemcached::Instance
* instance,
+ssize_t memcached_io_write(
memcached_instance_st
* instance,
const void *buffer, const size_t length, const bool with_flush)
{
size_t written;
const void *buffer, const size_t length, const bool with_flush)
{
size_t written;
@@
-669,7
+676,7
@@
ssize_t memcached_io_write(org::libmemcached::Instance* instance,
return ssize_t(written);
}
return ssize_t(written);
}
-bool memcached_io_writev(
org::libmemcached::Instance
* instance,
+bool memcached_io_writev(
memcached_instance_st
* instance,
libmemcached_io_vector_st vector[],
const size_t number_of, const bool with_flush)
{
libmemcached_io_vector_st vector[],
const size_t number_of, const bool with_flush)
{
@@
-701,7
+708,7
@@
bool memcached_io_writev(org::libmemcached::Instance* instance,
return (complete_total == total);
}
return (complete_total == total);
}
-void
org::libmemcached::Instance
::start_close_socket()
+void
memcached_instance_st
::start_close_socket()
{
if (fd != INVALID_SOCKET)
{
{
if (fd != INVALID_SOCKET)
{
@@
-710,7
+717,7
@@
void org::libmemcached::Instance::start_close_socket()
}
}
}
}
-void
org::libmemcached::Instance
::reset_socket()
+void
memcached_instance_st
::reset_socket()
{
if (fd != INVALID_SOCKET)
{
{
if (fd != INVALID_SOCKET)
{
@@
-719,7
+726,7
@@
void org::libmemcached::Instance::reset_socket()
}
}
}
}
-void
org::libmemcached::Instance
::close_socket()
+void
memcached_instance_st
::close_socket()
{
if (fd != INVALID_SOCKET)
{
{
if (fd != INVALID_SOCKET)
{
@@
-755,7
+762,7
@@
void org::libmemcached::Instance::close_socket()
major_version= minor_version= micro_version= UINT8_MAX;
}
major_version= minor_version= micro_version= UINT8_MAX;
}
-
org::libmemcached::Instance
* memcached_io_get_readable_server(Memcached *memc, memcached_return_t&)
+
memcached_instance_st
* memcached_io_get_readable_server(Memcached *memc, memcached_return_t&)
{
#define MAX_SERVERS_TO_POLL 100
struct pollfd fds[MAX_SERVERS_TO_POLL];
{
#define MAX_SERVERS_TO_POLL 100
struct pollfd fds[MAX_SERVERS_TO_POLL];
@@
-763,7
+770,7
@@
org::libmemcached::Instance* memcached_io_get_readable_server(Memcached *memc, m
for (uint32_t x= 0; x < memcached_server_count(memc) and host_index < MAX_SERVERS_TO_POLL; ++x)
{
for (uint32_t x= 0; x < memcached_server_count(memc) and host_index < MAX_SERVERS_TO_POLL; ++x)
{
-
org::libmemcached::Instance
* instance= memcached_instance_fetch(memc, x);
+
memcached_instance_st
* instance= memcached_instance_fetch(memc, x);
if (instance->read_buffer_length > 0) /* I have data in the buffer */
{
if (instance->read_buffer_length > 0) /* I have data in the buffer */
{
@@
-784,7
+791,7
@@
org::libmemcached::Instance* memcached_io_get_readable_server(Memcached *memc, m
/* We have 0 or 1 server with pending events.. */
for (uint32_t x= 0; x< memcached_server_count(memc); ++x)
{
/* We have 0 or 1 server with pending events.. */
for (uint32_t x= 0; x< memcached_server_count(memc); ++x)
{
-
org::libmemcached::Instance
* instance= memcached_instance_fetch(memc, x);
+
memcached_instance_st
* instance= memcached_instance_fetch(memc, x);
if (instance->response_count() > 0)
{
if (instance->response_count() > 0)
{
@@
-811,7
+818,7
@@
org::libmemcached::Instance* memcached_io_get_readable_server(Memcached *memc, m
{
for (uint32_t y= 0; y < memcached_server_count(memc); ++y)
{
{
for (uint32_t y= 0; y < memcached_server_count(memc); ++y)
{
-
org::libmemcached::Instance
* instance= memcached_instance_fetch(memc, y);
+
memcached_instance_st
* instance= memcached_instance_fetch(memc, y);
if (instance->fd == fds[x].fd)
{
if (instance->fd == fds[x].fd)
{
@@
-828,7
+835,7
@@
org::libmemcached::Instance* memcached_io_get_readable_server(Memcached *memc, m
/*
Eventually we will just kill off the server with the problem.
*/
/*
Eventually we will just kill off the server with the problem.
*/
-void memcached_io_reset(
org::libmemcached::Instance
* instance)
+void memcached_io_reset(
memcached_instance_st
* instance)
{
memcached_quit_server(instance, true);
}
{
memcached_quit_server(instance, true);
}
@@
-837,7
+844,7
@@
void memcached_io_reset(org::libmemcached::Instance* instance)
* Read a given number of bytes from the server and place it into a specific
* buffer. Reset the IO channel on this server if an error occurs.
*/
* Read a given number of bytes from the server and place it into a specific
* buffer. Reset the IO channel on this server if an error occurs.
*/
-memcached_return_t memcached_safe_read(
org::libmemcached::Instance
* instance,
+memcached_return_t memcached_safe_read(
memcached_instance_st
* instance,
void *dta,
const size_t size)
{
void *dta,
const size_t size)
{
@@
-862,7
+869,7
@@
memcached_return_t memcached_safe_read(org::libmemcached::Instance* instance,
return MEMCACHED_SUCCESS;
}
return MEMCACHED_SUCCESS;
}
-memcached_return_t memcached_io_readline(
org::libmemcached::Instance
* instance,
+memcached_return_t memcached_io_readline(
memcached_instance_st
* instance,
char *buffer_ptr,
size_t size,
size_t& total_nr)
char *buffer_ptr,
size_t size,
size_t& total_nr)