X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fconnect.c;h=da72c8e379350cec1100196e2e05e66ad1eb0b66;hb=ff452398ec3114d6af77aa5d2d77f53b18d980e3;hp=36971f60aa9c86e4a19d4bf8e42bc85a47ea1aa3;hpb=e42302e08fa4d04cb21eaf7493f5f92b11169c03;p=m6w6%2Flibmemcached diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 36971f60..da72c8e3 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -111,7 +111,32 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) return MEMCACHED_FAILURE; } - if (ptr->root->send_size) + if (ptr->root->flags.tcp_keepalive) + { + int flag= 1; + int error; + + error= setsockopt(ptr->fd, SOL_SOCKET, SO_KEEPALIVE, + &flag, (socklen_t)sizeof(int)); + WATCHPOINT_ASSERT(error == 0); + if (error) + return MEMCACHED_FAILURE; + } + +#ifdef TCP_KEEPIDLE + if (ptr->root->tcp_keepidle > 0) + { + int error; + + error= setsockopt(ptr->fd, IPPROTO_TCP, TCP_KEEPIDLE, + &ptr->root->tcp_keepidle, (socklen_t)sizeof(int)); + WATCHPOINT_ASSERT(error == 0); + if (error) + return MEMCACHED_FAILURE; + } +#endif + + if (ptr->root->send_size > 0) { int error; @@ -122,7 +147,7 @@ static memcached_return_t set_socket_options(memcached_server_st *ptr) return MEMCACHED_FAILURE; } - if (ptr->root->recv_size) + if (ptr->root->recv_size > 0) { int error; @@ -313,7 +338,7 @@ static memcached_return_t network_connect(memcached_server_st *ptr) } -memcached_return_t memcached_connect(memcached_server_st *ptr) +memcached_return_t memcached_connect(memcached_server_write_instance_st ptr) { memcached_return_t rc= MEMCACHED_NO_SERVERS; LIBMEMCACHED_MEMCACHED_CONNECT_START(); @@ -335,12 +360,16 @@ memcached_return_t memcached_connect(memcached_server_st *ptr) if (curr_time.tv_sec < ptr->next_retry) { - if (memcached_behavior_get(ptr->root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS)) + memcached_st *root= (memcached_st *)ptr->root; + // @todo fix this by fixing behavior to no longer make use of + // memcached_st + if (memcached_behavior_get(root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS)) { - run_distribution(ptr->root); + run_distribution(root); } - ptr->root->last_disconnected_server = ptr; + root->last_disconnected_server = ptr; + return MEMCACHED_SERVER_MARKED_DEAD; } } @@ -364,7 +393,12 @@ memcached_return_t memcached_connect(memcached_server_st *ptr) WATCHPOINT_ASSERT(0); } - unlikely ( rc != MEMCACHED_SUCCESS) ptr->root->last_disconnected_server = ptr; + unlikely ( rc != MEMCACHED_SUCCESS) + { + //@todo create interface around last_discontected_server + memcached_st *root= (memcached_st *)ptr->root; + root->last_disconnected_server = ptr; + } LIBMEMCACHED_MEMCACHED_CONNECT_END();