]> git.meshlink.io Git - utcp/blobdiff - utcp.c
Change utcp_timeout() to return a struct timeval.
[utcp] / utcp.c
diff --git a/utcp.c b/utcp.c
index a79304ca8114b717028e9f8d5e3ede76948e6ccf..2ef56ea76a451558d19d6963679f1d9c5a7e8b6c 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -930,6 +930,8 @@ int utcp_shutdown(struct utcp_connection *c, int dir) {
 int utcp_close(struct utcp_connection *c) {
        if(utcp_shutdown(c, SHUT_RDWR))
                return -1;
+       c->recv = NULL;
+       c->poll = NULL;
        c->reapable = true;
        return 0;
 }
@@ -946,6 +948,8 @@ int utcp_abort(struct utcp_connection *c) {
                return -1;
        }
 
+       c->recv = NULL;
+       c->poll = NULL;
        c->reapable = true;
 
        switch(c->state) {
@@ -1057,7 +1061,7 @@ static void retransmit(struct utcp_connection *c) {
  * The return value is the time to the next timeout in milliseconds,
  * or maybe a negative value if the timeout is infinite.
  */
-int utcp_timeout(struct utcp *utcp) {
+struct timeval utcp_timeout(struct utcp *utcp) {
        struct timeval now;
        gettimeofday(&now, NULL);
        struct timeval next = {now.tv_sec + 3600, now.tv_usec};
@@ -1107,9 +1111,7 @@ int utcp_timeout(struct utcp *utcp) {
 
        struct timeval diff;
        timersub(&next, &now, &diff);
-       if(diff.tv_sec < 0)
-               return 0;
-       return diff.tv_sec * 1000 + diff.tv_usec / 1000;
+       return diff;
 }
 
 struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv) {