libev can be used (but not multithreaded) and del fd unused.

git-svn-id: file:///svn/unbound/trunk@1023 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2008-04-09 11:58:53 +00:00
parent d26b183ba6
commit 46e703c989
7 changed files with 41 additions and 7 deletions

6
configure vendored
View file

@ -21971,7 +21971,7 @@ echo $ECHO_N "checking for libevent... $ECHO_C" >&6; }
fi fi
done done
if test x_$found_libevent != x_yes; then 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 # libevent source directory
{ echo "$as_me:$LINENO: result: found in $thedir" >&5 { echo "$as_me:$LINENO: result: found in $thedir" >&5
echo "${ECHO_T}found in $thedir" >&6; } 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_o build/libevent
cp $ev_files_lo build/libevent cp $ev_files_lo build/libevent
cp $ev_files_libso build/libevent/.libs cp $ev_files_libso build/libevent/.libs
LATE_LDFLAGS="build/libevent/*.lo" LATE_LDFLAGS="build/libevent/*.lo -lm"
LDFLAGS="build/libevent/*.o $LDFLAGS" LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
else else
{ { echo "$as_me:$LINENO: error: Cannot find the libevent library in $withval { { echo "$as_me:$LINENO: error: Cannot find the libevent library in $withval
You can restart ./configure --with-libevent=no to use a builtin alternative. You can restart ./configure --with-libevent=no to use a builtin alternative.

View file

@ -520,7 +520,7 @@ if test x_$withval == x_yes -o x_$withval != x_no; then
fi fi
done done
if test x_$found_libevent != x_yes; then 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 # libevent source directory
AC_MSG_RESULT(found in $thedir) AC_MSG_RESULT(found in $thedir)
CPPFLAGS="$CPPFLAGS -I$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_o build/libevent
cp $ev_files_lo build/libevent cp $ev_files_lo build/libevent
cp $ev_files_libso build/libevent/.libs cp $ev_files_libso build/libevent/.libs
LATE_LDFLAGS="build/libevent/*.lo" LATE_LDFLAGS="build/libevent/*.lo -lm"
LDFLAGS="build/libevent/*.o $LDFLAGS" LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
else else
AC_MSG_ERROR([Cannot find the libevent library in $withval AC_MSG_ERROR([Cannot find the libevent library in $withval
You can restart ./configure --with-libevent=no to use a builtin alternative. You can restart ./configure --with-libevent=no to use a builtin alternative.

View file

@ -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 8 April 2008: Wouter
- unbound tries to set the ulimit fds when started as server. - unbound tries to set the ulimit fds when started as server.
if that does not work, it will scale back its requirements. if that does not work, it will scale back its requirements.

View file

@ -275,6 +275,9 @@ outnet_udp_cb(struct comm_point* c, void* arg, int error,
(void)rbtree_delete(outnet->pending, p->node.key); (void)rbtree_delete(outnet->pending, p->node.key);
fptr_ok(fptr_whitelist_pending_udp(p->cb)); fptr_ok(fptr_whitelist_pending_udp(p->cb));
(void)(*p->cb)(p->c, p->cb_arg, NETEVENT_NOERROR, reply_info); (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); pending_delete(NULL, p);
return 0; return 0;
} }
@ -367,9 +370,12 @@ make_udp_range(struct comm_point** coms, const char* ifname,
} }
coms[done] = comm_point_create_udp(outnet->base, fd, coms[done] = comm_point_create_udp(outnet->base, fd,
outnet->udp_buff, outnet_udp_cb, outnet); 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++; done++;
} }
}
return done; return done;
} }
@ -409,6 +415,9 @@ pending_udp_timer_cb(void *arg)
verbose(VERB_ALGO, "timeout udp"); verbose(VERB_ALGO, "timeout udp");
fptr_ok(fptr_whitelist_pending_udp(p->cb)); fptr_ok(fptr_whitelist_pending_udp(p->cb));
(void)(*p->cb)(p->c, p->cb_arg, NETEVENT_TIMEOUT, NULL); (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); pending_delete(p->outnet, p);
} }
@ -528,6 +537,9 @@ pending_node_del(rbnode_t* node, void* arg)
{ {
struct pending* pend = (struct pending*)node; struct pending* pend = (struct pending*)node;
struct outside_network* outnet = (struct outside_network*)arg; 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); pending_delete(outnet, pend);
} }
@ -725,6 +737,9 @@ pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
pending_delete(outnet, pend); pending_delete(outnet, pend);
return NULL; 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 /* system calls to set timeout after sending UDP to make roundtrip
smaller. */ smaller. */
@ -916,6 +931,9 @@ serviced_delete(struct serviced_query* sq)
if(sq->status == serviced_query_UDP_EDNS || if(sq->status == serviced_query_UDP_EDNS ||
sq->status == serviced_query_UDP) { sq->status == serviced_query_UDP) {
struct pending* p = (struct pending*)sq->pending; 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); pending_delete(sq->outnet, p);
} else { } else {
struct waiting_tcp* p = (struct waiting_tcp*) struct waiting_tcp* p = (struct waiting_tcp*)

View file

@ -79,6 +79,8 @@ struct outside_network {
* Each is on a different port. This is for ip4 ports. * Each is on a different port. This is for ip4 ports.
*/ */
struct comm_point** udp4_ports; struct comm_point** udp4_ports;
/** number of queries open on each port */
int* udp4_inuse;
/** number of udp4 ports */ /** number of udp4 ports */
size_t num_udp4; size_t num_udp4;
@ -86,6 +88,8 @@ struct outside_network {
* The opened ip6 ports. * The opened ip6 ports.
*/ */
struct comm_point** udp6_ports; struct comm_point** udp6_ports;
/** number of queries open on each port */
int* udp6_inuse;
/** number of udp6 ports */ /** number of udp6 ports */
size_t num_udp6; size_t num_udp6;

View file

@ -850,6 +850,7 @@ comm_point_create_udp(struct comm_base *base, int fd, ldns_buffer* buffer,
c->do_not_close = 0; c->do_not_close = 0;
c->tcp_do_toggle_rw = 0; c->tcp_do_toggle_rw = 0;
c->tcp_check_nb_connect = 0; c->tcp_check_nb_connect = 0;
c->inuse = 0;
c->callback = callback; c->callback = callback;
c->cb_arg = callback_arg; c->cb_arg = callback_arg;
evbits = EV_READ | EV_PERSIST; 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->type = comm_udp;
c->tcp_do_close = 0; c->tcp_do_close = 0;
c->do_not_close = 0; c->do_not_close = 0;
c->inuse = 0;
c->tcp_do_toggle_rw = 0; c->tcp_do_toggle_rw = 0;
c->tcp_check_nb_connect = 0; c->tcp_check_nb_connect = 0;
c->callback = callback; c->callback = callback;

View file

@ -191,6 +191,10 @@ struct comm_point {
/** if set, checks for pending error from nonblocking connect() call.*/ /** if set, checks for pending error from nonblocking connect() call.*/
int tcp_check_nb_connect; int tcp_check_nb_connect;
/** number of queries outstanding on this socket, used by
* outside network for udp ports */
int inuse;
/** callback when done. /** callback when done.
tcp_accept does not get called back, is NULL then. tcp_accept does not get called back, is NULL then.
If a timeout happens, callback with timeout=1 is called. If a timeout happens, callback with timeout=1 is called.