]> git.meshlink.io Git - utcp/blobdiff - utcp.c
Add a poll callback to UTCP connections.
[utcp] / utcp.c
diff --git a/utcp.c b/utcp.c
index 5962820805d60f822a3a16d28b4098c604bb380f..ca3c132f60c9132da69b019e3583d83db11974df 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -1022,6 +1022,9 @@ int utcp_timeout(struct utcp *utcp) {
                        retransmit(c);
                }
 
+               if(c->poll && c->sndbufsize < c->maxsndbufsize / 2)
+                       c->poll(c, c->maxsndbufsize - c->sndbufsize);
+
                if(timerisset(&c->conn_timeout) && timercmp(&c->conn_timeout, &next, <))
                        next = c->conn_timeout;
 
@@ -1097,6 +1100,10 @@ size_t utcp_get_sndbuf(struct utcp_connection *c) {
        return c->maxsndbufsize;
 }
 
+size_t utcp_get_sndbuf_free(struct utcp_connection *c) {
+       return c->maxsndbufsize - c->sndbufsize;
+}
+
 void utcp_set_sndbuf(struct utcp_connection *c, size_t size) {
        c->maxsndbufsize = size;
        if(c->maxsndbufsize != size)
@@ -1122,3 +1129,11 @@ void utcp_set_keepalive(struct utcp_connection *c, bool keepalive) {
 size_t utcp_get_outq(struct utcp_connection *c) {
        return seqdiff(c->snd.nxt, c->snd.una);
 }
+
+void utcp_set_recv_cb(struct utcp_connection *c, utcp_recv_t recv) {
+       c->recv = recv;
+}
+
+void utcp_set_poll_cb(struct utcp_connection *c, utcp_poll_t poll) {
+       c->poll = poll;
+}