658 Commits

Author SHA1 Message Date
Greg Hazel
9652fe0f79
add const qualifier to evhttp_uri_join declaration
Signed-off-by: Kirill Rodriguez <theoden8@gmail.com>
2017-05-15 00:36:47 -07:00
Kirill Rodriguez
a92ce7e111
moved EVHTTP_ flags to http.c 2024-10-29 11:26:35 +00:00
Kirill Rd
e30b215f34
Add caching for evdns (#1717)
No evdns will do caching by default (with respect to TTL), to disable this set EVDNS_BASE_NO_CACHE

There are also helpers for manually manage the cache:
- evdns_cache_write()
- evdns_cache_lookup()

Initial PR: #571
Fixes: #1715

Co-authored-by: Greg Hazel <ghazel@gmail.com>
Co-authored-by: Keith Moore <kmoore@clostra.com>
2024-10-24 08:28:53 +02:00
James
267e808eb7
Updated documentation for bufferevent_setcb() (#1733)
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
2024-10-23 22:54:31 +02:00
Wu, Zhenyu
8f1e4bd937 fix typo: bufferevent_set_callbacks should be bufferevent_setcb 2024-10-03 10:15:06 +03:00
Orian
bb0d473bbb Add small note to event_active() documentation 2024-09-15 00:08:41 +03:00
icy17
0499c51753
Document non-NULL parameters in public API (#1705) 2024-08-04 23:23:43 +02:00
Andy Pan
96c259f1d9
tcpkeepalive: distinguish OS versions and use proper time units (#1669)
DragonFly BSD changed the time unit for TCP keep-alive from milliseconds to seconds since v5.8 and Solaris 11.4 added `TCP_KEEPIDLE`, `TCP_KEEPINTVL`, and `TCP_KEEPCNT` with time units in second while Solaris <11.4 still use `TCP_KEEPALIVE_THRESHOLD` and `TCP_KEEPALIVE_ABORT_THRESHOLD` with time units in millisecond.

Currently, we don't differentiate among DragonFly BSD versions but set the keepalive options with seconds, which will result in unexpected behaviors on DragonFlyBSD <5.8. This PR intends to fix the wrong usage of time units of TCP keepalive options on DragonFly BSD <5.8 and consolidate the logic of time units conversion for TCP keepalive across platforms.

In addition, this PR introduces a new custom macro for determining Solaris 11.4. This macro is expected to help us implement some new features for `libuv` using some abilities that only exist on Solaris 11.4 and other mainstream platforms in the future, considering that Oracle developed and released Solaris 11.4 to replenish plenty of features on Solaris that have already been implemented on other UNIX-like OSs but missing from Solaris <11.4, also bring a good deal of new features.
### References

- [Change tcp keepalive options from ms to seconds (DISRUPTIVE)](https://lists.dragonflybsd.org/pipermail/commits/2019-July/719125.html)
- [DragonFly BSD 5.8 release notes](https://www.dragonflybsd.org/release58/)
- [DragonFly TCP](https://man.dragonflybsd.org/?command=tcp&section=4)
- [Solaris 11.3 TCP](https://docs.oracle.com/cd/E86824_01/html/E54777/tcp-7p.html)
- [Solaris 11.4 TCP](https://docs.oracle.com/cd/E88353_01/html/E37851/tcp-4p.html)
- [Solaris 11.4 release notes](https://docs.oracle.com/cd/E37838_01/html/E60973/)

Signed-off-by: Andy Pan <i@andypan.me>
2024-06-26 06:10:00 +02:00
Andy Pan
832f52692e aix: enable SO_REUSEPORT on AIX
AIX 7.2.5 added the feature that would add the capability
to distribute incoming connections across all listening ports.

https://www.ibm.com/support/pages/how-get-better-listening-performance-multiple-listening-sockets-using-same-port-number-soreuseport

---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-05-18 16:57:54 +03:00
Cœur
eec47a6710
Fix typos (#1634) 2024-04-30 09:59:58 +02:00
Andy Pan
cbbf209c08
Support SO_REUSEPORT on FreeBSD, DragonFly and Solaris (#1624)
## References

- [The SO_REUSEPORT socket option on Linux](https://lwn.net/Articles/542629/)
- [DragonFly Release 3.6](https://www.dragonflybsd.org/release36/)
- [FreeBSD 12.0-RELEASE Release Notes](https://www.freebsd.org/releases/12.0R/relnotes/)
- [SO_REUSEPORT on Solaris 11.4](https://docs.oracle.com/cd/E88353_01/html/E37843/setsockopt-3c.html)

Co-authored-by: Azat Khuzhin <azat@libevent.org>
2024-04-29 07:31:34 +02:00
Cœur
73c0349ed4
Fix evutil_parse_sockaddr_port documentation (#1628)
In some IDE like Xcode, the list is interpreted as markdown instead of plain text
2024-04-29 07:16:58 +02:00
Azat Khuzhin
539f73e319 Fix leak in evbuffer_add_file() on empty files
Found by oss-fuzz, after coverage had been improved in google/oss-fuzz#11257
v2: adjust test
v3: fix for windows (_get_osfhandle() crashes when called on closed fd)
v4: fix for EVENT__DISABLE_MM_REPLACEMENT
2024-03-12 09:29:47 +01:00
tgolang
9c8860ec6c chore: remove repetitive words
Signed-off-by: tgolang <seekseat@aliyun.com>
2024-03-11 09:18:25 +01:00
Andy Pan
e66df92cfc
Accept SOCK_NONBLOCK/SOCK_CLOEXEC in type argument of socketpair (#1567)
Setting `SOCK_NONBLOCK` and `SOCK_CLOEXEC` in the `type` argument of `socketpair()` is widely supported across UNIX-like OS: Linux, *BSD, Solaris, etc., as is the `socket()`. This will conserve several extra system calls, we should use it where available.

### References

- [socketpair(2) on Linux](https://man7.org/linux/man-pages/man2/socketpair.2.html#HISTORY)
- [socketpair(2) on FreeBSD](https://man.freebsd.org/cgi/man.cgi?query=socketpair&sektion=2#DESCRIPTION)
- [socketpair(2) on DragonFly](https://man.dragonflybsd.org/?command=socketpair&section=2)
- [socketpair(2) on NetBSD](https://man.netbsd.org/socketpair.2#DESCRIPTION)
- [socketpair(2) on OpenBSD](https://man.openbsd.org/socketpair.2)
- [socketpair(3C) on Solaris](https://docs.oracle.com/cd/E88353_01/html/E37843/socketpair-3c.html)

Changelog:
- Set SOCK_NONBLOCK and SOCK_CLOEXEC in the type argument of socketpair
- Avoid EPROTOTYPE on macOS and OpenBSD
- Eliminate the warnings about unused variables
- Add some comments
2024-03-07 09:19:11 +01:00
Azat Khuzhin
d9b5fe318a evrpc: proper NULL checks (API function return value added)
Note, that in order to do this evrpc_hook_add_meta() should have return
value, so this is a minor ABI change, which should not affect C ABI, but
still worth to mention.

Anyway this will be done in 2.2 release and unlikely RPC subsystem is
popular.
2024-02-18 19:48:55 +01:00
Andy Pan
9d4853b363
Optimize preprocessor directives on Solaris for evutil_set_tcp_keepalive (#1536)
Changes:
- Optimize preprocessor directives on Solaris for evutil_set_tcp_keepalive
- Reduce the amount of code being compiled and trim trailing whitespace in passing.
- Move comments for Solaris under its macro
- Refactor the control flow
2024-01-13 15:51:49 +03:00
Andy Pan
7658b78853
Implement full support of TCP Keep-Alives across most Unix-like OS's (#1532)
Default settings of TCP keep-alive are not always feasible,
take Linux for example, the duration a connection needs to be
idle before sending out the first keep-alive probe is two hours,
which makes detecting dead connections extremely deferred. Thus,
enabling TCP keep-alive will be to little avail.

This sets TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT when enabling TCP
keep-alive mechanism to make it practicable.
2024-01-05 19:52:43 +03:00
Faraz Vahedi
7f5b8f1909 Fix documentation inconsistency in evhttp callbacks
This commit addresses a minor inconsistency identified in the
documentation of multiple `evhttp` callback functions within
the `event2/http.h` header file. It was observed that the word
"additional" was presumably missing in the description of the
`arg` parameter for several functions. This oversight led to
an incorrect phrasing: "an context argument for the callback."

The documentation for the following functions has been updated
to rectify this issue:

  - `evhttp_set_gencb`
  - `evhttp_set_bevcb`
  - `evhttp_set_newreqcb`
  - `evhttp_set_errorcb`

This commit solely improves the readability of the function
descriptions without altering any functional aspects of the
code.
2023-11-25 18:34:32 +01:00
Azat Khuzhin
c2a935b5c7 Add a comment for evbuffer_ref_cleanup_cb 2023-09-22 09:35:07 +02:00
MBeanwenshengming
648ec50e11 Add function evbuffer_add_reference_with_offset()
This is the same as evbuffer_add_reference(), but allows to specify
offset in the @data

v2: rename evbuffer_add_reference_misalign() to evbuffer_add_reference_with_offset()
2023-09-21 22:02:26 +02:00
Dmitry Ilyin
f39ad1c494
ws: replace evws_send with evws_send_text/evws_send_binary (ABI breakage) (#1500)
Replace evws_send with evws_send_text, and introduce new API -
evws_send_binary, that can be used to send binary frames.

But note, that this commit breaks the ABI compatibility, but it should be OK,
since there was only alpha release with evws_send, and nobody should rely on
this, and I hope nobody does (we decided to go this way to avoid supporting
deprecated API).
2023-08-31 21:38:41 +02:00
Azat Khuzhin
57d9eec641 Disable signalfd by default
signalfd may behave differently to sigaction/signal, so to avoid
breaking libevent users (like [1], [2]) disable it by default.

  [1]: https://github.com/tmux/tmux/pull/3621
  [2]: https://github.com/tmux/tmux/pull/3626

Also signalfd is not that perfect:
- you need to SIG_BLOCK the signal before
  - blocked signals are not reset on exec
  - blocked signals are allowed to coalesce - so in case of multiple
    signals sent you may get the signal only once (ok for most of the
    signals, but may be a problem for SIGCHLD, though you may call
    waitpid() in a loop or use pidfd)
- and also one implementation problem -
  sigprocmask is unspecified in a multithreaded process

Refs:
- https://lwn.net/Articles/415684/
- https://ldpreload.com/blog/signalfd-is-useless

Refs: https://github.com/libevent/libevent/issues/1460
Refs: #1342 (cc @dmantipov)
2023-07-13 21:21:09 +02:00
Q_uan
57bb630ce3 Add __cplusplus in ws.h to fix compilation errors when using c++ compiler 2023-06-20 12:16:59 +03:00
Kurt Roeckx
4e6375e84c
Always have evutil_secure_rng_add_bytes available (#1427)
When libevent doesn't provide random the arc4 function, but they come from libc, there is no need to call this function, so make it do nothing.

Fixes: #1393
2023-03-05 16:56:56 +01:00
Edoardo Lolletti
f9134df7d0
Add LEV_OPT_BIND_IPV4_AND_IPV6 flag (#1400)
Libevent introduced the LEV_OPT_BIND_IPV6ONLY to pass to evconnlistener_new_bind to make it automatically set the underlying socket as accepting ipv6 requests. This works fine on posix compliant platforms as by the standard every new AF_INET6 socket is created as both supporting ipv6 and ipv4 connections. But on windows the default is the opposite, with the flag IPV6_V6ONLY  being always enabled by default.

This makes creating a listener to supports both protocols a bit more tricky as winsock doesn't allow changing this flag after evconnlistener_new_bind does all the initial setup because as stated in the docs, you can't change it after the sonnect connected, so one would have to manually create the socket beforehand and set the flag and then call evconnlistener_new with the socket itself.

It would be nice to have libevent keep a consistent behaviour across the platforms in this scenario, maybe or by making it always set IPV6_V6ONLY  to false unless LEV_OPT_BIND_IPV6ONLY is passed, in which case it's set to true, or add another flag to forcefully set it to false and keep the system dependent behaviour as default.

So this patch add new option for libevent listeners to bind to both - LEV_OPT_BIND_IPV4_AND_IPV6
2023-02-04 15:00:48 +01:00
Daniel Kempenich
a7fffb5c0f Replace magic numbers with consts for evdns_base_resolv_conf_parse() errors 2023-01-27 08:47:01 +01:00
Dmitry Antipov
1af745d033 signal: new signal handling backend based on signalfd
Linux-specific signal handling backend based on signalfd(2)
system call, and public function event_base_get_signal_method()
to obtain an underlying kernel signal handling mechanism.

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2022-11-12 21:14:48 +01:00
Dmitry Ilyin
c2ecb4acb5 Add locks for server WS, fixes #1357 2022-10-12 14:13:44 +03:00
Dmitry Ilyin
88317a4ef8 Add helpers and all regress tests are passed 2022-10-04 17:49:22 +03:00
Dmitry Ilyin
e8313084f9
Add minimal WebSocket server implementation for evhttp (#1322)
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.

Implementation was inspired by modified Libevent source code in ipush project
[1].

  [1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable

Also, WebSocket-based chat server was added as a sample.
2022-09-12 22:16:56 +03:00
Leon M. George
1bdc91350e http: allow setting bevcb per socket
Co-authored-by: Azat Khuzhin <azat@libevent.org>
v2: remove handling of HTTP_BIND_IPV6
2022-08-13 20:12:18 +02:00
Dmitry Ilyin
05a03d4a15 Add more HTTP_ response codes 2022-08-07 11:13:48 +02:00
Azat Khuzhin
4872734277 Add a note that IOCP is experimental feature
Refs: #1228
2022-07-10 16:18:40 +03:00
cui fliter
1c204d5564
Fix some typos (#1284)
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-06-12 23:58:50 +03:00
zhongzedu
5cc2ff8897 fix grammar in comment 2022-05-12 15:00:52 +03:00
Syedh30
e339880f55 include/event.h: include <event2/util.h> over deprecatd <evutil.h>
Fixes: #1263
2022-04-30 02:32:13 +03:00
Jay Freeman (saurik)
3da71856a7 Fix build w/o OpenSSL by w/ MbedTLS
In 78fa3971be892194aa168c04fc34bf5f2cd99b99 from
https://github.com/libevent/libevent/pull/1241#commitcomment-63865496 a
new "if MBEDTLS" block was added to include/include.am. This is not
parsed by automake as it isn't on the first column, resulting in a
subsequent error in the build.

From [1]:

> The if, else, and endif statements should not be indented, i.e., start on column one.

  [1]: https://www.gnu.org/software/automake/manual/html_node/Usage-of-Conditionals.html

Fixes: #1251
Fixes: google/oss-fuzz#7149
2022-02-12 22:57:30 +03:00
Dmitry Ilyin
78fa3971be Fix make install failed when Automake used and both OpenSSL and MbedTLS are activated
Issue:
https://github.com/libevent/libevent/pull/1241#commitcomment-63865496
2022-01-15 08:30:26 +03:00
Dmitry Ilyin
2db55e43cf Install bufferevent_ssl.h with MbedTLS support also 2021-12-15 21:27:21 +03:00
Yongsheng Xu
cd6a41ecdd feat: add evdns_base_get_nameserver_fd method
To get underlying udp socket fd.
2021-12-10 11:05:13 +08:00
Azat Khuzhin
0c217f4fe1 Fix comment for evdns_base_new() 2021-11-22 00:05:27 +03:00
Yong Wu
68675d5f67
doc: adjust flags notice on event_base_loop() 2021-09-12 18:03:03 +08:00
Sean Young
f446229b22 http: support unix domain sockets
There are no standard for encoding a unix socket in an url. nginx uses:

    http://unix:/path/to/unix/socket:/httppath

The second colon is needed to delimit where the unix path ends and where
the rest of the url continues.

Signed-off-by: Sean Young <sean@mess.org>
2021-08-10 23:22:10 +03:00
Sergey Matveychuk
19b3fd0bf0 evdns: add ability to get CNAME
Add new flag (DNS_CNAME_CALLBACK) for
evdns_base_resolve_ipv4()/evdns_base_resolve_ipv6().

If set, you will get one more callback with type == DNS_CNAME and CNAME
in addrs argument.
2021-05-24 21:03:45 +03:00
Azat Khuzhin
8e03f49597 Merge #1152 -- remove no op evdns functions
* upstream/pr/1152:
  dns: remove evdns_set_transaction_id_fn
  dns: remove evdns_set_random_bytes_fn
2021-04-03 12:51:24 +03:00
fanquake
01beec2fea
dns: remove evdns_set_transaction_id_fn 2021-04-03 12:55:32 +08:00
fanquake
39d680534a
dns: remove evdns_set_random_bytes_fn 2021-04-03 12:55:11 +08:00
Emil Engler
0ef0d9475c doc: adjust edge-trigger notice on event_new()
This makes it easier to read and to understand it in my opinon. It also
fixes a missing "-" character.
2021-04-02 20:59:55 +02:00
fanquake
4c29b01c87
build: remove splice implementation fragments
Looks like a `splice` implementation was planned, but has clearly never
eventuated (the TODO comment is from ~12 years ago, in
8b5bd77415fb6634fadf08357676926fecf5f032). For now, it's probably better
to remove the unused code/correct the docs.
2021-03-28 10:57:11 +08:00