diff options
author | Laurent Ghigonis <laurent@p1sec.com> | 2012-11-29 07:42:17 +0100 |
---|---|---|
committer | Laurent Ghigonis <laurent@p1sec.com> | 2012-11-29 07:42:17 +0100 |
commit | 18274274dac64d3ef2174b0782b270bc485f3016 (patch) | |
tree | 32b3defd32c3eb40d50c6b3c55b4f0b8477b515f /libglouglou/libglouglou.h | |
parent | fix error handling in "make run_loop (diff) | |
download | glouglou-18274274dac64d3ef2174b0782b270bc485f3016.tar.xz glouglou-18274274dac64d3ef2174b0782b270bc485f3016.zip |
improve connection handling between server and client.
better API.
skeletion for packet_decode()
Diffstat (limited to 'libglouglou/libglouglou.h')
-rw-r--r-- | libglouglou/libglouglou.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libglouglou/libglouglou.h b/libglouglou/libglouglou.h index 03ed2f1..aa602da 100644 --- a/libglouglou/libglouglou.h +++ b/libglouglou/libglouglou.h @@ -55,6 +55,7 @@ struct gg_user { LIST_ENTRY(gg_user) entry; int id; struct sockaddr_in addr; + char *buf[16384]; }; struct gg_server { @@ -62,8 +63,8 @@ struct gg_server { int port; struct event *ev; int sock; - int (*handle_conn)(struct gg_server *, int, struct sockaddr_in *); - int (*handle_packet)(struct gg_server *, struct gg_packet *); + int (*handle_conn)(struct gg_server *, struct gg_user *); + int (*handle_packet)(struct gg_server *, struct gg_user *, struct gg_packet *); LIST_HEAD(, gg_user) user_list; int user_id_count; }; @@ -71,21 +72,24 @@ struct gg_server { struct gg_client { const char *ip; int port; + int status; +#define GG_CLIENT_STATUS_DISCONNECTED 0 +#define GG_CLIENT_STATUS_CONNECTED 1 struct event *ev; int sock; - int (*handle_conn)(struct gg_client *, int); + int (*handle_conn)(struct gg_client *); int (*handle_packet)(struct gg_client *, struct gg_packet *); }; struct gg_server *gg_server_start(struct event_base *, char *, int, - int (*handle_conn)(struct gg_server *, int, struct sockaddr_in *), - int (*handle_packet)(struct gg_server *, struct gg_packet *)); + int (*handle_conn)(struct gg_server *, struct gg_user *), + int (*handle_packet)(struct gg_server *, struct gg_user *, struct gg_packet *)); int gg_server_send(struct gg_server *, int, struct gg_packet *); void gg_server_stop(struct gg_server *); struct gg_client *gg_client_connect(struct event_base *, char *, int, - int (*handle_conn)(struct gg_client *, int), + int (*handle_conn)(struct gg_client *), int (*handle_packet)(struct gg_client *, struct gg_packet *)); int gg_client_send(struct gg_client *, struct gg_packet *); void gg_client_disconnect(struct gg_client *); |