diff --git a/GNUmakefile b/GNUmakefile
index 9b06c59..0496325 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -150,6 +150,7 @@ libuhub_SOURCES := \
src/adc/message.c \
src/util/misc.c \
src/core/netevent.c \
+ src/network/connection.c \
src/network/network.c \
src/util/rbtree.c \
src/core/route.c \
@@ -181,6 +182,7 @@ uhub_HEADERS := \
src/adc/message.h \
src/util/misc.h \
src/core/netevent.h \
+ src/network/connection.h \
src/network/network.h \
src/util/rbtree.h \
src/core/route.h \
diff --git a/src/network/connection.c b/src/network/connection.c
new file mode 100644
index 0000000..8194a93
--- /dev/null
+++ b/src/network/connection.c
@@ -0,0 +1,51 @@
+/*
+ * uhub - A tiny ADC p2p connection hub
+ * Copyright (C) 2007-2009, Jan Vidar Krey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include "uhub.h"
+
+extern struct hub_info* g_hub;
+
+void net_con_initialize(struct net_connection* con, int sd, const void* ptr, int events)
+{
+ con->sd = sd;
+ con->ptr = (void*) ptr;
+
+ event_set(&con->event, con->sd, events | EV_PERSIST, net_event, con->ptr);
+ event_base_set(g_hub->evbase, &con->event);
+ event_add(&con->event, 0);
+}
+
+void net_con_update(struct net_connection* con, int events)
+{
+ if (event_pending(&con->event, EV_READ | EV_WRITE, 0) == events)
+ return;
+
+ event_del(&con->event);
+ event_set(&con->event, con->sd, events | EV_PERSIST, net_event, con->ptr);
+ event_add(&con->event, 0);
+}
+
+void net_con_close(struct net_connection* con)
+{
+ if (!event_pending(&con->event, EV_READ | EV_WRITE, 0))
+ return;
+ event_del(&con->event);
+}
+
+
diff --git a/src/network/connection.h b/src/network/connection.h
new file mode 100644
index 0000000..63cde55
--- /dev/null
+++ b/src/network/connection.h
@@ -0,0 +1,41 @@
+/*
+ * uhub - A tiny ADC p2p connection hub
+ * Copyright (C) 2007-2009, Jan Vidar Krey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifndef HAVE_UHUB_NETWORK_CONNECTION_H
+#define HAVE_UHUB_NETWORK_CONNECTION_H
+
+#include "uhub.h"
+
+struct net_connection
+{
+ int sd; /** socket descriptor */
+ void* ptr; /** data pointer */
+ struct event event; /** libevent struct for read/write events */
+#ifdef SSL_SUPPORT
+ SSL* ssl; /** SSL handle */
+#endif /* SSL_SUPPORT */
+};
+
+extern void net_con_initialize(struct net_connection* con, int sd, const void* ptr, int events);
+extern void net_con_update(struct net_connection* con, int events);
+extern void net_con_close(struct net_connection* con);
+
+
+#endif /* HAVE_UHUB_NETWORK_CONNECTION_H */
+
diff --git a/src/uhub.h b/src/uhub.h
index 1a80d1c..9d25431 100644
--- a/src/uhub.h
+++ b/src/uhub.h
@@ -167,6 +167,7 @@ extern "C" {
#include "adc/sid.h"
#include "adc/message.h"
#include "network/network.h"
+#include "network/connection.h"
#include "core/auth.h"
#include "core/config.h"