aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-02 15:35:31 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-02 15:35:31 +0100
commitde85285f3e15a779adef18b874cbfea99fd2bcb2 (patch)
tree42b79265a500ea609aa72815fa39c55eb24bc7db
parentTODO++ (diff)
downloadglouglou-de85285f3e15a779adef18b874cbfea99fd2bcb2.tar.xz
glouglou-de85285f3e15a779adef18b874cbfea99fd2bcb2.zip
add functions to flush send buffers
-rw-r--r--libglouglou/libglouglou.c18
-rw-r--r--libglouglou/libglouglou.h2
-rw-r--r--libglouglou/sendbuf.c23
-rw-r--r--libglouglou/sendbuf.h1
4 files changed, 33 insertions, 11 deletions
diff --git a/libglouglou/libglouglou.c b/libglouglou/libglouglou.c
index 090e774..0b0ab48 100644
--- a/libglouglou/libglouglou.c
+++ b/libglouglou/libglouglou.c
@@ -145,6 +145,18 @@ gg_server_send(struct gg_server *srv, struct gg_packet *pkt, struct gg_user *usr
return res;
}
+void
+gg_server_send_flush(struct gg_server *srv, struct gg_user *usr)
+{
+ struct gg_user *u;
+
+ if (usr)
+ sendbuf_flush(usr->sbuf);
+ else
+ LIST_FOREACH(u, &srv->user_list, entry)
+ sendbuf_flush(u->sbuf);
+}
+
/*
* Server - private
*/
@@ -369,6 +381,12 @@ gg_client_send(struct gg_client *cli, struct gg_packet *pkt)
return pkt_encode(pkt, newpkt);
}
+void
+gg_client_send_flush(struct gg_client *cli)
+{
+ sendbuf_flush(cli->sbuf);
+}
+
/*
* Client - private
*/
diff --git a/libglouglou/libglouglou.h b/libglouglou/libglouglou.h
index 3fdd2ae..473c7a2 100644
--- a/libglouglou/libglouglou.h
+++ b/libglouglou/libglouglou.h
@@ -162,6 +162,7 @@ struct gg_server *gg_server_start(struct event_base *, char *, int,
void *);
void gg_server_stop(struct gg_server *);
int gg_server_send(struct gg_server *, struct gg_packet *, struct gg_user *);
+void gg_server_send_flush(struct gg_server *, struct gg_user *);
struct gg_client *gg_client_connect(struct event_base *, char *, int,
int (*handle_conn)(struct gg_client *),
@@ -169,6 +170,7 @@ struct gg_client *gg_client_connect(struct event_base *, char *, int,
void *);
void gg_client_disconnect(struct gg_client *);
int gg_client_send(struct gg_client *, struct gg_packet *);
+void gg_client_send_flush(struct gg_client *);
int gg_verbosity_get(void);
void gg_verbosity_set(int);
diff --git a/libglouglou/sendbuf.c b/libglouglou/sendbuf.c
index 15a7d23..4e83294 100644
--- a/libglouglou/sendbuf.c
+++ b/libglouglou/sendbuf.c
@@ -3,7 +3,6 @@
#include "sendbuf.h"
-static int flushbuf(struct sendbuf *);
static void cb_timer(evutil_socket_t, short, void *);
/*
@@ -50,7 +49,7 @@ sendbuf_free(struct sendbuf *sbuf)
if (sbuf->ev_timer)
event_del(sbuf->ev_timer);
if (sbuf->buffer && sbuf->send_func)
- flushbuf(sbuf);
+ sendbuf_flush(sbuf);
if (sbuf->buffer)
free(sbuf->buffer);
free(sbuf);
@@ -65,7 +64,7 @@ int
sendbuf_append(struct sendbuf *sbuf, void *token, int size)
{
if (sbuf->buffer_pos + size >= sbuf->buffer_size)
- if (flushbuf(sbuf) == -1)
+ if (sendbuf_flush(sbuf) == -1)
return -1;
memcpy(sbuf->buffer + sbuf->buffer_pos, token, size);
@@ -85,7 +84,7 @@ sendbuf_gettoken(struct sendbuf *sbuf, int size)
void *token;
if (sbuf->buffer_pos + size >= sbuf->buffer_size)
- if (flushbuf(sbuf) == -1)
+ if (sendbuf_flush(sbuf) == -1)
return NULL;
token = sbuf->buffer + sbuf->buffer_pos;
@@ -95,16 +94,13 @@ sendbuf_gettoken(struct sendbuf *sbuf, int size)
}
/*
- * Private
- */
-
-/*
+ * Send buffer immediatly
* Note that you can still add data to the buffer even if flushing is in
* progress
* returns 0 on success or -1 on error
*/
-static int
-flushbuf(struct sendbuf *sbuf)
+int
+sendbuf_flush(struct sendbuf *sbuf)
{
int tosend, sent;
@@ -130,12 +126,17 @@ flushbuf(struct sendbuf *sbuf)
return 0;
}
+
+/*
+ * Private
+ */
+
static void
cb_timer(evutil_socket_t fd, short what, void *arg)
{
struct sendbuf *sbuf;
sbuf = arg;
- flushbuf(sbuf);
+ sendbuf_flush(sbuf);
evtimer_add(sbuf->ev_timer, &sbuf->ev_timer_tv);
}
diff --git a/libglouglou/sendbuf.h b/libglouglou/sendbuf.h
index 0290202..6d163d4 100644
--- a/libglouglou/sendbuf.h
+++ b/libglouglou/sendbuf.h
@@ -21,3 +21,4 @@ struct sendbuf *sendbuf_new(struct event_base *, int, int,
void sendbuf_free(struct sendbuf *);
int sendbuf_append(struct sendbuf *, void *, int);
void *sendbuf_gettoken(struct sendbuf *, int);
+int sendbuf_flush(struct sendbuf *);