Compare commits

...

4 Commits

Author SHA1 Message Date
Jan Vidar Krey
84e278658b Libevent changes. 2009-03-19 00:43:43 +01:00
Jan Vidar Krey
c671851be8 Cleaned up local event queue.
Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
2009-03-18 02:56:49 +01:00
Jan Vidar Krey
4f8edfe9c8 Started working on an updated libevent and event queue implementation that would not require timers.
Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
2009-03-18 02:32:00 +01:00
Jan Vidar Krey
4d0ed61a05 A first stab at creating debian packages
Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
2009-03-17 01:38:55 +01:00
27 changed files with 503 additions and 57 deletions

View File

@@ -1,3 +1,6 @@
0.2.7:
0.2.6: 0.2.6:
- Better "!uptime" command formatting. - Better "!uptime" command formatting.
- Better "!stats"; can display peak and current bandwidth usage. - Better "!stats"; can display peak and current bandwidth usage.

View File

@@ -30,8 +30,9 @@ CFLAGS += -mno-cygwin
LDFLAGS += -mno-cygwin LDFLAGS += -mno-cygwin
BIN_EXT ?= .exe BIN_EXT ?= .exe
else else
UHUB_CONF_DIR ?= /etc/uhub DESTDIR ?= /
UHUB_PREFIX ?= /usr/local UHUB_CONF_DIR ?= $(DESTDIR)/etc/uhub
UHUB_PREFIX ?= $(DESTDIR)/usr/
CFLAGS += -I/usr/local/include CFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib LDFLAGS += -L/usr/local/lib
BIN_EXT ?= BIN_EXT ?=
@@ -251,7 +252,7 @@ install: $(uhub_BINARY)
@if [ ! -d $(UHUB_CONF_DIR) ]; then echo Creating $(UHUB_CONF_DIR); mkdir -p $(UHUB_CONF_DIR); fi @if [ ! -d $(UHUB_CONF_DIR) ]; then echo Creating $(UHUB_CONF_DIR); mkdir -p $(UHUB_CONF_DIR); fi
@if [ ! -f $(UHUB_CONF_DIR)/uhub.conf ]; then cp doc/uhub.conf $(UHUB_CONF_DIR); fi @if [ ! -f $(UHUB_CONF_DIR)/uhub.conf ]; then cp doc/uhub.conf $(UHUB_CONF_DIR); fi
@if [ ! -f $(UHUB_CONF_DIR)/users.conf ]; then cp doc/users.conf $(UHUB_CONF_DIR); fi @if [ ! -f $(UHUB_CONF_DIR)/users.conf ]; then cp doc/users.conf $(UHUB_CONF_DIR); fi
@touch $(UHUB_CONF_DIR)/motd @touch $(UHUB_CONF_DIR)/motd.txt
@echo done. @echo done.
endif endif

5
debian/changelog vendored Normal file
View File

@@ -0,0 +1,5 @@
uhub (0.2.6-1) unstable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
-- Jan Vidar Krey <janvidar@extatic.org> Tue, 17 Mar 2009 00:38:12 +0100

1
debian/compat vendored Normal file
View File

@@ -0,0 +1 @@
7

3
debian/conffiles vendored Normal file
View File

@@ -0,0 +1,3 @@
etc/uhub/uhub.conf
etc/uhub/users.conf
etc/uhub/motd.txt

15
debian/control vendored Normal file
View File

@@ -0,0 +1,15 @@
Source: uhub
Section: net
Priority: extra
Maintainer: Jan Vidar Krey <janvidar@extatic.org>
Build-Depends: debhelper (>= 7)
Standards-Version: 3.8.1
Homepage: http://www.extatic.org/uhub/
Package: uhub
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: uHub is a high performance peer-to-peer hub for the ADC network.
Its low memory footprint allows it to handle several thousand users on high-end servers,
or a small private hub on embedded hardware.
uHub uses the ADC protocol, and is compatible with DC++, jUCy and other ADC clients.

9
debian/copyright vendored Normal file
View File

