577 Commits

Author SHA1 Message Date
Azat Khuzhin
30f2a969e8 cmake: eliminate EVENT_BUILDING_REGRESS_TEST, since we link with shared libs
Before 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED
and STATIC libraries (like autoconf does)") it links with *.c.
2017-03-14 00:33:37 +03:00
Azat Khuzhin
7182c2f561 cmake: build SHARED and STATIC libraries (like autoconf does)
Since they are useful for debugging, and if autotools build them then
cmamke has to do this too, to make migration more simple.

And now:
- tests: uses shared libraries (since this is upstreams one)
- other binaries: uses static libraries

This removes next private config:
- EVENT__NEED_DLLIMPORT
2017-03-13 16:20:40 +03:00
Azat Khuzhin
72ef9d1652 cmake: add missing event_openssl/event_pthreads libraries
This will remove openssl requirement if you don't use it (i.e. if you
not link with openssl_pthreads).

Plus it fixes some linking dependencies:
- libm required only for test-ratelim

And fix some coding style alignment issues.

Refs: #246
2017-03-13 12:57:22 +03:00
Azat Khuzhin
9081b66c9c Export symbols for -fvisibility=hidden (under cmake)
Fixes: #442
2017-03-13 12:57:22 +03:00
Marek Sebera
6541168d70 Detect arch4random_addrandom() existence
Refs: #370
Refs: #475
2017-03-08 13:31:55 +03:00
Azat Khuzhin
4545807db4 Fix UB in evutil_date_rfc1123()
As pointed in https://github.com/libevent/libevent/pull/417#issuecomment-267860738
  "code is unsafe because in evutil_date_rfc1123() the pointer to the
  automatic variable struct tm cur is used outside the scope it defined."

Checked with `clang -fsanitize=address -fsanitize-address-use-after-scope`
and test that call evutil_date_rfc1123() with tm==NULL
2016-12-22 14:46:38 +03:00
Vis Virial
db60ade81d http: do not use local settings for Date header 2016-12-19 00:55:50 +03:00
Thomas Bernard
e983712456 use ev_uint16_t instead of unsigned short for port
Like in `sockaddr_in` structure in /usr/include/netinet/in.h

