From f757325bea76ccff1a88627f5510dc3e32ffd5e7 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 11 Dec 2007 00:11:46 -0800 Subject: [PATCH] New async test. Lingerd is now working well with fcntl() in order to get async close. --- lib/memcached_connect.c | 27 ++++++++++++++------------- lib/memcached_io.c | 13 ------------- lib/memcached_quit.c | 3 +++ tests/function.c | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index fd4518d5..e00a6301 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -136,25 +136,13 @@ static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key) return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE; } - /* For the moment, not getting a nonblocking mode will not be fatal */ - if (ptr->flags & MEM_NO_BLOCK) - { - int flags; - - flags= fcntl(ptr->hosts[server_key].fd, F_GETFL, 0); - if (flags != -1) - { - (void)fcntl(ptr->hosts[server_key].fd, F_SETFL, flags | O_NONBLOCK); - } - } - if (ptr->flags & MEM_NO_BLOCK) { int error; struct linger linger; linger.l_onoff= 1; - linger.l_linger= 400; + linger.l_linger= 65536; error= setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_LINGER, &linger, (socklen_t)sizeof(struct linger)); WATCHPOINT_ASSERT(error == 0); @@ -188,6 +176,19 @@ static memcached_return tcp_connect(memcached_st *ptr, unsigned int server_key) WATCHPOINT_ASSERT(error == 0); } + /* For the moment, not getting a nonblocking mode will not be fatal */ + if (ptr->flags & MEM_NO_BLOCK) + { + int flags; + + flags= fcntl(ptr->hosts[server_key].fd, F_GETFL, 0); + if (flags != -1) + { + (void)fcntl(ptr->hosts[server_key].fd, F_SETFL, flags | O_NONBLOCK); + } + } + + /* connect to server */ test_connect: if (connect(ptr->hosts[server_key].fd, diff --git a/lib/memcached_io.c b/lib/memcached_io.c index de3eda32..85a27d96 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -150,19 +150,6 @@ ssize_t memcached_io_write(memcached_st *ptr, unsigned int server_key, memcached_return memcached_io_close(memcached_st *ptr, unsigned int server_key) { - if (ptr->flags & MEM_NO_BLOCK && 0) - { - int sock_size; - int error; - socklen_t sock_length; - - error= getsockopt(ptr->hosts[server_key].fd, IPPROTO_TCP, SO_LINGER, - &sock_size, &sock_length); - - WATCHPOINT_NUMBER(error); - WATCHPOINT_NUMBER(sock_size); - } - close(ptr->hosts[server_key].fd); return MEMCACHED_SUCCESS; diff --git a/lib/memcached_quit.c b/lib/memcached_quit.c index 3125abad..9c77e71e 100644 --- a/lib/memcached_quit.c +++ b/lib/memcached_quit.c @@ -27,6 +27,9 @@ void memcached_quit_server(memcached_st *ptr, unsigned int server_key, uint8_t i memcached_io_close(ptr, server_key); } + else + WATCHPOINT_ASSERT(0); + ptr->hosts[server_key].fd= -1; ptr->hosts[server_key].stack_responses= 0; ptr->hosts[server_key].cursor_active= 0; diff --git a/tests/function.c b/tests/function.c index 9c57ec4d..f21cb684 100644 --- a/tests/function.c +++ b/tests/function.c @@ -341,6 +341,16 @@ uint8_t add_test(memcached_st *memc) return 0; } +uint8_t add_wrapper(memcached_st *memc) +{ + unsigned int x; + + for (x= 0; x < 10000; x++) + add_test(memc); + + return 0; +} + uint8_t replace_test(memcached_st *memc) { memcached_return rc; @@ -1930,6 +1940,11 @@ test_st tests[] ={ {0, 0, 0} }; +test_st async_tests[] ={ + {"add", 1, add_wrapper }, + {0, 0, 0} +}; + test_st string_tests[] ={ {"string static with null", 0, string_static_null }, {"string alloc with null", 0, string_alloc_null }, @@ -2001,6 +2016,7 @@ collection_st collection[] ={ {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3}, {"string", 0, 0, string_tests}, {"result", 0, 0, result_tests}, + {"async", pre_nonblock, 0, async_tests}, {"user", 0, 0, user_tests}, {"generate", 0, 0, generate_tests}, {"generate_hsieh", pre_hsieh, 0, generate_tests}, -- 2.30.2