@@ -0,0 +1,9 @@
Copyright:
Copyright (C) 2008-2009 Jan Vidar Krey <janvidar@extatic.org>
License:
Licensed under the GPL version 3,
see `/usr/share/common-licenses/GPL-3'.

1
debian/dirs vendored Normal file
View File

@@ -0,0 +1 @@
usr/bin

3
debian/docs vendored Normal file
View File

@@ -0,0 +1,3 @@
BUGS
README
AUTHORS

1
debian/files vendored Normal file
View File

@@ -0,0 +1 @@
uhub_0.2.6-1_amd64.deb net extra

157
debian/init.d vendored Normal file
View File

@@ -0,0 +1,157 @@
#! /bin/sh
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Further changes by Javier Fernandez-Sanguino <jfs@debian.org>
#
# Version: @(#)skeleton 1.9 26-Feb-2001 miquels@cistron.nl
#
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/uhub
NAME=uhub
DESC=uhub
test -x $DAEMON || exit 0
LOGDIR=/var/log/uhub
PIDFILE=/var/run/$NAME.pid
DODTIME=1 # Time to wait for the server to die, in seconds
# If this value is set too low you might not
# let some servers to die gracefully and
# 'restart' will not work
# Include uhub defaults if available
if [ -f /etc/default/uhub ] ; then
. /etc/default/uhub
fi
set -e
running_pid()
{
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
# Is this the expected child?
[ "$cmd" != "$name" ] && return 1
return 0
}
running()
{
# Check if the process is running looking at /proc
# (works for all users)
# No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
# Obtain the pid and check it against the binary name
pid=`cat $PIDFILE`
running_pid $pid $DAEMON || return 1
return 0
}
force_stop() {
# Forcefully kill the process
[ ! -f "$PIDFILE" ] && return
if running ; then
kill -15 $pid
# Is it really dead?
[ -n "$DODTIME" ] && sleep "$DODTIME"s
if running ; then
kill -9 $pid
[ -n "$DODTIME" ] && sleep "$DODTIME"s
if running ; then
echo "Cannot kill $LABEL (pid=$pid)!"
exit 1
fi
fi
fi
rm -f $PIDFILE
return 0
}
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $DAEMON_OPTS
if running ; then
echo "$NAME."
else
echo " ERROR."
fi
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec $DAEMON
echo "$NAME."
;;
force-stop)
echo -n "Forcefully stopping $DESC: "
force_stop
if ! running ; then
echo "$NAME."
else
echo " ERROR."
fi
;;
reload)
#
# If the daemon can reload its config files on the fly
# for example by sending it SIGHUP, do it here.
#
# If the daemon responds to changes in its config file
# directly anyway, make this a do-nothing entry.
#
echo "Reloading $DESC configuration files."
start-stop-daemon --stop --signal 1 --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON
#;;
force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart" except that it does nothing if the
# daemon isn't already running.
# check wether $DAEMON is running. If so, restart
start-stop-daemon --stop --test --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON \
&& $0 restart \
|| exit 0
;;
restart)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON
[ -n "$DODTIME" ] && sleep $DODTIME
start-stop-daemon --start --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
status)
echo -n "$LABEL is "
if running ; then
echo "running"
else
echo " not running."
exit 1
fi
;;
*)
N=/etc/init.d/$NAME
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
exit 1
;;
esac
exit 0

39
debian/postinst vendored Normal file
View File

@@ -0,0 +1,39 @@
#!/bin/sh
# postinst script for uhub
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

37
debian/postrm vendored Normal file
View File

@@ -0,0 +1,37 @@
#!/bin/sh
# postrm script for uhub
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

35
debian/preinst vendored Normal file
View File

@@ -0,0 +1,35 @@
#!/bin/sh
# preinst script for uhub
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
# * <new-preinst> `upgrade' <old-version>
# * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
install|upgrade)
;;
abort-upgrade)
;;
*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

38
debian/prerm vendored Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
# prerm script for uhub
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <prerm> `remove'
# * <old-prerm> `upgrade' <new-version>
# * <new-prerm> `failed-upgrade' <old-version>
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
# * <deconfigured's-prerm> `deconfigure' `in-favour'
# <package-being-installed> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
remove|upgrade|deconfigure)
;;
failed-upgrade)
;;
*)
echo "prerm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

