X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fio.c;h=6aad480510f4ce5df02fab12273ca6220a1e4cc4;hb=02fa1c85c842e175225f74b0e213a5600d4c03cf;hp=3b8943c8dc31c1c00a0f0bc0b1705cb8f150f6e8;hpb=3928e14fbe1ed17cefe9bdbbb282fb7ecf053e7a;p=m6w6%2Flibmemcached diff --git a/libmemcached/io.c b/libmemcached/io.c index 3b8943c8..6aad4805 100644 --- a/libmemcached/io.c +++ b/libmemcached/io.c @@ -127,14 +127,14 @@ static bool process_input_buffer(memcached_server_instance_st *ptr) */ memcached_callback_st cb= *ptr->root->callbacks; - ptr->root->options.is_processing_input= true; + memcached_set_processing_input(ptr->root, true); char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; memcached_return_t error; error= memcached_response(ptr, buffer, sizeof(buffer), &ptr->root->result); - ptr->root->options.is_processing_input = false; + memcached_set_processing_input(ptr->root, false); if (error == MEMCACHED_SUCCESS) { @@ -154,6 +154,42 @@ static bool process_input_buffer(memcached_server_instance_st *ptr) 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) { @@ -280,6 +316,12 @@ ssize_t memcached_io_write(memcached_server_instance_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; @@ -330,7 +372,11 @@ ssize_t memcached_io_write(memcached_server_instance_st *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;