X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached_io.c;h=7ed2a403f58563f375c8cd04424308a4de86e0b3;hb=cd5188989914aa6857305ea96ecb852ebcc12b85;hp=47486d3095b799872a6943004c23821af525c7b9;hpb=8a5081c5ed9c33b1d6d5f070ba97b2b21b7a0da8;p=awesomized%2Flibmemcached diff --git a/libmemcached/memcached_io.c b/libmemcached/memcached_io.c index 47486d30..7ed2a403 100644 --- a/libmemcached/memcached_io.c +++ b/libmemcached/memcached_io.c @@ -30,6 +30,17 @@ static memcached_return io_wait(memcached_server_st *ptr, fds[0].fd= ptr->fd; fds[0].events= flags; + /* + ** 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.. + ** Try to purge the input buffer if we don't do any flow control in the + ** application layer (just sending a lot of data etc) + ** The test is moved down in the purge function to avoid duplication of + ** the test. + */ + if (read_or_write == MEM_WRITE) + memcached_purge(ptr); + error= poll(fds, 1, ptr->root->poll_timeout); if (error == 1) @@ -101,6 +112,7 @@ ssize_t memcached_io_read(memcached_server_st *ptr, switch (errno) { case EAGAIN: + case EINTR: { memcached_return rc; @@ -124,6 +136,7 @@ ssize_t memcached_io_read(memcached_server_st *ptr, } } + ptr->io_bytes_sent = 0; ptr->read_data_length= data_read; ptr->read_buffer_length= data_read; ptr->read_ptr= ptr->read_buffer; @@ -220,7 +233,10 @@ memcached_return memcached_io_close(memcached_server_st *ptr) #endif r= close(ptr->fd); - WATCHPOINT_ASSERT(r == 0); +#ifdef HAVE_DEBUG + if (r != 0) + WATCHPOINT_ERRNO(errno); +#endif return MEMCACHED_SUCCESS; } @@ -280,6 +296,13 @@ static ssize_t io_flush(memcached_server_st *ptr, } else { + /* + ** 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); + if ((sent_length= write(ptr->fd, local_write_ptr, write_length)) == -1) { @@ -307,13 +330,16 @@ static ssize_t io_flush(memcached_server_st *ptr, } } + ptr->io_bytes_sent += sent_length; + local_write_ptr+= sent_length; write_length-= sent_length; return_length+= sent_length; } WATCHPOINT_ASSERT(write_length == 0); - WATCHPOINT_ASSERT(return_length == ptr->write_buffer_offset); + // Need to study this assert() WATCHPOINT_ASSERT(return_length == + // ptr->write_buffer_offset); ptr->write_buffer_offset= 0; return return_length;