In this case client can't connect to server, and this bring to the front some
bugs with assigning on already added events (because of ```fd_is_set``` stuff),
for more info see #258, since this is the reproducible for it.
This makes the code build on other systems that also don't have
SO_REUSEADDR without requiring special code.
[ azat: partially revert WIN32 check since SO_REUSEADDR on win32 differs from
unix semantics. ]
Closes#275
On both Android and Ubuntu machines, TAILQ_END is not defined. This
header also does not seem to be part of standard BSD sys/queue.h
Fix this by always defining missing TAILQ_ macros rather than
conditioning on a particular macro.
Fixes#267
These types are not part of POSIX. As we only use them in a small number
of places, we'd better replace them by C standard types. This makes a
larger part of the code build for CloudABI.
Systems like CloudABI implement kqueue() but do not provide the
BSD-specific TIMEVAL_TO_TIMESPEC() macro. Change the code to perform
this manually, as it is not hard to do this conversion.
There is regression tests and also this code worked/tested during crawling a
huge number of pages (billions).
* reuse-conn_address-on-retry-v11:
be_sock: bufferevent_socket_set_conn_address(): assert instead of silent no-op
http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR
be_sock: sanity check in bufferevent_socket_set_conn_address()
be: replace sockaddr_storage with sockaddr_in6 for conn_address
be: we don't need to use getpeername() we we have conn_address
be: replace conn_address by full struct instead of pointer
test/http: cover retrying with saved conn_address by shutting down dns server
http: use IP address that we got before (if any) during retrying
bufferevent: move conn_address out from http into bufferevent
be: make @sa const for bufferevent_socket_connect()
util: make @sa const for evutil_socket_connect_()
We need only ipv6/ipv4 for connect in bufferevent, and since
sockaddr_storage is pretty big (128 bytes) it will be better to use
sockaddr_in6 here (it will fit ipv4 too).
Before this patch every time we are retrying our request we resolve
domain, but we could optimize this (since UDP is slow) by using cached
conn_address value, so do this.
In http the only case when when we could store it is when we already
connected, *but* if we are doing request using domain name, then we need
to do request to nameserver to get IP address, and this is handled by
bufferevent.
So when we have IP address (from nameserver) and don't have connection
to this IP address, we could already cache it to avoid extra DNS
requests (since UDP is slow), and we can't do this from http layer, only
from bufferevent.
- A handy event_enable_debug_mode() feature which will error and abort the
application if any thread-aware libevent functions are called BEFORE the
evthread API has been initialized (manually, or through
evthread_use_windows_threads() / evthread_use_pthreads()
- This is done by setting the global debug variable
'event_debug_created_threadable_ctx_' whenever the following functions
are called:
evthreadimpl_lock_alloc_()
evthreadimpl_cond_alloc_()
event_base_new_with_config() <- this checks to see if the thread
callbacks are enabled first, so we
have to manually set the variable.
- Example:
int main(int argc, char ** argv) {
struct event_base * base;
event_enable_debug_mode();
base = event_base_new();
evthread_use_pthreads();
return 0;
}
When executed, the program will throw an error and exit:
[err] evthread initialization must be called BEFORE anything else!