From 46e703c98997618e78e4786745952ddfeef49f70 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 9 Apr 2008 11:58:53 +0000 Subject: [PATCH] libev can be used (but not multithreaded) and del fd unused. git-svn-id: file:///svn/unbound/trunk@1023 be551aaa-1e26-0410-a405-d3ace91eadb9 --- configure | 6 +++--- configure.ac | 6 +++--- doc/Changelog | 6 ++++++ services/outside_network.c | 20 +++++++++++++++++++- services/outside_network.h | 4 ++++ util/netevent.c | 2 ++ util/netevent.h | 4 ++++ 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 88ebc1299..7adf3dca2 100755 --- a/configure +++ b/configure @@ -21971,7 +21971,7 @@ echo $ECHO_N "checking for libevent... $ECHO_C" >&6; } fi done if test x_$found_libevent != x_yes; then - if test -f "$dir/event.h" -a -f "$dir/libevent.la"; then + if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then # libevent source directory { echo "$as_me:$LINENO: result: found in $thedir" >&5 echo "${ECHO_T}found in $thedir" >&6; } @@ -21987,8 +21987,8 @@ echo "${ECHO_T}found in $thedir" >&6; } cp $ev_files_o build/libevent cp $ev_files_lo build/libevent cp $ev_files_libso build/libevent/.libs - LATE_LDFLAGS="build/libevent/*.lo" - LDFLAGS="build/libevent/*.o $LDFLAGS" + LATE_LDFLAGS="build/libevent/*.lo -lm" + LDFLAGS="build/libevent/*.o $LDFLAGS -lm" else { { echo "$as_me:$LINENO: error: Cannot find the libevent library in $withval You can restart ./configure --with-libevent=no to use a builtin alternative. diff --git a/configure.ac b/configure.ac index bcd25e59f..1e38ce48f 100644 --- a/configure.ac +++ b/configure.ac @@ -520,7 +520,7 @@ if test x_$withval == x_yes -o x_$withval != x_no; then fi done if test x_$found_libevent != x_yes; then - if test -f "$dir/event.h" -a -f "$dir/libevent.la"; then + if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then # libevent source directory AC_MSG_RESULT(found in $thedir) CPPFLAGS="$CPPFLAGS -I$thedir" @@ -535,8 +535,8 @@ if test x_$withval == x_yes -o x_$withval != x_no; then cp $ev_files_o build/libevent cp $ev_files_lo build/libevent cp $ev_files_libso build/libevent/.libs - LATE_LDFLAGS="build/libevent/*.lo" - LDFLAGS="build/libevent/*.o $LDFLAGS" + LATE_LDFLAGS="build/libevent/*.lo -lm" + LDFLAGS="build/libevent/*.o $LDFLAGS -lm" else AC_MSG_ERROR([Cannot find the libevent library in $withval You can restart ./configure --with-libevent=no to use a builtin alternative. diff --git a/doc/Changelog b/doc/Changelog index 9a737b17f..d5f7ffbe3 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,9 @@ +9 April 2008: Wouter + - configure can detect libev(from its build directory) when passed + --with-libevent=/home/wouter/libev-3.2 + libev-3.2 is a little faster than libevent-1.4.3-stable (about 5%). + - unused commpoints not listed in epoll list. + 8 April 2008: Wouter - unbound tries to set the ulimit fds when started as server. if that does not work, it will scale back its requirements. diff --git a/services/outside_network.c b/services/outside_network.c index f69de0281..713c2a512 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -275,6 +275,9 @@ outnet_udp_cb(struct comm_point* c, void* arg, int error, (void)rbtree_delete(outnet->pending, p->node.key); fptr_ok(fptr_whitelist_pending_udp(p->cb)); (void)(*p->cb)(p->c, p->cb_arg, NETEVENT_NOERROR, reply_info); + p->c->inuse--; + if(p->c->inuse == 0) + comm_point_stop_listening(p->c); pending_delete(NULL, p); return 0; } @@ -367,8 +370,11 @@ make_udp_range(struct comm_point** coms, const char* ifname, } coms[done] = comm_point_create_udp(outnet->base, fd, outnet->udp_buff, outnet_udp_cb, outnet); - if(coms[done]) + if(coms[done]) { + log_assert(coms[done]->inuse == 0); + comm_point_stop_listening(coms[done]); done++; + } } return done; } @@ -409,6 +415,9 @@ pending_udp_timer_cb(void *arg) verbose(VERB_ALGO, "timeout udp"); fptr_ok(fptr_whitelist_pending_udp(p->cb)); (void)(*p->cb)(p->c, p->cb_arg, NETEVENT_TIMEOUT, NULL); + p->c->inuse--; + if(p->c->inuse == 0) + comm_point_stop_listening(p->c); pending_delete(p->outnet, p); } @@ -528,6 +537,9 @@ pending_node_del(rbnode_t* node, void* arg) { struct pending* pend = (struct pending*)node; struct outside_network* outnet = (struct outside_network*)arg; + pend->c->inuse--; + if(pend->c->inuse == 0) + comm_point_stop_listening(pend->c); pending_delete(outnet, pend); } @@ -725,6 +737,9 @@ pending_udp_query(struct outside_network* outnet, ldns_buffer* packet, pending_delete(outnet, pend); return NULL; } + if(pend->c->inuse == 0) + comm_point_start_listening(pend->c, -1, -1); + pend->c->inuse++; /* system calls to set timeout after sending UDP to make roundtrip smaller. */ @@ -916,6 +931,9 @@ serviced_delete(struct serviced_query* sq) if(sq->status == serviced_query_UDP_EDNS || sq->status == serviced_query_UDP) { struct pending* p = (struct pending*)sq->pending; + p->c->inuse--; + if(p->c->inuse == 0) + comm_point_stop_listening(p->c); pending_delete(sq->outnet, p); } else { struct waiting_tcp* p = (struct waiting_tcp*) diff --git a/services/outside_network.h b/services/outside_network.h index 7286a614c..b51fc5720 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -79,6 +79,8 @@ struct outside_network { * Each is on a different port. This is for ip4 ports. */ struct comm_point** udp4_ports; + /** number of queries open on each port */ + int* udp4_inuse; /** number of udp4 ports */ size_t num_udp4; @@ -86,6 +88,8 @@ struct outside_network { * The opened ip6 ports. */ struct comm_point** udp6_ports; + /** number of queries open on each port */ + int* udp6_inuse; /** number of udp6 ports */ size_t num_udp6; diff --git a/util/netevent.c b/util/netevent.c index 58faa39b1..4e25f8741 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -850,6 +850,7 @@ comm_point_create_udp(struct comm_base *base, int fd, ldns_buffer* buffer, c->do_not_close = 0; c->tcp_do_toggle_rw = 0; c->tcp_check_nb_connect = 0; + c->inuse = 0; c->callback = callback; c->cb_arg = callback_arg; evbits = EV_READ | EV_PERSIST; @@ -893,6 +894,7 @@ comm_point_create_udp_ancil(struct comm_base *base, int fd, c->type = comm_udp; c->tcp_do_close = 0; c->do_not_close = 0; + c->inuse = 0; c->tcp_do_toggle_rw = 0; c->tcp_check_nb_connect = 0; c->callback = callback; diff --git a/util/netevent.h b/util/netevent.h index 299044a76..2a8644a0d 100644 --- a/util/netevent.h +++ b/util/netevent.h @@ -191,6 +191,10 @@ struct comm_point { /** if set, checks for pending error from nonblocking connect() call.*/ int tcp_check_nb_connect; + /** number of queries outstanding on this socket, used by + * outside network for udp ports */ + int inuse; + /** callback when done. tcp_accept does not get called back, is NULL then. If a timeout happens, callback with timeout=1 is called. -- 2.47.2