aboutsummaryrefslogtreecommitdiffstats
path: root/libglouglou/libglouglou.c
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-01 16:36:37 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-01 16:36:37 +0100
commitc112e5013454b48c9f05b3ac2153656cdcf549a4 (patch)
treeee34f55863ae900c045f42c9540153f43b7b37fd /libglouglou/libglouglou.c
parentwork in progress on implementing a send buffer (diff)
downloadglouglou-c112e5013454b48c9f05b3ac2153656cdcf549a4.tar.xz
glouglou-c112e5013454b48c9f05b3ac2153656cdcf549a4.zip
work in progress on sendbuf
Diffstat (limited to 'libglouglou/libglouglou.c')
-rw-r--r--libglouglou/libglouglou.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/libglouglou/libglouglou.c b/libglouglou/libglouglou.c
index c9c0df8..85993ce 100644
--- a/libglouglou/libglouglou.c
+++ b/libglouglou/libglouglou.c
@@ -28,10 +28,11 @@
int server_send(struct gg_server *, struct gg_user *,
void *, int);
void cb_srv_receive(evutil_socket_t, short, void *);
-int user_send(struct gg_user *, void *, int);
struct gg_user *user_add(struct gg_server *, struct sockaddr_in *);
void user_del(struct gg_server *, struct gg_user *);
struct gg_user * user_find(struct gg_server *, struct sockaddr_in *);
+int user_send(struct gg_user *, void *, int);
+int cb_usr_send(void *, int, void *);
int client_send(struct gg_client *, void *, int);
void cb_cli_receive(evutil_socket_t, short, void *);
void cb_cli_timer(evutil_socket_t, short, void *);
@@ -59,7 +60,6 @@ gg_server_start(struct event_base *ev_base, char *ip, int port,
struct gg_server *srv;
struct sockaddr_in sock_addr;
struct event *ev;
- struct sendbuf *sbuf;
int s;
int sock_on = 1;
@@ -71,12 +71,6 @@ gg_server_start(struct event_base *ev_base, char *ip, int port,
srv->handle_packet = handle_packet;
srv->usrdata = usrdata;
- sbuf = sendbuf_init(ev_base, PACKET_SNDBUF_MAX * 2, PACKET_SNDBUF_MAX, 200,
- cb_srv_send, srv);
- if (!sbuf)
- goto err;
- srv->sbuf = sbuf;
-
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
goto err;
@@ -99,6 +93,12 @@ gg_server_start(struct event_base *ev_base, char *ip, int port,
event_add(ev, NULL);
srv->ev = ev;
+ sbuf = sendbuf_init(srv->ev_base, PACKET_SNDBUF_MAX * 2, PACKET_SNDBUF_MAX,
+ 200);
+ if (!sbuf)
+ goto err;
+ srv->sbuf = sbuf;
+
return srv;
err:
@@ -108,23 +108,16 @@ err:
}
int
-cb_srv_send(void *data, int size, void *usrdata)
-{
- struct gg_server *srv;
-
- srv = usrdata;
-}
-
-int
gg_server_send(struct gg_server *srv, struct gg_packet *pkt, struct gg_user *usr)
{
static struct gg_packet *newpkt;
int size;
// XXX IN PROGRESS get size before
- newpkt = sendbuf_gettoken(srv->sndbuf, size);
-
- pkt_encode(pkt, &size, newpkt);
+ size = pkt_getsize(pkt);
+ newpkt = sendbuf_token_get(srv->sndbuf, size);
+ pkt_encode(pkt, newpkt);
+ sendbuf_token_ready(srv->sndbuf, newpkt);
if (!newpkt)
return -1;
@@ -210,12 +203,16 @@ struct gg_user *
user_add(struct gg_server *srv, struct sockaddr_in *remote)
{
struct gg_user *usr;
+ struct sendbuf *sbuf;
usr = xcalloc(1, sizeof(struct gg_user));
usr->id = srv->user_id_count;
srv->user_id_count++;
usr->sock = srv->sock;
addrcpy(&usr->addr, remote);
+
+ sendbuf_queue_add(srv->sbuf, cb_usr_send, usr);
+
LIST_INSERT_HEAD(&srv->user_list, usr, entry);
verbose("Add user %d !", usr->id);
@@ -256,6 +253,16 @@ user_send(struct gg_user *usr, void *data, int size)
return 0;
}
+int
+cb_usr_send(void *data, int size, void *usrdata)
+{
+ struct gg_user *usr;
+
+ usr = usrdata;
+ user_send(usr, NULL, data, size);
+}
+
+
/*
* Client
*/