]> granicus.if.org Git - libevent/commitdiff
Remove calls to deprecated bufferevent functions from evhttp.c
authorNick Mathewson <nickm@torproject.org>
Mon, 12 Sep 2011 14:57:37 +0000 (10:57 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 12 Sep 2011 14:57:37 +0000 (10:57 -0400)
http.c

diff --git a/http.c b/http.c
index d5c51f4662ac9369f1ceed5ff800aa76e1747d47..abc73471b58b0d88c10b27df71b9dab1094eacc3 100644 (file)
--- a/http.c
+++ b/http.c
@@ -92,7 +92,6 @@
 #include "event2/event.h"
 #include "event2/buffer.h"
 #include "event2/bufferevent.h"
-#include "event2/bufferevent_compat.h"
 #include "event2/http_struct.h"
 #include "event2/http_compat.h"
 #include "event2/util.h"
@@ -1435,8 +1434,9 @@ evhttp_connection_cb(struct bufferevent *bufev, short what, void *arg)
            evcon);
 
        if (!evutil_timerisset(&evcon->timeout)) {
-               bufferevent_settimeout(evcon->bufev,
-                   HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
+               const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 };
+               const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 };
+               bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv);
        } else {
                bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
        }
@@ -2181,28 +2181,24 @@ evhttp_connection_base_bufferevent_new(struct event_base *base, struct evdns_bas
        }
 
        if (bev == NULL) {
-               if ((evcon->bufev = bufferevent_new(-1,
-                                       evhttp_read_cb,
-                                       evhttp_write_cb,
-                                       evhttp_error_cb, evcon)) == NULL) {
-                       event_warn("%s: bufferevent_new failed", __func__);
+               if (!(bev = bufferevent_socket_new(base, -1, 0))) {
+                       event_warn("%s: bufferevent_socket_new failed", __func__);
                        goto error;
                }
        }
-       else {
-               bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon);
-               evcon->bufev = bev;
-       }
+
+       bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon);
+       evcon->bufev = bev;
 
        evcon->state = EVCON_DISCONNECTED;
        TAILQ_INIT(&evcon->requests);
 
        if (base != NULL) {
                evcon->base = base;
-               bufferevent_base_set(base, evcon->bufev);
+               if (bufferevent_get_base(bev) != base)
+                       bufferevent_base_set(base, evcon->bufev);
        }
 
-
        event_deferred_cb_init(&evcon->read_more_deferred_cb,
            evhttp_deferred_read_cb, evcon);
 
@@ -2260,8 +2256,10 @@ evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon,
                evcon->timeout = *tv;
                bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout);
        } else {
+               const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 };
+               const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 };
                evutil_timerclear(&evcon->timeout);
-               bufferevent_settimeout(evcon->bufev, HTTP_READ_TIMEOUT, HTTP_WRITE_TIMEOUT);
+               bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv);
        }
 }
 
@@ -2314,10 +2312,12 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
            NULL /* evhttp_write_cb */,
            evhttp_connection_cb,
            evcon);
-       if (!evutil_timerisset(&evcon->timeout))
-               bufferevent_settimeout(evcon->bufev, 0, HTTP_CONNECT_TIMEOUT);
-       else
+       if (!evutil_timerisset(&evcon->timeout)) {
+               const struct timeval conn_tv = { HTTP_CONNECT_TIMEOUT, 0 };
+               bufferevent_set_timeouts(evcon->bufev, NULL, &conn_tv);
+       } else {
                bufferevent_set_timeouts(evcon->bufev, NULL, &evcon->timeout);
+       }
        /* make sure that we get a write callback */
        bufferevent_enable(evcon->bufev, EV_WRITE);