From 36d0ee5c9faa59b2bb0289ec84189eb2aeb6ba18 Mon Sep 17 00:00:00 2001 From: Patrick Pelletier Date: Tue, 13 Nov 2012 21:22:39 -0800 Subject: [PATCH] preserve errno in evhttp_connection_fail_ for inspection by the callback --- http.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/http.c b/http.c index 34d1dc96..0a9390f2 100644 --- a/http.c +++ b/http.c @@ -681,6 +681,7 @@ void evhttp_connection_fail_(struct evhttp_connection *evcon, enum evhttp_connection_error error) { + const int errsave = errno; struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); void (*cb)(struct evhttp_request *, void *); void *cb_arg; @@ -726,6 +727,12 @@ evhttp_connection_fail_(struct evhttp_connection *evcon, if (TAILQ_FIRST(&evcon->requests) != NULL) evhttp_connection_connect_(evcon); + /* The call to evhttp_connection_reset_ overwrote errno. + * Let's restore the original errno, so that the user's + * callback can have a better idea of what the error was. + */ + errno = errsave; + /* inform the user */ if (cb != NULL) (*cb)(NULL, cb_arg);