mirror of
https://github.com/cuberite/libevent.git
synced 2025-08-04 01:36:23 -04:00
Suspend read/write on bufferevents during hostname lookup
When we're doing a lookup in preparation for doing a connect, we might have an unconnected socket on hand, and mustn't actually do any reading or writing with it.
This commit is contained in:
parent
4faeaea90e
commit
db08f640d5
@ -53,6 +53,9 @@ extern "C" {
|
|||||||
#define BEV_SUSPEND_BW 0x02
|
#define BEV_SUSPEND_BW 0x02
|
||||||
/* On a base bufferevent: when we have emptied the group's bandwidth bucket. */
|
/* On a base bufferevent: when we have emptied the group's bandwidth bucket. */
|
||||||
#define BEV_SUSPEND_BW_GROUP 0x04
|
#define BEV_SUSPEND_BW_GROUP 0x04
|
||||||
|
/* On a socket bufferevent: can't do any operations while we're waiting for
|
||||||
|
* name lookup to finish. */
|
||||||
|
#define BEV_SUSPEND_LOOKUP 0x08
|
||||||
|
|
||||||
struct bufferevent_rate_limit_group {
|
struct bufferevent_rate_limit_group {
|
||||||
/** List of all members in the group */
|
/** List of all members in the group */
|
||||||
|
@ -417,6 +417,9 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
|
|||||||
int r;
|
int r;
|
||||||
BEV_LOCK(bev);
|
BEV_LOCK(bev);
|
||||||
|
|
||||||
|
bufferevent_unsuspend_write(bev, BEV_SUSPEND_LOOKUP);
|
||||||
|
bufferevent_unsuspend_read(bev, BEV_SUSPEND_LOOKUP);
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
/* XXX Communicate the error somehow. */
|
/* XXX Communicate the error somehow. */
|
||||||
_bufferevent_run_eventcb(bev, BEV_EVENT_ERROR);
|
_bufferevent_run_eventcb(bev, BEV_EVENT_ERROR);
|
||||||
@ -452,15 +455,21 @@ bufferevent_socket_connect_hostname(struct bufferevent *bev,
|
|||||||
hint.ai_protocol = IPPROTO_TCP;
|
hint.ai_protocol = IPPROTO_TCP;
|
||||||
hint.ai_socktype = SOCK_STREAM;
|
hint.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
bufferevent_suspend_write(bev, BEV_SUSPEND_LOOKUP);
|
||||||
|
bufferevent_suspend_read(bev, BEV_SUSPEND_LOOKUP);
|
||||||
|
|
||||||
bufferevent_incref(bev);
|
bufferevent_incref(bev);
|
||||||
err = evutil_getaddrinfo_async(evdns_base, hostname, portbuf,
|
err = evutil_getaddrinfo_async(evdns_base, hostname, portbuf,
|
||||||
&hint, bufferevent_connect_getaddrinfo_cb, bev);
|
&hint, bufferevent_connect_getaddrinfo_cb, bev);
|
||||||
|
|
||||||
if (err == 0)
|
if (err == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
|
bufferevent_unsuspend_write(bev, BEV_SUSPEND_LOOKUP);
|
||||||
|
bufferevent_unsuspend_read(bev, BEV_SUSPEND_LOOKUP);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new buffered event object.
|
* Create a new buffered event object.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user