@azat: convert all other users (bench, compat, ..) and tweak message
Fixes: #178
Fixes: #196
Refs: 6bf1ca78
Link: https://codereview.appspot.com/156040043/#msg4
2016-10-26 01:41:13 +03:00
Mark Ellzey
303161777d
[#372] check for errno.h 2016-06-28 10:37:24 -07:00
Azat Khuzhin
9fde5189df http: lingering close (like nginx have) for entity-too-large
By lingering close I mean something what nginx have for this name, by this term
I mean that we need to read all the body even if it's size greater then
`max_body_size`, otherwise browsers on win32 (including chrome) failed read the
http status - entity-too-large (while on linux chrome for instance are good),
and also this includes badly written http clients.

Refs: #321

v2: do this only under EVHTTP_SERVER_LINGERING_CLOSE
2016-03-09 18:52:07 +03:00
Azat Khuzhin
680742e166 http: read server response even after server closed the connection
Otherwise if we will try to write more data than server can accept
(see `evhttp_set_max_body_size()` for libevent server) we will get `EPIPE` and
will not try to read server's response which must contain 400 error for now
(which is not strictly correct though, it must 413).
```
  $ strace regress --no-fork http/data_length_constraints
  ...
  connect(10, {sa_family=AF_INET, sin_port=htons(43988), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
  ...
  writev(10, [{"POST / HTTP/1.1\r\nHost: somehost\r"..., 60}, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 16324}], 2) = 16384
  epoll_wait(5, [{EPOLLOUT, {u32=10, u64=10}}, {EPOLLIN, {u32=11, u64=11}}], 32, 50000) = 2
  writev(10, [{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 16384}], 1) = 16384
  ioctl(11, FIONREAD, [32768])            = 0
  readv(11, [{"POST / HTTP/1.1\r\nHost: somehost\r"..., 4096}], 1) = 4096
  epoll_ctl(5, EPOLL_CTL_DEL, 11, 0x7fff09d41e50) = 0
  epoll_ctl(5, EPOLL_CTL_ADD, 11, {EPOLLOUT, {u32=11, u64=11}}) = 0
  epoll_wait(5, [{EPOLLOUT, {u32=10, u64=10}}, {EPOLLOUT, {u32=11, u64=11}}], 32, 50000) = 2
  writev(10, [{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 16384}], 1) = 16384
  writev(11, [{"HTTP/1.1 400 Bad Request\r\nConten"..., 129}, {"<HTML><HEAD>\n<TITLE>400 Bad Requ"..., 94}], 2) = 223
  epoll_ctl(5, EPOLL_CTL_DEL, 11, 0x7fff09d42080) = 0
  shutdown(11, SHUT_WR)                   = 0
  close(11)                               = 0
  epoll_wait(5, [{EPOLLOUT|EPOLLERR|EPOLLHUP, {u32=10, u64=10}}], 32, 50000) = 1
  writev(10, [{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 16384}], 1) = -1 EPIPE (Broken pipe)
  --- SIGPIPE {si_signo=SIGPIPE, si_code=SI_USER, si_pid=13954, si_uid=1000} ---
  epoll_ctl(5, EPOLL_CTL_DEL, 10, 0x7fff09d42010) = 0
  shutdown(10, SHUT_WR)                   = -1 ENOTCONN (Transport endpoint is not connected)
  close(10)                               = 0
  write(1, "\n  FAIL ../test/regress_http.c:3"..., 37
```
Careful reader can ask why it send error even when it didn't read
`evcon->max_body_size`, and the answer will be checks for `evcon->max_body_size
against `Content-Length` header, which contains ~8MB (-2 bytes).

And also if we will not drain the output buffer than we will send buffer that
we didn't send in previous request and instead of sending method via
`evhttp_make_header()`.

Fixes: http/data_length_constraints
Refs: #321

v2: do this only under EVHTTP_CON_READ_ON_WRITE_ERROR flag
2016-03-09 01:12:50 +03:00
Azat Khuzhin
4dc09795c0 http: fix conflicts EVHTTP_CON_AUTOFREE and EVHTTP_CON_REUSE_CONNECTED_ADDR
And we can't make them continuous, since the latest is a public API, and
otherwise we will break binary compatibility.
Also extra check for EVHTTP_CON_PUBLIC_FLAGS_END, in case somebody forgot about
this (implementer I mean).

Refs: #182
2016-02-24 14:22:31 +03:00
Azat Khuzhin
bb6b53d031 visibility: align it to make it more readable 2016-01-12 01:36:35 +03:00
Mark Ellzey
a264da8671 Revert "The Windows socket type is defined as SOCKET." 2015-12-20 00:57:50 -08:00
billsegall
c9e6c3d70f The Windows socket type is defined as SOCKET.
Under the hood it's an unsigned rather than a signed type and whilst C
compilers are largely happy with this C++ compilers tend to be fussy
about class function signatures which makes C++ usage of libevent
problematic.
2015-12-16 11:17:36 +10:00
Azat Khuzhin
575ff67885 buffer_compat: fix comment -- we have EVBUFFER_EOL_ANY not EOL_STYLE_ANY 2015-10-30 01:34:40 +03:00
Azat Khuzhin
714fc70500 http: export evhttp_connection_set_family()
Fixes #176
2015-09-10 11:46:30 +03:00
Azat Khuzhin
a50f5f0ac0 http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR 2015-08-18 20:06:53 +03:00
Azat Khuzhin
8bb3842552 bufferevent: move conn_address out from http into bufferevent
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.
2015-08-18 20:06:52 +03:00
Azat Khuzhin
dc33c78391 be: make @sa const for bufferevent_socket_connect() 2015-08-18 20:06:52 +03:00
Mark Ellzey
043ae7481f Fix garbage value in socketpair util function, stdint?
* Fixed an issue with evutil_ersatz_socketpair_, listen_addr could all
  be compared against with agarbage values. So just memset it before
  using it anywhere.

* Nick might punch me in the face, but if we have stdint.h; (as in
  EVENT__HAVE_STDINT_H is defined), might as well use those instead of
  the manual [U]INT[X}_MAX/MIN muck in there now.
2015-05-11 12:06:01 -04:00
Mark Ellzey
1ed6718d1d expose bufferevent_incref/decref (with fewer modifications) 2015-05-06 14:56:31 -07:00
Nick Mathewson
1cae3ae167 Merge remote-tracking branch 'public/master' 2015-02-02 13:57:50 -05:00
Nick Mathewson
537177d315 New function to get address for nameserver. 2015-02-02 13:57:22 -05:00
jer-gentoo
8674e4fb0a EVBUFFER_PTR_SET -> EVBUFFER_PTR_ADD
Looks like EVBUFFER_PTR_ADD should have been used instead of EVBUFFER_PTR_SET.
2015-01-21 11:24:23 +01:00
Andrea Shepard
f2645f80c1 Implement new/free for struct evutil_monotonic_timer and export monotonic time functions 2014-12-04 09:30:20 -05:00
Nick Mathewson
7fd4941465 Merge remote-tracking branch 'origin/pr/182' 2014-11-30 19:26:20 -05:00
Nick Mathewson
23133cacc8 Merge remote-tracking branch 'origin/pr/180' 2014-11-30 19:25:21 -05:00
John Ohl
2b9ec4c13c Implement interface that provides the ability to have an outbound evhttp_connection free itself once all requests have completed 2014-10-26 01:25:28 -04:00
Jean-Philippe Ouellet
b361b8a656 remove trailing comma from enum
makes being included from something with -std=c89 happy
2014-10-16 22:56:49 -04:00
Maciej Soltysiak
b625361a6a Provide support for SO_REUSEPORT through LEV_OPT_REUSABLE_PORT 2014-10-13 17:28:14 +02:00
Nick Mathewson
0fb71c35dc Merge remote-tracking branch 'origin/patches-2.0' 2014-10-09 10:14:30 -04:00
Nick Mathewson
be1aeff21a Fix a typo in a doxygen comment. Reported by 亦得. 2014-10-09 10:14:12 -04:00
Nick Mathewson
c243dbf4c8 Merge pull request #168 from ufo2243/master
make bufferevent_getwatermark api more robust
2014-09-18 11:44:11 -04:00
Nick Mathewson
73615a3723 Merge pull request #118 from azat/http-forward-family-to-bufferevent
Add evhttp_connection_set_family() to set addrinfo->family for DNS requests
2014-09-18 11:31:52 -04:00
ufo2243
a21e5108c2 make bufferevent_getwatermark api more robust 2014-09-12 11:51:59 +08:00
Azat Khuzhin
12c29b0f6e Add evhttp_connection_set_family() to set addrinfo->family for DNS requests
This is useful if you want to avoid extra dns requests.
2014-03-21 17:32:09 +04:00
Nick Mathewson
58408eedd8 Fix duplicate paragraph in evbuffer_ptr documentation 2014-03-12 14:06:02 -04:00
Trond Norbye
4545fa9b68 Add option to build shared library 2014-02-25 14:57:24 +01:00
Nick Mathewson
53d279389a Expand EV_CLOSED documentation a bit 2014-01-21 15:44:05 -05:00
Diego Giagio
b1b69ac7c1 Implemented EV_CLOSED event for epoll backend (EPOLLRDHUP).
- Added new EV_CLOSED event - detects premature connection close
  by clients without the necessity of reading all the pending
  data. Does not depend on EV_READ and/or EV_WRITE.

- Added new EV_FEATURE_EARLY_CLOSED feature for epoll.
  Must be supported for listening to EV_CLOSED event.

- Added new regression test: test-closed.c

- All regression tests passed (test/regress and test/test.sh)

- strace output of test-closed using EV_CLOSED:
    socketpair(PF_LOCAL, SOCK_STREAM, 0, [6, 7]) = 0
    sendto(6, "test string\0", 12, 0, NULL, 0) = 12
    shutdown(6, SHUT_WR)                    = 0
    epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0
    epoll_wait(3, {{EPOLLRDHUP, {u32=7, u64=7}}}, 32, 3000) = 1
    epoll_ctl(3, EPOLL_CTL_MOD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0
    fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...})
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYM...
    write(1, "closed_cb: detected connection close "..., 45) = 45
2014-01-17 23:20:42 -02:00
Nick Mathewson
8d15f57f61 Merge remote-tracking branch 'asweeny86/on-complete-cb' 2014-01-07 16:59:26 -05:00
Andrew Sweeney
da86dda951 evhttp_request_set_on_complete_cb to be more specific about what the function actually does and usage 2014-01-06 20:36:31 -05:00
Nick Mathewson
f9e091bf4e Merge remote-tracking branch 'asweeny86/event-count-max' 2014-01-06 12:11:30 -05:00
Andrew Sweeney
b083ca0551 Provide on request complete callback facility
This patch provides the ability to receive a callback on the completion of a
request.  The callback takes place immediately before the request's resources
are released.
2014-01-05 20:35:46 -05:00
Andrew Sweeney
5173bef50f Add access to max event count stats
This commit provides an interface for accessing and resetting the maximum
number of events in a given period.  This information provides better insight
into event queue pressure.
2013-12-30 14:06:20 -05:00
Nick Mathewson
471fbe3baf Merge remote-tracking branch 'rbalint/from-forked-daapd' 2013-12-24 12:27:24 -05:00
Nick Mathewson
a3172a415b Minor optimizations on bufferevent_trigger options
By making BEV_TRIG_DEFER_CALLBACKS equal to BEV_OPT_DEFER_CALLBACKS,
and BEV_TRIG_IGNORE_WATERMARKS disjoint from BEV_OPT_*, we can save a
few operations in bufferevent_run_*, which is critical-path.
2013-12-24 11:30:06 -05:00
Nick Mathewson
b4ef3def6f Merge remote-tracking branch 'mistotebe/bufferevent_trigger' 2013-12-24 10:33:58 -05:00
Nick Mathewson
87fa2b004a Unit tests for active_by_fd; unsupport active_by_fd(TIMEOUT)
[It turns out that event_base_active_by_fd(TIMEOUT) didn't actually
work right. Feel free to add it back in as a patch.]
2013-12-23 20:46:38 -05:00