]> git.meshlink.io Git - utcp/blobdiff - utcp.c
Add some missing definitions for Windows.
[utcp] / utcp.c
diff --git a/utcp.c b/utcp.c
index cf33e4c174b1a63d7b5291a961ea479be9aad03f..75553d72567be387667b7ced7871cac32d0d6a46 100644 (file)
--- a/utcp.c
+++ b/utcp.c
 
 #include "utcp_priv.h"
 
+#ifndef EBADMSG
+#define EBADMSG         104
+#endif
+
+#ifndef SHUT_RDWR
+#define SHUT_RDWR 2
+#endif
+
+#ifdef poll
+#undef poll
+#endif
+
+#ifndef timersub
+#define timersub(a, b, r) do {\
+       (r)->tv_sec = (a)->tv_sec - (b)->tv_sec;\
+       (r)->tv_usec = (a)->tv_usec - (b)->tv_usec;\
+       if((r)->tv_usec < 0)\
+               (r)->tv_sec--, (r)->tv_usec += 1000000;\
+} while (0)
+#endif
+
 #ifdef UTCP_DEBUG
 #include <stdarg.h>
 
@@ -202,6 +223,7 @@ struct utcp_connection *utcp_connect(struct utcp *utcp, uint16_t dst, utcp_recv_
                return NULL;
 
        c->recv = recv;
+       c->priv = priv;
 
        struct hdr hdr;
 
@@ -1021,6 +1043,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;
 
@@ -1096,6 +1121,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)
@@ -1121,3 +1150,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;
+}