aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libevent/bufferevent_sock.c
diff options
context:
space:
mode:
authorkikht <kikht@yandex-team.ru>2022-02-10 16:45:14 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:14 +0300
commit194cae0e8855b11be2005e1eff12c660c3ee9774 (patch)
treeed29c437b616690880c017855ebe0be34fdf81a2 /contrib/libs/libevent/bufferevent_sock.c
parent49116032d905455a7b1c994e4a696afc885c1e71 (diff)
downloadydb-194cae0e8855b11be2005e1eff12c660c3ee9774.tar.gz
Restoring authorship annotation for <kikht@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/libevent/bufferevent_sock.c')
-rw-r--r--contrib/libs/libevent/bufferevent_sock.c300
1 files changed, 150 insertions, 150 deletions
diff --git a/contrib/libs/libevent/bufferevent_sock.c b/contrib/libs/libevent/bufferevent_sock.c
index 003a5d3d0d..148a45fa7c 100644
--- a/contrib/libs/libevent/bufferevent_sock.c
+++ b/contrib/libs/libevent/bufferevent_sock.c
@@ -26,12 +26,12 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "event2/event-config.h"
-#include "evconfig-private.h"
-
+#include "event2/event-config.h"
+#include "evconfig-private.h"
+
#include <sys/types.h>
-#ifdef EVENT__HAVE_SYS_TIME_H
+#ifdef EVENT__HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@@ -39,27 +39,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef EVENT__HAVE_STDARG_H
+#ifdef EVENT__HAVE_STDARG_H
#include <stdarg.h>
#endif
-#ifdef EVENT__HAVE_UNISTD_H
+#ifdef EVENT__HAVE_UNISTD_H
#include <unistd.h>
#endif
-#ifdef _WIN32
+#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
-#ifdef EVENT__HAVE_SYS_SOCKET_H
+#ifdef EVENT__HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
-#ifdef EVENT__HAVE_NETINET_IN_H
+#ifdef EVENT__HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
-#ifdef EVENT__HAVE_NETINET_IN6_H
-#error #include <netinet/in6.h>
-#endif
+#ifdef EVENT__HAVE_NETINET_IN6_H
+#error #include <netinet/in6.h>
+#endif
#include "event2/util.h"
#include "event2/bufferevent.h"
@@ -71,7 +71,7 @@
#include "mm-internal.h"
#include "bufferevent-internal.h"
#include "util-internal.h"
-#ifdef _WIN32
+#ifdef _WIN32
#include "iocp-internal.h"
#endif
@@ -89,49 +89,49 @@ const struct bufferevent_ops bufferevent_ops_socket = {
evutil_offsetof(struct bufferevent_private, bev),
be_socket_enable,
be_socket_disable,
- NULL, /* unlink */
+ NULL, /* unlink */
be_socket_destruct,
- bufferevent_generic_adj_existing_timeouts_,
+ bufferevent_generic_adj_existing_timeouts_,
be_socket_flush,
be_socket_ctrl,
};
-const struct sockaddr*
-bufferevent_socket_get_conn_address_(struct bufferevent *bev)
-{
- struct bufferevent_private *bev_p = BEV_UPCAST(bev);
- return (struct sockaddr *)&bev_p->conn_address;
-}
-
-void
-bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev,
- evutil_socket_t fd)
-{
- struct bufferevent_private *bev_p = BEV_UPCAST(bev);
-
- socklen_t len = sizeof(bev_p->conn_address);
-
- struct sockaddr *addr = (struct sockaddr *)&bev_p->conn_address;
- if (addr->sa_family != AF_UNSPEC)
- getpeername(fd, addr, &len);
-}
-
-void
-bufferevent_socket_set_conn_address_(struct bufferevent *bev,
- struct sockaddr *addr, size_t addrlen)
-{
- struct bufferevent_private *bev_p = BEV_UPCAST(bev);
- EVUTIL_ASSERT(addrlen <= sizeof(bev_p->conn_address));
- memcpy(&bev_p->conn_address, addr, addrlen);
-}
-
+const struct sockaddr*
+bufferevent_socket_get_conn_address_(struct bufferevent *bev)
+{
+ struct bufferevent_private *bev_p = BEV_UPCAST(bev);
+ return (struct sockaddr *)&bev_p->conn_address;
+}
+
+void
+bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev,
+ evutil_socket_t fd)
+{
+ struct bufferevent_private *bev_p = BEV_UPCAST(bev);
+
+ socklen_t len = sizeof(bev_p->conn_address);
+
+ struct sockaddr *addr = (struct sockaddr *)&bev_p->conn_address;
+ if (addr->sa_family != AF_UNSPEC)
+ getpeername(fd, addr, &len);
+}
+
+void
+bufferevent_socket_set_conn_address_(struct bufferevent *bev,
+ struct sockaddr *addr, size_t addrlen)
+{
+ struct bufferevent_private *bev_p = BEV_UPCAST(bev);
+ EVUTIL_ASSERT(addrlen <= sizeof(bev_p->conn_address));
+ memcpy(&bev_p->conn_address, addr, addrlen);
+}
+
static void
bufferevent_socket_outbuf_cb(struct evbuffer *buf,
const struct evbuffer_cb_info *cbinfo,
void *arg)
{
struct bufferevent *bufev = arg;
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
if (cbinfo->n_added &&
(bufev->enabled & EV_WRITE) &&
@@ -139,7 +139,7 @@ bufferevent_socket_outbuf_cb(struct evbuffer *buf,
!bufev_p->write_suspended) {
/* Somebody added data to the buffer, and we would like to
* write, and we were not writing. So, start writing. */
- if (bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) {
+ if (bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) {
/* Should we log this? */
}
}
@@ -149,13 +149,13 @@ static void
bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
{
struct bufferevent *bufev = arg;
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
struct evbuffer *input;
int res = 0;
short what = BEV_EVENT_READING;
ev_ssize_t howmuch = -1, readmax=-1;
- bufferevent_incref_and_lock_(bufev);
+ bufferevent_incref_and_lock_(bufev);
if (event == EV_TIMEOUT) {
/* Note that we only check for event==EV_TIMEOUT. If
@@ -179,7 +179,7 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
goto done;
}
}
- readmax = bufferevent_get_read_max_(bufev_p);
+ readmax = bufferevent_get_read_max_(bufev_p);
if (howmuch < 0 || howmuch > readmax) /* The use of -1 for "unlimited"
* uglifies this code. XXXX */
howmuch = readmax;
@@ -194,10 +194,10 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
int err = evutil_socket_geterror(fd);
if (EVUTIL_ERR_RW_RETRIABLE(err))
goto reschedule;
- if (EVUTIL_ERR_CONNECT_REFUSED(err)) {
- bufev_p->connection_refused = 1;
- goto done;
- }
+ if (EVUTIL_ERR_CONNECT_REFUSED(err)) {
+ bufev_p->connection_refused = 1;
+ goto done;
+ }
/* error case */
what |= BEV_EVENT_ERROR;
} else if (res == 0) {
@@ -208,10 +208,10 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
if (res <= 0)
goto error;
- bufferevent_decrement_read_buckets_(bufev_p, res);
+ bufferevent_decrement_read_buckets_(bufev_p, res);
/* Invoke the user callback - must always be called last */
- bufferevent_trigger_nolock_(bufev, EV_READ, 0);
+ bufferevent_trigger_nolock_(bufev, EV_READ, 0);
goto done;
@@ -220,23 +220,23 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
error:
bufferevent_disable(bufev, EV_READ);
- bufferevent_run_eventcb_(bufev, what, 0);
+ bufferevent_run_eventcb_(bufev, what, 0);
done:
- bufferevent_decref_and_unlock_(bufev);
+ bufferevent_decref_and_unlock_(bufev);
}
static void
bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
{
struct bufferevent *bufev = arg;
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
int res = 0;
short what = BEV_EVENT_WRITING;
int connected = 0;
ev_ssize_t atmost = -1;
- bufferevent_incref_and_lock_(bufev);
+ bufferevent_incref_and_lock_(bufev);
if (event == EV_TIMEOUT) {
/* Note that we only check for event==EV_TIMEOUT. If
@@ -246,12 +246,12 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
goto error;
}
if (bufev_p->connecting) {
- int c = evutil_socket_finished_connecting_(fd);
+ int c = evutil_socket_finished_connecting_(fd);
/* we need to fake the error if the connection was refused
* immediately - usually connection to localhost on BSD */
if (bufev_p->connection_refused) {
- bufev_p->connection_refused = 0;
- c = -1;
+ bufev_p->connection_refused = 0;
+ c = -1;
}
if (c == 0)
@@ -261,22 +261,22 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
if (c < 0) {
event_del(&bufev->ev_write);
event_del(&bufev->ev_read);
- bufferevent_run_eventcb_(bufev, BEV_EVENT_ERROR, 0);
+ bufferevent_run_eventcb_(bufev, BEV_EVENT_ERROR, 0);
goto done;
} else {
connected = 1;
- bufferevent_socket_set_conn_address_fd_(bufev, fd);
-#ifdef _WIN32
+ bufferevent_socket_set_conn_address_fd_(bufev, fd);
+#ifdef _WIN32
if (BEV_IS_ASYNC(bufev)) {
event_del(&bufev->ev_write);
- bufferevent_async_set_connected_(bufev);
- bufferevent_run_eventcb_(bufev,
- BEV_EVENT_CONNECTED, 0);
+ bufferevent_async_set_connected_(bufev);
+ bufferevent_run_eventcb_(bufev,
+ BEV_EVENT_CONNECTED, 0);
goto done;
}
#endif
- bufferevent_run_eventcb_(bufev,
- BEV_EVENT_CONNECTED, 0);
+ bufferevent_run_eventcb_(bufev,
+ BEV_EVENT_CONNECTED, 0);
if (!(bufev->enabled & EV_WRITE) ||
bufev_p->write_suspended) {
event_del(&bufev->ev_write);
@@ -285,7 +285,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
}
}
- atmost = bufferevent_get_write_max_(bufev_p);
+ atmost = bufferevent_get_write_max_(bufev_p);
if (bufev_p->write_suspended)
goto done;
@@ -309,7 +309,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
if (res <= 0)
goto error;
- bufferevent_decrement_write_buckets_(bufev_p, res);
+ bufferevent_decrement_write_buckets_(bufev_p, res);
}
if (evbuffer_get_length(bufev->output) == 0) {
@@ -320,8 +320,8 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
* Invoke the user callback if our buffer is drained or below the
* low watermark.
*/
- if (res || !connected) {
- bufferevent_trigger_nolock_(bufev, EV_WRITE, 0);
+ if (res || !connected) {
+ bufferevent_trigger_nolock_(bufev, EV_WRITE, 0);
}
goto done;
@@ -334,10 +334,10 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
error:
bufferevent_disable(bufev, EV_WRITE);
- bufferevent_run_eventcb_(bufev, what, 0);
+ bufferevent_run_eventcb_(bufev, what, 0);
done:
- bufferevent_decref_and_unlock_(bufev);
+ bufferevent_decref_and_unlock_(bufev);
}
struct bufferevent *
@@ -347,15 +347,15 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd,
struct bufferevent_private *bufev_p;
struct bufferevent *bufev;
-#ifdef _WIN32
- if (base && event_base_get_iocp_(base))
- return bufferevent_async_new_(base, fd, options);
+#ifdef _WIN32
+ if (base && event_base_get_iocp_(base))
+ return bufferevent_async_new_(base, fd, options);
#endif
if ((bufev_p = mm_calloc(1, sizeof(struct bufferevent_private)))== NULL)
return NULL;
- if (bufferevent_init_common_(bufev_p, base, &bufferevent_ops_socket,
+ if (bufferevent_init_common_(bufev_p, base, &bufferevent_ops_socket,
options) < 0) {
mm_free(bufev_p);
return NULL;
@@ -364,9 +364,9 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd,
evbuffer_set_flags(bufev->output, EVBUFFER_FLAG_DRAINS_TO_FD);
event_assign(&bufev->ev_read, bufev->ev_base, fd,
- EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev);
+ EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev);
event_assign(&bufev->ev_write, bufev->ev_base, fd,
- EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev);
+ EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev);
evbuffer_add_cb(bufev->output, bufferevent_socket_outbuf_cb, bufev);
@@ -378,32 +378,32 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd,
int
bufferevent_socket_connect(struct bufferevent *bev,
- const struct sockaddr *sa, int socklen)
+ const struct sockaddr *sa, int socklen)
{
- struct bufferevent_private *bufev_p = BEV_UPCAST(bev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bev);
evutil_socket_t fd;
int r = 0;
int result=-1;
int ownfd = 0;
- bufferevent_incref_and_lock_(bev);
+ bufferevent_incref_and_lock_(bev);
fd = bufferevent_getfd(bev);
if (fd < 0) {
if (!sa)
goto done;
- fd = evutil_socket_(sa->sa_family,
- SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0);
+ fd = evutil_socket_(sa->sa_family,
+ SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0);
if (fd < 0)
- goto freesock;
+ goto freesock;
ownfd = 1;
}
if (sa) {
-#ifdef _WIN32
- if (bufferevent_async_can_connect_(bev)) {
+#ifdef _WIN32
+ if (bufferevent_async_can_connect_(bev)) {
bufferevent_setfd(bev, fd);
- r = bufferevent_async_connect_(bev, fd, sa, socklen);
+ r = bufferevent_async_connect_(bev, fd, sa, socklen);
if (r < 0)
goto freesock;
bufev_p->connecting = 1;
@@ -411,17 +411,17 @@ bufferevent_socket_connect(struct bufferevent *bev,
goto done;
} else
#endif
- r = evutil_socket_connect_(&fd, sa, socklen);
+ r = evutil_socket_connect_(&fd, sa, socklen);
if (r < 0)
goto freesock;
}
-#ifdef _WIN32
+#ifdef _WIN32
/* ConnectEx() isn't always around, even when IOCP is enabled.
* Here, we borrow the socket object's write handler to fall back
* on a non-blocking connect() when ConnectEx() is unavailable. */
if (BEV_IS_ASYNC(bev)) {
event_assign(&bev->ev_write, bev->ev_base, fd,
- EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bev);
+ EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bev);
}
#endif
bufferevent_setfd(bev, fd);
@@ -435,12 +435,12 @@ bufferevent_socket_connect(struct bufferevent *bev,
/* The connect succeeded already. How very BSD of it. */
result = 0;
bufev_p->connecting = 1;
- bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS);
+ bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS);
} else {
/* The connect failed already. How very BSD of it. */
result = 0;
- bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS);
- bufferevent_disable(bev, EV_WRITE|EV_READ);
+ bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS);
+ bufferevent_disable(bev, EV_WRITE|EV_READ);
}
goto done;
@@ -449,7 +449,7 @@ freesock:
if (ownfd)
evutil_closesocket(fd);
done:
- bufferevent_decref_and_unlock_(bev);
+ bufferevent_decref_and_unlock_(bev);
return result;
}
@@ -458,24 +458,24 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
void *arg)
{
struct bufferevent *bev = arg;
- struct bufferevent_private *bev_p = BEV_UPCAST(bev);
+ struct bufferevent_private *bev_p = BEV_UPCAST(bev);
int r;
BEV_LOCK(bev);
- bufferevent_unsuspend_write_(bev, BEV_SUSPEND_LOOKUP);
- bufferevent_unsuspend_read_(bev, BEV_SUSPEND_LOOKUP);
-
- bev_p->dns_request = NULL;
+ bufferevent_unsuspend_write_(bev, BEV_SUSPEND_LOOKUP);
+ bufferevent_unsuspend_read_(bev, BEV_SUSPEND_LOOKUP);
- if (result == EVUTIL_EAI_CANCEL) {
- bev_p->dns_error = result;
- bufferevent_decref_and_unlock_(bev);
- return;
- }
+ bev_p->dns_request = NULL;
+
+ if (result == EVUTIL_EAI_CANCEL) {
+ bev_p->dns_error = result;
+ bufferevent_decref_and_unlock_(bev);
+ return;
+ }
if (result != 0) {
bev_p->dns_error = result;
- bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0);
- bufferevent_decref_and_unlock_(bev);
+ bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0);
+ bufferevent_decref_and_unlock_(bev);
if (ai)
evutil_freeaddrinfo(ai);
return;
@@ -486,11 +486,11 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
while (found_ai->ai_addr->sa_family != AF_INET6 && found_ai->ai_next != NULL) {
found_ai = found_ai->ai_next;
}
- bufferevent_socket_set_conn_address_(bev, found_ai->ai_addr, (int)found_ai->ai_addrlen);
+ bufferevent_socket_set_conn_address_(bev, found_ai->ai_addr, (int)found_ai->ai_addrlen);
r = bufferevent_socket_connect(bev, found_ai->ai_addr, (int)found_ai->ai_addrlen);
- if (r < 0)
- bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0);
- bufferevent_decref_and_unlock_(bev);
+ if (r < 0)
+ bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0);
+ bufferevent_decref_and_unlock_(bev);
evutil_freeaddrinfo(ai);
}
@@ -500,7 +500,7 @@ bufferevent_socket_connect_hostname(struct bufferevent *bev,
{
char portbuf[10];
struct evutil_addrinfo hint;
- struct bufferevent_private *bev_p = BEV_UPCAST(bev);
+ struct bufferevent_private *bev_p = BEV_UPCAST(bev);
if (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC)
return -1;
@@ -512,27 +512,27 @@ bufferevent_socket_connect_hostname(struct bufferevent *bev,
hint.ai_protocol = IPPROTO_TCP;
hint.ai_socktype = SOCK_STREAM;
- evutil_snprintf(portbuf, sizeof(portbuf), "%d", port);
-
- BEV_LOCK(bev);
- bev_p->dns_error = 0;
-
- bufferevent_suspend_write_(bev, BEV_SUSPEND_LOOKUP);
- bufferevent_suspend_read_(bev, BEV_SUSPEND_LOOKUP);
+ evutil_snprintf(portbuf, sizeof(portbuf), "%d", port);
- bufferevent_incref_(bev);
- bev_p->dns_request = evutil_getaddrinfo_async_(evdns_base, hostname,
- portbuf, &hint, bufferevent_connect_getaddrinfo_cb, bev);
- BEV_UNLOCK(bev);
+ BEV_LOCK(bev);
+ bev_p->dns_error = 0;
- return 0;
+ bufferevent_suspend_write_(bev, BEV_SUSPEND_LOOKUP);
+ bufferevent_suspend_read_(bev, BEV_SUSPEND_LOOKUP);
+
+ bufferevent_incref_(bev);
+ bev_p->dns_request = evutil_getaddrinfo_async_(evdns_base, hostname,
+ portbuf, &hint, bufferevent_connect_getaddrinfo_cb, bev);
+ BEV_UNLOCK(bev);
+
+ return 0;
}
int
bufferevent_socket_get_dns_error(struct bufferevent *bev)
{
int rv;
- struct bufferevent_private *bev_p = BEV_UPCAST(bev);
+ struct bufferevent_private *bev_p = BEV_UPCAST(bev);
BEV_LOCK(bev);
rv = bev_p->dns_error;
@@ -571,11 +571,11 @@ bufferevent_new(evutil_socket_t fd,
static int
be_socket_enable(struct bufferevent *bufev, short event)
{
- if (event & EV_READ &&
- bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1)
+ if (event & EV_READ &&
+ bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1)
return -1;
- if (event & EV_WRITE &&
- bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1)
+ if (event & EV_WRITE &&
+ bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1)
return -1;
return 0;
}
@@ -583,7 +583,7 @@ be_socket_enable(struct bufferevent *bufev, short event)
static int
be_socket_disable(struct bufferevent *bufev, short event)
{
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
if (event & EV_READ) {
if (event_del(&bufev->ev_read) == -1)
return -1;
@@ -599,16 +599,16 @@ be_socket_disable(struct bufferevent *bufev, short event)
static void
be_socket_destruct(struct bufferevent *bufev)
{
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
evutil_socket_t fd;
- EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
+ EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
fd = event_get_fd(&bufev->ev_read);
if ((bufev_p->options & BEV_OPT_CLOSE_ON_FREE) && fd >= 0)
EVUTIL_CLOSESOCKET(fd);
- evutil_getaddrinfo_cancel_async_(bufev_p->dns_request);
+ evutil_getaddrinfo_cancel_async_(bufev_p->dns_request);
}
static int
@@ -622,27 +622,27 @@ be_socket_flush(struct bufferevent *bev, short iotype,
static void
be_socket_setfd(struct bufferevent *bufev, evutil_socket_t fd)
{
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
-
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+
BEV_LOCK(bufev);
- EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
+ EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
event_del(&bufev->ev_read);
event_del(&bufev->ev_write);
- evbuffer_unfreeze(bufev->input, 0);
- evbuffer_unfreeze(bufev->output, 1);
-
+ evbuffer_unfreeze(bufev->input, 0);
+ evbuffer_unfreeze(bufev->output, 1);
+
event_assign(&bufev->ev_read, bufev->ev_base, fd,
- EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev);
+ EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev);
event_assign(&bufev->ev_write, bufev->ev_base, fd,
- EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev);
+ EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev);
if (fd >= 0)
bufferevent_enable(bufev, bufev->enabled);
- evutil_getaddrinfo_cancel_async_(bufev_p->dns_request);
-
+ evutil_getaddrinfo_cancel_async_(bufev_p->dns_request);
+
BEV_UNLOCK(bufev);
}
@@ -651,7 +651,7 @@ int
bufferevent_priority_set(struct bufferevent *bufev, int priority)
{
int r = -1;
- struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
+ struct bufferevent_private *bufev_p = BEV_UPCAST(bufev);
BEV_LOCK(bufev);
if (BEV_IS_ASYNC(bufev) || BEV_IS_FILTER(bufev) || BEV_IS_PAIR(bufev))
@@ -662,8 +662,8 @@ bufferevent_priority_set(struct bufferevent *bufev, int priority)
if (event_priority_set(&bufev->ev_write, priority) == -1)
goto done;
- event_deferred_cb_set_priority_(&bufev_p->deferred, priority);
-
+ event_deferred_cb_set_priority_(&bufev_p->deferred, priority);
+
r = 0;
done:
BEV_UNLOCK(bufev);
@@ -677,7 +677,7 @@ bufferevent_base_set(struct event_base *base, struct bufferevent *bufev)
int res = -1;
BEV_LOCK(bufev);
- if (!BEV_IS_SOCKET(bufev))
+ if (!BEV_IS_SOCKET(bufev))
goto done;
bufev->ev_base = base;