91
debian/rules vendored Executable file
View File

@@ -0,0 +1,91 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
configure: configure-stamp
configure-stamp:
dh_testdir
# Add here commands to configure the package.
touch configure-stamp
build: build-stamp
build-stamp: configure-stamp
dh_testdir
# Add here commands to compile the package.
$(MAKE)
#docbook-to-man debian/uhub.sgml > uhub.1
touch $@
clean:
dh_testdir
dh_testroot
rm -f build-stamp configure-stamp
# Add here commands to clean up after the build process.
$(MAKE) clean
dh_clean
install: build
dh_testdir
dh_testroot
dh_prep
dh_installdirs
# Add here commands to install the package into debian/uhub.
$(MAKE) DESTDIR=$(CURDIR)/debian/uhub install
# Build architecture-independent files here.
binary-indep: install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: install
dh_testdir
dh_testroot
dh_installchangelogs ChangeLog
dh_installdocs
dh_installexamples
# dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
# dh_python
# dh_installinit
# dh_installcron
# dh_installinfo
dh_installman
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
# dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure

10
debian/uhub.default vendored Normal file
View File

@@ -0,0 +1,10 @@
# Defaults for uhub initscript
# sourced by /etc/init.d/uhub
# installed at /etc/default/uhub by the maintainer scripts
# Additional options that are passed to the Daemon.
ENABLED=1
LOGFILE="/var/log/uhug.log"
USER=nobody
GROUP=nogroup
DAEMON_OPTS="-f -l ${LOGFILE} -u ${USER} -g {GROUP}"

View File

@@ -936,6 +936,7 @@ int main(int argc, char** argv)
parse_command_line(argc, argv); parse_command_line(argc, argv);
net_initialize(); net_initialize();
event_init();
memset(&saddr, 0, sizeof(saddr)); memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;

View File

@@ -35,9 +35,8 @@ int event_queue_initialize(struct event_queue** queue, event_queue_callback call
(*queue)->q1 = list_create(); (*queue)->q1 = list_create();
(*queue)->q2 = list_create(); (*queue)->q2 = list_create();
(*queue)->event = (struct event*) hub_malloc_zero(sizeof(struct event));
if (!(*queue)->q1 || !(*queue)->q2 || !(*queue)->event) if (!(*queue)->q1 || !(*queue)->q2)
{ {
list_destroy((*queue)->q1); list_destroy((*queue)->q1);
list_destroy((*queue)->q2); list_destroy((*queue)->q2);
@@ -47,7 +46,6 @@ int event_queue_initialize(struct event_queue** queue, event_queue_callback call
(*queue)->callback = callback; (*queue)->callback = callback;
(*queue)->callback_data = ptr; (*queue)->callback_data = ptr;
evtimer_set((*queue)->event, libevent_queue_process, *queue);
return 0; return 0;
} }
@@ -57,12 +55,6 @@ void event_queue_shutdown(struct event_queue* queue)
/* Should be empty at this point! */ /* Should be empty at this point! */
list_destroy(queue->q1); list_destroy(queue->q1);
list_destroy(queue->q2); list_destroy(queue->q2);
if (queue->event)
{
evtimer_del(queue->event);
hub_free(queue->event);
}
hub_free(queue); hub_free(queue);
} }
@@ -135,12 +127,6 @@ void event_queue_post(struct event_queue* queue, struct event_data* message)
#endif #endif
list_append(q, data); list_append(q, data);
if (!queue->locked && queue->event)
{
libevent_queue_schedule(queue);
}
} }
else else
{ {
@@ -154,19 +140,5 @@ size_t event_queue_size(struct event_queue* queue)
return list_size(queue->q1) + list_size(queue->q2); return list_size(queue->q1) + list_size(queue->q2);
} }
void libevent_queue_schedule(struct event_queue* queue)
{
struct timeval zero = { 0, };
evtimer_add(queue->event, &zero);
}
void libevent_queue_process(int fd, short events, void* arg)
{
struct event_queue* queue = (struct event_queue*) arg;
if (event_queue_process(queue))
{
libevent_queue_schedule(queue);
}
}

View File

