]> granicus.if.org Git - libevent/commitdiff
Make bufferevent_set_timeouts(bev, NULL, NULL) have plausible semantics
authorNick Mathewson <nickm@torproject.org>
Fri, 16 Nov 2012 23:34:43 +0000 (18:34 -0500)
committerNick Mathewson <nickm@torproject.org>
Fri, 16 Nov 2012 23:34:43 +0000 (18:34 -0500)
bufferevent_openssl.c
bufferevent_sock.c

index 55173d928d9411513b176ac7df15eedd76b848c9..99ed5f8d68e308159ef3b7fdd62e2f9b621a5116 100644 (file)
@@ -1221,14 +1221,25 @@ be_openssl_adj_timeouts(struct bufferevent *bev)
 {
        struct bufferevent_openssl *bev_ssl = upcast(bev);
 
-       if (bev_ssl->underlying)
+       if (bev_ssl->underlying) {
                return bufferevent_generic_adj_timeouts_(bev);
-       else {
+       else {
                int r1=0, r2=0;
-               if (event_pending(&bev->ev_read, EV_READ, NULL))
-                       r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read);
-               if (event_pending(&bev->ev_write, EV_WRITE, NULL))
-                       r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write);
+               if (event_pending(&bev->ev_read, EV_READ, NULL)) {
+                       if (evutil_timerisset(&bev->timeout_read)) {
+                               r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read);
+                       } else {
+                               event_remove_timer(&bev->ev_read);
+                       }
+               }
+               if (event_pending(&bev->ev_write, EV_WRITE, NULL)) {
+                       if (evutil_timerisset(&bev->timeout_write)) {
+                               r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write);
+                       } else {
+                               event_remove_timer(&bev->ev_write);
+                       }
+               }
+
                return (r1<0 || r2<0) ? -1 : 0;
        }
 }
index eaaf9414e8c07c2b96b9d4f2fa584004fddc856c..5a85743dbf8cb8fa0bccac7525656ade3b94756a 100644 (file)
@@ -600,12 +600,21 @@ static int
 be_socket_adj_timeouts(struct bufferevent *bufev)
 {
        int r = 0;
-       if (event_pending(&bufev->ev_read, EV_READ, NULL))
-               if (be_socket_add(&bufev->ev_read, &bufev->timeout_read) < 0)
-                       r = -1;
+       if (event_pending(&bufev->ev_read, EV_READ, NULL)) {
+               if (evutil_timerisset(&bufev->timeout_read)) {
+                           if (be_socket_add(&bufev->ev_read, &bufev->timeout_read) < 0)
+                                   r = -1;
+               } else {
+                       event_remove_timer(&bufev->ev_read);
+               }
+       }
        if (event_pending(&bufev->ev_write, EV_WRITE, NULL)) {
-               if (be_socket_add(&bufev->ev_write, &bufev->timeout_write) < 0)
-                       r = -1;
+               if (evutil_timerisset(&bufev->timeout_write)) {
+                       if (be_socket_add(&bufev->ev_write, &bufev->timeout_write) < 0)
+                               r = -1;
+               } else {
+                       event_remove_timer(&bufev->ev_write);
+               }
        }
        return r;
 }