From: Brian Aker Date: Fri, 9 Nov 2007 22:18:25 +0000 (-0800) Subject: Updating server_st to keep client buffers per server. X-Git-Tag: 0.10~21 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c1f907e3ade57bd12d08277f6b805c958f3cf581;p=awesomized%2Flibmemcached Updating server_st to keep client buffers per server. This is ground work to allow more async efforts around protocol. --- diff --git a/ChangeLog b/ChangeLog index 170f7378..1a54023a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +0.9 + * fix for when no servers are definied. + * different buffers are now kept for different connections to + speed up async efforts + 0.8 Mon Nov 5 10:40:41 PST 2007 * Adding support for CRC hash method * Adding support for UNIX sockets diff --git a/include/memcached.h b/include/memcached.h index 51c5e94e..a684a1ec 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -101,6 +101,11 @@ struct memcached_server_st { int fd; unsigned int stack_responses; unsigned int cursor_active; + char write_buffer[MEMCACHED_MAX_BUFFER]; + size_t write_buffer_offset; + char read_buffer[MEMCACHED_MAX_BUFFER]; + size_t read_buffer_length; + char *read_ptr; memcached_connection type; }; @@ -157,11 +162,6 @@ struct memcached_st { memcached_server_st *hosts; unsigned int number_of_hosts; unsigned int cursor_server; - char read_buffer[MEMCACHED_MAX_BUFFER]; - size_t read_buffer_length; - char *read_ptr; - char write_buffer[MEMCACHED_MAX_BUFFER]; - size_t write_buffer_offset; char connected; int cached_errno; unsigned long long flags; diff --git a/lib/memcached_hosts.c b/lib/memcached_hosts.c index ad0cad2e..c77e5583 100644 --- a/lib/memcached_hosts.c +++ b/lib/memcached_hosts.c @@ -15,6 +15,9 @@ static void host_reset(memcached_server_st *host, char *new_hostname, unsigned i host->port= port; host->fd= -1; host->type= type; + host->write_buffer_offset= 0; + host->read_buffer_length= 0; + host->read_ptr= host->read_buffer; } memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *list) diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 54844be4..473b8881 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -36,7 +36,7 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, while (length) { - if (!ptr->read_buffer_length) + if (!ptr->hosts[server_key].read_buffer_length) { size_t data_read; @@ -52,7 +52,7 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, } data_read= read(ptr->hosts[server_key].fd, - ptr->read_buffer, + ptr->hosts[server_key].read_buffer, MEMCACHED_MAX_BUFFER); if (data_read == -1) { @@ -72,14 +72,14 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, /* If zero, just keep looping */ } - ptr->read_buffer_length= data_read; - ptr->read_ptr= ptr->read_buffer; + ptr->hosts[server_key].read_buffer_length= data_read; + ptr->hosts[server_key].read_ptr= ptr->hosts[server_key].read_buffer; } - *buffer_ptr= *ptr->read_ptr; + *buffer_ptr= *ptr->hosts[server_key].read_ptr; length--; - ptr->read_ptr++; - ptr->read_buffer_length--; + ptr->hosts[server_key].read_ptr++; + ptr->hosts[server_key].read_buffer_length--; buffer_ptr++; } @@ -93,17 +93,17 @@ ssize_t memcached_io_write(memcached_st *ptr, unsigned int server_key, for (x= 0; x < length; x++) { - ptr->write_buffer[ptr->write_buffer_offset]= buffer[x]; - ptr->write_buffer_offset++; + ptr->hosts[server_key].write_buffer[ptr->hosts[server_key].write_buffer_offset]= buffer[x]; + ptr->hosts[server_key].write_buffer_offset++; - if (ptr->write_buffer_offset == MEMCACHED_MAX_BUFFER) + if (ptr->hosts[server_key].write_buffer_offset == MEMCACHED_MAX_BUFFER) { size_t sent_length; sent_length= memcached_io_flush(ptr, server_key); WATCHPOINT_ASSERT(sent_length == MEMCACHED_MAX_BUFFER); - ptr->write_buffer_offset= 0; + ptr->hosts[server_key].write_buffer_offset= 0; } } @@ -120,11 +120,11 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) { size_t sent_length; size_t return_length; - char *write_ptr= ptr->write_buffer; - size_t write_length= ptr->write_buffer_offset; + char *write_ptr= ptr->hosts[server_key].write_buffer; + size_t write_length= ptr->hosts[server_key].write_buffer_offset; unsigned int loop= 1; - if (ptr->write_buffer_offset == 0) + if (ptr->hosts[server_key].write_buffer_offset == 0) return 0; return_length= 0; @@ -167,8 +167,8 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) } WATCHPOINT_ASSERT(write_length == 0); - WATCHPOINT_ASSERT(return_length == ptr->write_buffer_offset); - ptr->write_buffer_offset= 0; + WATCHPOINT_ASSERT(return_length == ptr->hosts[server_key].write_buffer_offset); + ptr->hosts[server_key].write_buffer_offset= 0; return return_length; } @@ -178,6 +178,6 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) */ void memcached_io_reset(memcached_st *ptr, unsigned int server_key) { - ptr->write_buffer_offset= 0; + ptr->hosts[server_key].write_buffer_offset= 0; memcached_quit(ptr); }