aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-11-29 10:08:56 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-11-29 10:08:56 +0100
commit2a5e8c3534d070de3bf142af47e29fb835498ad9 (patch)
treec969d878e5f128152507e72312ab1c9f43ece076
parentfix callback function definition (diff)
downloadglouglou-2a5e8c3534d070de3bf142af47e29fb835498ad9.tar.xz
glouglou-2a5e8c3534d070de3bf142af47e29fb835498ad9.zip
add a way to pass userdata to server and client callbacks
-rw-r--r--libglouglou/libglouglou.c8
-rw-r--r--libglouglou/libglouglou.h8
-rw-r--r--libglouglou/tests/connect.c4
-rw-r--r--libglouglou/tests/sendrecv.c4
4 files changed, 16 insertions, 8 deletions
diff --git a/libglouglou/libglouglou.c b/libglouglou/libglouglou.c
index efbd256..a3eb271 100644
--- a/libglouglou/libglouglou.c
+++ b/libglouglou/libglouglou.c
@@ -29,7 +29,8 @@ void cb_cli_receive(evutil_socket_t, short, void *);
struct gg_server *
gg_server_start(struct event_base *ev_base, char *ip, int port,
int (*handle_conn)(struct gg_server *, struct gg_user *),
- int (*handle_packet)(struct gg_server *, struct gg_user *, struct gg_packet *))
+ int (*handle_packet)(struct gg_server *, struct gg_user *, struct gg_packet *),
+ void *usrdata)
{
struct gg_server *srv;
struct sockaddr_in sock_addr;
@@ -42,6 +43,7 @@ gg_server_start(struct event_base *ev_base, char *ip, int port,
srv->port = port;
srv->handle_conn = handle_conn;
srv->handle_packet = handle_packet;
+ srv->usrdata = usrdata;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
goto err;
@@ -272,7 +274,8 @@ void cb_srv_receive(evutil_socket_t fd, short what, void *arg)
struct gg_client *
gg_client_connect(struct event_base *ev_base, char *ip, int port,
int (*handle_conn)(struct gg_client *),
- int (*handle_packet)(struct gg_client *, struct gg_packet *))
+ int (*handle_packet)(struct gg_client *, struct gg_packet *),
+ void *usrdata)
{
struct gg_client *cli;
struct sockaddr_in sock_addr;
@@ -285,6 +288,7 @@ gg_client_connect(struct event_base *ev_base, char *ip, int port,
cli->port = port;
cli->handle_conn = handle_conn;
cli->handle_packet = handle_packet;
+ cli->usrdata = usrdata;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
goto err;
diff --git a/libglouglou/libglouglou.h b/libglouglou/libglouglou.h
index 418e565..93a4492 100644
--- a/libglouglou/libglouglou.h
+++ b/libglouglou/libglouglou.h
@@ -70,6 +70,7 @@ struct gg_server {
int sock;
int (*handle_conn)(struct gg_server *, struct gg_user *);
int (*handle_packet)(struct gg_server *, struct gg_user *, struct gg_packet *);
+ void *usrdata;
LIST_HEAD(, gg_user) user_list;
int user_id_count;
};
@@ -85,18 +86,21 @@ struct gg_client {
#define GG_CLIENT_STATUS_CONNECTED 1
int (*handle_conn)(struct gg_client *);
int (*handle_packet)(struct gg_client *, struct gg_packet *);
+ void *usrdata;
};
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 (*handle_packet)(struct gg_server *, struct gg_user *, struct gg_packet *),
+ void *);
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 (*handle_packet)(struct gg_client *, struct gg_packet *),
+ void *);
int gg_client_send(struct gg_client *, struct gg_packet *, int);
void gg_client_disconnect(struct gg_client *);
diff --git a/libglouglou/tests/connect.c b/libglouglou/tests/connect.c
index 1c41ecb..b61107f 100644
--- a/libglouglou/tests/connect.c
+++ b/libglouglou/tests/connect.c
@@ -26,11 +26,11 @@ main(void)
struct event_base *ev_base;
ev_base = event_base_new();
- if (!gg_server_start(ev_base, "127.0.0.1", 12345, srv_handle_conn, NULL)) {
+ if (!gg_server_start(ev_base, "127.0.0.1", 12345, srv_handle_conn, NULL, NULL)) {
printf("error: gg_server_start returned NULL\n");
return 1;
}
- if (!gg_client_connect(ev_base, "127.0.0.1", 12345, cli_handle_conn, NULL)) {
+ if (!gg_client_connect(ev_base, "127.0.0.1", 12345, cli_handle_conn, NULL, NULL)) {
printf("error: gg_client_connect returned NULL\n");
return 1;
}
diff --git a/libglouglou/tests/sendrecv.c b/libglouglou/tests/sendrecv.c
index 0127cb4..ea8fa0e 100644
--- a/libglouglou/tests/sendrecv.c
+++ b/libglouglou/tests/sendrecv.c
@@ -30,12 +30,12 @@ main(void)
struct gg_packet pkt;
ev_base = event_base_new();
- srv = gg_server_start(ev_base, "127.0.0.1", 12345, NULL, srv_handle_packet);
+ srv = gg_server_start(ev_base, "127.0.0.1", 12345, NULL, srv_handle_packet, NULL);
if (!srv) {
printf("error: gg_server_start returned NULL\n");
return 1;
}
- cli = gg_client_connect(ev_base, "127.0.0.1", 12345, NULL, cli_handle_packet);
+ cli = gg_client_connect(ev_base, "127.0.0.1", 12345, NULL, cli_handle_packet, NULL);
if (!cli) {
printf("error: gg_client_connect returned NULL\n");
return 1;