Started working on abstracting the connection data away from the user struct.

This commit is contained in:
Jan Vidar Krey 2009-08-02 21:37:55 +02:00
parent 053fb30192
commit 653cfb285e
4 changed files with 95 additions and 0 deletions

View File

@ -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 \

51
src/network/connection.c Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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);
}

41
src/network/connection.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
#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 */

View File

@ -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"