From a381958b0d9477c8cc3412cb7d6eda0fba175b03 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 29 Nov 2012 21:50:05 +0100 Subject: many improvements, mainly on gg_client * when client or server disconnects, correctly inform the other party * add a reconnect mechanism for gg_client() based on timers * clean function headers * improve *_send() code * client now ignores packets from someone else than it's server --- libglouglou/libglouglou.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'libglouglou/libglouglou.h') diff --git a/libglouglou/libglouglou.h b/libglouglou/libglouglou.h index 04ee779..17be3f7 100644 --- a/libglouglou/libglouglou.h +++ b/libglouglou/libglouglou.h @@ -91,11 +91,13 @@ struct gg_packet { struct gg_user { LIST_ENTRY(gg_user) entry; int id; + int sock; struct sockaddr_in addr; char *buf[16384]; }; struct gg_server { + struct event_base *ev_base; const char *ip; int port; struct sockaddr_in addr; @@ -108,15 +110,20 @@ struct gg_server { int user_id_count; }; +enum client_status { + GG_CLIENT_STATUS_CONNECTING = 0, + GG_CLIENT_STATUS_CONNECTED = 1 +}; + struct gg_client { + struct event_base *ev_base; const char *ip; int port; struct sockaddr_in addr; struct event *ev; + struct event *ev_timer; int sock; - int status; -#define GG_CLIENT_STATUS_DISCONNECTED 0 -#define GG_CLIENT_STATUS_CONNECTED 1 + enum client_status status; int (*handle_conn)(struct gg_client *); int (*handle_packet)(struct gg_client *, struct gg_packet *); void *usrdata; @@ -141,3 +148,4 @@ void *xmalloc(size_t); void *xcalloc(size_t, size_t); void fd_nonblock(int); void addrcpy(struct sockaddr_in *, struct sockaddr_in *); +int addrcmp(struct sockaddr_in *, struct sockaddr_in *); -- cgit v1.2.3-59-g8ed1b