diff options
Diffstat (limited to 'libglouglou/libglouglou.h')
-rw-r--r-- | libglouglou/libglouglou.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/libglouglou/libglouglou.h b/libglouglou/libglouglou.h index aa602da..418e565 100644 --- a/libglouglou/libglouglou.h +++ b/libglouglou/libglouglou.h @@ -2,20 +2,24 @@ #include "contrib/queue.h" #define PACKET_VERSION 1 +#define PACKET_BUFFER_SIZE 16384 #define DNSNAME_MAX 20 struct gg_packet { +#define PACKET_HEADER_SIZE 2 u_int8_t ver; u_int8_t type; /* XXX nicer way for _SIZE ... ? */ +#define PACKET_TYPE_MIN 0 +#define PACKET_TYPE_MAX 3 #define PACKET_NEWCONN 0 -#define PACKET_NEWCONN_SIZE (2 + sizeof((struct packet *)0)->pdat.newconn) +#define PACKET_NEWCONN_SIZE (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.newconn) #define PACKET_DELCONN 1 -#define PACKET_DELCONN_SIZE (2 + sizeof((struct packet *)0)->pdat.delconn) +#define PACKET_DELCONN_SIZE (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.delconn) #define PACKET_DATA 2 -#define PACKET_DATA_SIZE (2 + sizeof((struct packet *)0)->pdat.data) +#define PACKET_DATA_SIZE (PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.data) #define PACKET_NAME 3 -#define PACKET_NAME_SIZE ((2 + sizeof((struct packet *)0)->pdat.name) - DNSNAME_MAX) +#define PACKET_NAME_SIZE ((PACKET_HEADER_SIZE + sizeof((struct gg_packet *)0)->pdat.name) - DNSNAME_MAX) union { struct newconn { @@ -61,6 +65,7 @@ struct gg_user { struct gg_server { const char *ip; int port; + struct sockaddr_in addr; struct event *ev; int sock; int (*handle_conn)(struct gg_server *, struct gg_user *); @@ -72,11 +77,12 @@ struct gg_server { struct gg_client { const char *ip; int port; + struct sockaddr_in addr; + struct event *ev; + int sock; 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 (*handle_packet)(struct gg_client *, struct gg_packet *); }; @@ -85,13 +91,13 @@ struct gg_client { struct gg_server *gg_server_start(struct event_base *, char *, int, 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 *); +int gg_server_send(struct gg_server *, struct gg_packet *, int, struct gg_user *); 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 (*handle_packet)(struct gg_client *, struct gg_packet *)); -int gg_client_send(struct gg_client *, struct gg_packet *); +int gg_client_send(struct gg_client *, struct gg_packet *, int); void gg_client_disconnect(struct gg_client *); void *xmalloc(size_t); |