@@ -36,7 +36,6 @@ struct event_queue
struct linked_list* q2; /* secondary, when primary is locked */ struct linked_list* q2; /* secondary, when primary is locked */
event_queue_callback callback; event_queue_callback callback;
void* callback_data; void* callback_data;
struct event* event; /* libevent handle */
}; };
extern int event_queue_initialize(struct event_queue** queue, event_queue_callback callback, void* ptr); extern int event_queue_initialize(struct event_queue** queue, event_queue_callback callback, void* ptr);
@@ -45,11 +44,5 @@ extern void event_queue_shutdown(struct event_queue* queue);
extern void event_queue_post(struct event_queue* queue, struct event_data* message); extern void event_queue_post(struct event_queue* queue, struct event_data* message);
extern size_t event_queue_size(struct event_queue* queue); extern size_t event_queue_size(struct event_queue* queue);
/**
* Only used internally with libevent.
*/
extern void libevent_queue_process(int fd, short events, void* arg);
extern void libevent_queue_schedule(struct event_queue* queue);
#endif /* HAVE_UHUB_EVENT_QUEUE_H */ #endif /* HAVE_UHUB_EVENT_QUEUE_H */

View File

@@ -479,11 +479,20 @@ struct hub_info* hub_start_service(struct hub_config* config)
net_address_to_string(AF_INET6, &((struct sockaddr_in6*) &addr)->sin6_addr, address_buf, INET6_ADDRSTRLEN); net_address_to_string(AF_INET6, &((struct sockaddr_in6*) &addr)->sin6_addr, address_buf, INET6_ADDRSTRLEN);
} }
hub->evbase = event_base_new();
if (!hub->evbase)
{
hub_log(log_error, "Unable to initialize libevent.");
hub_free(hub);
return 0;
}
hub_log(log_info, "Starting server, listening on %s:%d...", address_buf, config->server_port); hub_log(log_info, "Starting server, listening on %s:%d...", address_buf, config->server_port);
server_tcp = net_socket_create(af, SOCK_STREAM, IPPROTO_TCP); server_tcp = net_socket_create(af, SOCK_STREAM, IPPROTO_TCP);
if (server_tcp == -1) if (server_tcp == -1)
{ {
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
return 0; return 0;
} }
@@ -492,6 +501,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
server_udp = net_socket_create(af, SOCK_DGRAM, IPPROTO_UDP); server_udp = net_socket_create(af, SOCK_DGRAM, IPPROTO_UDP);
if (server_udp == -1) if (server_udp == -1)
{ {
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
return 0; return 0;
} }
@@ -500,6 +510,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
ret = net_set_reuseaddress(server_tcp, 1); ret = net_set_reuseaddress(server_tcp, 1);
if (ret == -1) if (ret == -1)
{ {
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
#ifdef ADC_UDP_OPERATION #ifdef ADC_UDP_OPERATION
@@ -512,6 +523,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
ret = net_set_reuseaddress(server_udp, 1); ret = net_set_reuseaddress(server_udp, 1);
if (ret == -1) if (ret == -1)
{ {
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
net_close(server_udp); net_close(server_udp);
@@ -523,6 +535,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
ret = net_set_nonblocking(server_tcp, 1); ret = net_set_nonblocking(server_tcp, 1);
if (ret == -1) if (ret == -1)
{ {
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
#ifdef ADC_UDP_OPERATION #ifdef ADC_UDP_OPERATION
@@ -535,6 +548,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
ret = net_set_nonblocking(server_udp, 1); ret = net_set_nonblocking(server_udp, 1);
if (ret == -1) if (ret == -1)
{ {
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
net_close(server_udp); net_close(server_udp);
@@ -547,6 +561,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
if (ret == -1) if (ret == -1)
{ {
hub_log(log_fatal, "hub_start_service(): Unable to bind to TCP local address. errno=%d, str=%s", net_error(), net_error_string(net_error())); hub_log(log_fatal, "hub_start_service(): Unable to bind to TCP local address. errno=%d, str=%s", net_error(), net_error_string(net_error()));
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
#ifdef ADC_UDP_OPERATION #ifdef ADC_UDP_OPERATION
@@ -560,6 +575,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
if (ret == -1) if (ret == -1)
{ {
hub_log(log_fatal, "hub_start_service(): Unable to bind to UDP local address. errno=%d, str=%s", net_error(), net_error_string(net_error())); hub_log(log_fatal, "hub_start_service(): Unable to bind to UDP local address. errno=%d, str=%s", net_error(), net_error_string(net_error()));
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
net_close(server_udp); net_close(server_udp);
@@ -571,6 +587,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
if (ret == -1) if (ret == -1)
{ {
hub_log(log_fatal, "hub_start_service(): Unable to listen to socket"); hub_log(log_fatal, "hub_start_service(): Unable to listen to socket");
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
net_close(server_tcp); net_close(server_tcp);
#ifdef ADC_UDP_OPERATION #ifdef ADC_UDP_OPERATION
@@ -597,6 +614,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
} }
event_set(&hub->ev_accept, hub->fd_tcp, EV_READ | EV_PERSIST, net_on_accept, hub); event_set(&hub->ev_accept, hub->fd_tcp, EV_READ | EV_PERSIST, net_on_accept, hub);
event_base_set(hub->evbase, &hub->ev_accept);
if (event_add(&hub->ev_accept, NULL) == -1) if (event_add(&hub->ev_accept, NULL) == -1)
{ {
user_manager_shutdown(hub); user_manager_shutdown(hub);
@@ -610,6 +628,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
#ifdef ADC_UDP_OPERATION #ifdef ADC_UDP_OPERATION
event_set(&hub->ev_datagram, hub->fd_udp, EV_READ | EV_PERSIST, net_on_packet, hub); event_set(&hub->ev_datagram, hub->fd_udp, EV_READ | EV_PERSIST, net_on_packet, hub);
event_base_set(hub->evbase, &hub->ev_datagram);
if (event_add(&hub->ev_datagram, NULL) == -1) if (event_add(&hub->ev_datagram, NULL) == -1)
{ {
user_manager_shutdown(hub); user_manager_shutdown(hub);
@@ -650,6 +669,7 @@ void hub_shutdown_service(struct hub_info* hub)
net_close(hub->fd_tcp); net_close(hub->fd_tcp);
user_manager_shutdown(hub); user_manager_shutdown(hub);
hub->status = hub_status_stopped; hub->status = hub_status_stopped;
event_base_free(hub->evbase);
hub_free(hub); hub_free(hub);
hub = 0; hub = 0;
} }
@@ -950,3 +970,19 @@ size_t hub_get_min_hubs_op(struct hub_info* hub)
} }
void hub_event_loop(struct hub_info* hub)
{
#if 0
event_dispatch();
#endif
int ret;
do
{
ret = event_base_loop(hub->evbase, EVLOOP_ONCE);
if (ret != 0)
break;
event_queue_process(hub->queue);
}
while (hub->status == hub_status_running);
}

View File

@@ -92,6 +92,7 @@ struct hub_info
#endif #endif
struct hub_stats stats; struct hub_stats stats;
struct event_queue* queue; struct event_queue* queue;
struct event_base* evbase;
struct hub_config* config; struct hub_config* config;
struct user_manager* users; struct user_manager* users;
struct acl_handle* acl; struct acl_handle* acl;
@@ -334,6 +335,10 @@ extern size_t hub_get_max_hubs_total(struct hub_info* hub);
*/ */
extern void hub_schedule_runslice(struct hub_info* hub); extern void hub_schedule_runslice(struct hub_info* hub);
/**
* Run event loop.
*/
extern void hub_event_loop(struct hub_info* hub);
#endif /* HAVE_UHUB_HUB_H */ #endif /* HAVE_UHUB_HUB_H */

View File

@@ -100,6 +100,7 @@ void setup_signal_handlers(struct hub_info* hub)
for (i = 0; signals[i]; i++) for (i = 0; signals[i]; i++)
{ {
signal_set(&signal_events[i], signals[i], hub_handle_signal, hub); signal_set(&signal_events[i], signals[i], hub_handle_signal, hub);
event_base_set(hub->evbase, &signal_events[i]);
if (signal_add(&signal_events[i], NULL)) if (signal_add(&signal_events[i], NULL))
{ {
hub_log(log_error, "Error setting signal handler %d", signals[i]); hub_log(log_error, "Error setting signal handler %d", signals[i]);
@@ -153,7 +154,7 @@ int main_loop()
hub_set_variables(hub, &acl); hub_set_variables(hub, &acl);
event_dispatch(); hub_event_loop(hub);
hub_free_variables(hub); hub_free_variables(hub);
acl_shutdown(&acl); acl_shutdown(&acl);

View File

@@ -291,7 +291,10 @@ void net_on_accept(int server_fd, short ev, void *arg)
event_set(user->ev_read, fd, EV_READ | EV_PERSIST, net_on_read, user); event_set(user->ev_read, fd, EV_READ | EV_PERSIST, net_on_read, user);
event_set(user->ev_write, fd, EV_WRITE, net_on_write, user); event_set(user->ev_write, fd, EV_WRITE, net_on_write, user);
event_base_set(hub->evbase, user->ev_read);
event_base_set(hub->evbase, user->ev_write);
event_add(user->ev_read, &timeout); event_add(user->ev_read, &timeout);
} }
} }

View File

@@ -23,7 +23,6 @@ static int is_ipv6_supported = -1; /* -1 = CHECK, 0 = NO, 1 = YES */
static int net_initialized = 0; static int net_initialized = 0;
static struct net_statistics stats; static struct net_statistics stats;
static struct net_statistics stats_total; static struct net_statistics stats_total;
static struct event_base* evbase;
#if defined(IPV6_BINDV6ONLY) #if defined(IPV6_BINDV6ONLY)
#define SOCK_DUAL_STACK_OPT IPV6_BINDV6ONLY #define SOCK_DUAL_STACK_OPT IPV6_BINDV6ONLY
@@ -53,16 +52,6 @@ int net_initialize()
/* FIXME: Initialize OpenSSL here. */ /* FIXME: Initialize OpenSSL here. */
#endif /* SSL_SUPPORT */ #endif /* SSL_SUPPORT */
#ifdef OLD_LIBEVENT
event_init();
#else
evbase = event_init();
if (!evbase)
{
hub_log(log_error, "Unable to initialize libevent.");
return -1;
}
#endif
net_initialized = 1; net_initialized = 1;
return 0; return 0;
} }
@@ -80,11 +69,6 @@ int net_shutdown()
/* FIXME: Shutdown OpenSSL here. */ /* FIXME: Shutdown OpenSSL here. */
#endif #endif
#ifndef OLD_LIBEVENT
event_base_free(evbase);
#endif
evbase = 0;
#ifdef WINSOCK #ifdef WINSOCK
WSACleanup(); WSACleanup();
#endif #endif

View File

@@ -74,6 +74,7 @@ static void timer_statistics(int fd, short ev, void *arg)
struct timeval timeout = { TIMEOUT_STATS, 0 }; struct timeval timeout = { TIMEOUT_STATS, 0 };
user_manager_update_stats(hub); user_manager_update_stats(hub);
evtimer_set(&hub->ev_timer, timer_statistics, hub); evtimer_set(&hub->ev_timer, timer_statistics, hub);
event_base_set(hub->evbase, &hub->ev_timer);
evtimer_add(&hub->ev_timer, &timeout); evtimer_add(&hub->ev_timer, &timeout);
} }
@@ -97,6 +98,7 @@ int user_manager_init(struct hub_info* hub)
hub->users = users; hub->users = users;
evtimer_set(&hub->ev_timer, timer_statistics, hub); evtimer_set(&hub->ev_timer, timer_statistics, hub);
event_base_set(hub->evbase, &hub->ev_timer);
evtimer_add(&hub->ev_timer, &timeout); evtimer_add(&hub->ev_timer, &timeout);
return 0; return 0;
} }

View File

@@ -7,7 +7,7 @@
#endif #endif
#ifndef VERSION #ifndef VERSION
#define VERSION "0.2.6" #define VERSION "0.2.7-alpha"
#endif #endif
#ifndef COPYRIGHT #ifndef COPYRIGHT