summaryrefslogtreecommitdiff
path: root/net.c
AgeCommit message (Collapse)Author
2024-03-23all: rename redis -> redict symbols and commentsmasterAnna (navi) Figueiredo Gomes
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2024-03-22all: use REUSE with LGPL-3.0-or-later and BSD-3-ClauseAnna (navi) Figueiredo Gomes
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
2023-08-18Make redisEnableKeepAlive a no-op on AF_UNIX connections. (#1215)Michael Grunder
Fixes #1185
2023-07-25Retry poll(2) if we are intterupted.michael-grunder
This commit adds logic to retry our poll call when waiting for the connection to complete, in the event that we are interrupted by a signal. Additionally we do some simple bookkeeping to keep track of the overall timeout specified by the user. Fixes #1206
2023-06-01Add a test for the TCP_USER_TIMEOUT option. (#1192)Michael Grunder
* Add a test for the TCP_USER_TIMEOUT option. * Explicitly set errno to ENOTSUP on unsupported OS's
2023-05-30Fix a typo in b6a052f.Yossi Gottlieb
2023-05-29Helper for setting TCP_USER_TIMEOUT socket option (#1188)Viktor Söderqvist
* Implement redisSetTcpUserTimeout to set socket option TCP_USER_TIMEOUT * Documentation for redisSetTcpUserTimeout and some more undocumented functions Documentation for redisReconnect() and the setters of socket options: * redisKeepAlive() * redisEnableKeepAliveWithInterval() * redisSetTcpUserTimeout()
2022-10-14Fixup of PR734: Coverage of hiredis.c (#1124)Bjorn Svensson
Improve coverage (#734) * Remove duplicate tests - double covered by: "Can parse RESP3 doubles" - bool covered via: "Can parse RESP3 bool" * Make (connect) timeout in test config general * Set error string in Unix connect with invalid timeout Restructure testcase since redisConnectWithTimeout() and redisConnectUnixWithTimeout() now behaves similar. * Use quiet flag in lcov/genhtml instead of piping to /dev/null * Fixup of redisCommandArgv test case * Update test case to match what it covers Use new test case info text since the previous one seemed copy&pasted. The sought coverage was the handling of the parent-chaining for a double object, which the test case now focuses on. Co-authored-by: Ariel <ashtul@gmail.com>
2022-09-05Fix protocol error (#1106)Michael Grunder
Fix ProtocolError This commit attempts to fix hiredis such that a recoverable write error will be retried rather than throwing a hard error. Since our read/write functions are now behind function pointers, we specify semantically that a return value of < 0 is a hard error, 0 a recoverable error, and > 0 a success. Our default `redisNetRead` function was already doing something similar so this also improves code consistency. Resolves #961 Co-authored-by: Maksim Tuleika <maksim.tuleika@appcast.io>
2022-09-03Use a windows specific keepalive function. (#1104)Michael Grunder
Use a windows specific keepalive function. While it is possible to toggle `TCP_KEEPALIVE` in windows via setsockopt, you have to use `WSAIoctl` to set the interval. Since `WSAIoctl` can actually do all of this in one call (toggle the option, and set the corresponding interval), just use that in Windows and avoid the call to `setsockopt` alltogether. Fixes: #1100
2022-09-01Add possibility to prefer IPv6, IPv4 or unspecifiedViktor Söderqvist
2022-08-29Do store command timeout in the context for redisSetTimeout (#593)Arseniy Simonov
2022-06-26Whitespace, stylemichael-grunder
2022-06-26Use correct type for getsockopt()Kristján Valur Jónsson
2022-06-26Support failed async connects on windows.Kristján Valur Jónsson
2020-07-26add a command_timeout to redisContextOptions (#839)valentinogeron
Add an additional timeout so the user has a convenient way of controlling distinct connect and command timeouts
2020-06-22fix #785: defer TCP_NODELAY in async tcp connections (#836)OmriSteiner
Co-authored-by: Omri Steiner <omri@insoundz.com>
2020-06-07sdsrange overflow fix (#830)Michael Grunder
Fix overflow bug in `sdsrange`
2020-05-22Allow users to replace allocator and handle OOM everywhere. (#800)Michael Grunder
* Adds an indirection to every allocation/deallocation to allow users to plug in ones of their choosing (use custom functions, jemalloc, etc). * Gracefully handle OOM everywhere in hiredis. This should make it possible for users of the library to have more flexibility in how they handle such situations. * Changes `redisReaderTask->elements` from an `int` to a `long long` to prevent a possible overflow when transferring the task elements into a `redisReply`. * Adds a configurable `max elements` member to `redisReader` that defaults to 2^32 - 1. This can be set to "unlimited" by setting the value to zero.
2020-04-02Win32 tests and timeout fix (#776)Michael Grunder
Unit tests in Windows and a Windows timeout fix This commit gets our unit tests compiling and running on Windows as well as removes a duplicated `timeval` -> `DWORD` conversion logic in sockcompat.c There are minor differences in behavior between Linux and Windows to note: 1. In Windows, opening a non-existent hangs forever in WSAPoll whereas it correctly returns with a "Connection refused" error on Linux. For that reason, I simply skip this test in Windows. It may be related to this known issue: https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/ 2. Timeouts are handled slightly differently in Windows and Linux. In Linux, we intentionally set REDIS_ERR_IO for connection timeouts whereas in Windows we set REDIS_ERR_TIMEOUT. It may be prudent to fix this discrepancy although there are almost certainly users relying on the current behavior.
2020-01-28Safe allocation wrappers (#754)Michael Grunder
Create allocation wrappers with a configurable OOM handler (defaults to abort()). See #752, #747
2019-08-13Merge pull request #670 from jman-krafton/masterMark Nunberg
fix timeout code in windows
2019-08-12add recv error code for clarifying timeoutSangmoon Yi
2019-08-12fix timeout code in windowsSangmoon Yi
2019-07-03Remove unnecessary null check before freeQuentin Young
2019-04-01Port network layer to Winsockm
With this change, Hiredis builds with MinGW and runs on Windows.
2019-04-01Use recv/send instead of read/writem
The recv/send calls are more portable than read/write, since unlike the latter, the former work with Windows sockets. We also check for EWOULDBLOCK instead of EAGAIN. On most Unices, EAGAIN and EWOULDBLBOCK are the same thing. However, on Windows they are different, and send/recv are expected to give EWOULDBLOCK for non-blocking sockets.
2019-04-01Introduce a redisFD typem
The redisFD type should be equal to the system native socket file desciptor type (for POSIX, this is a plain int). We also introduce the REDIS_INVALID_FD value, which maps to -1 on POSIX systems.
2019-04-01Move network I/O calls to net.cm
This makes hiredis.c free from system calls related to socket I/O. This is also makes the treatment of raw socket connections more similar to the SSL backend.
2019-02-20Remove redundant line after rebaseMark Nunberg
2019-02-20Unix: set addrlen so async reconnect uses proper sizeMark Nunberg
2019-01-28Fix Invalid argument after redisAsyncConnectUnixCode Hz
2018-12-05Fix regression when connecting with Unix sockets (#629)Mark Nunberg
2018-09-25Handle connection errors better in blocking mode as wellMark Nunberg
2018-09-25saddr should be addrlen bytesMark Nunberg
Not sizeof saddr.
2018-09-25Call connect(2) again for non-blocking connectMark Nunberg
This retrieves the actual error which occurred, as getsockopt is not always reliable in this regard.
2018-04-30Remove redundant NULL checksJustin Brewer
free(NULL) is a valid NOP. Most of the hiredis free functions behave the same way. redisReaderFree is updated to also be NULL-safe. There is one redundant NULL check at sds.c:1036, but it's left as is since sds is imported from upstream. Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30Fix a segfault on *BSDJustin Brewer
freeaddrinfo is not required by POSIX to be NULL-safe. OpenBSD will SIGSEGV. NetBSD will assert. FreeBSD up to 11.1 will SIGSEGV, while in future versions, it will be a silent NOP [1]. Commit d4b715f0aa97 ("Fix potential race in 'invalid timeout' tests") added a code path to _redisContextConnectTcp which calls freeaddrinfo(NULL), triggering the segfault. Put a NULL check around the call to freeaddrinfo. [1] - https://github.com/freebsd/freebsd/commit/e9167239034a1e475c3238f8d133ebf703424ee0 Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30Drop __redis_strerror_rJustin Brewer
Since _GNU_SOURCE is now guaranteed to be unset, it is no longer necessary to support the GNU-specific version of strerror_r. Drop __redis_strerror_r from the header, and call strerror_r directly. This breaks any external users of this macro, but they shouldn't have been using it in the first place. Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-28Strip down fmacros.hJustin Brewer
strerror_r and addrinfo require _POSIX_C_SOURCE >= 200112L, which is implied by _XOPEN_SOURCE >= 600. With the removal of AF_LOCAL usage, the only non-standard features being used are the TCP_KEEP* socket flags. _DARWIN_C_SOURCE is required to expose TCP_KEEPALIVE. Fall back to using _XOPEN_SOURCE 600 for all platforms, and additionally define _DARWIN_C_SOURCE for Darwin. Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-28Use AF_UNIXJustin Brewer
AF_LOCAL is the old, non-standardized name for AF_UNIX. Just use AF_UNIX, rather than wrestling with platform specifics of AF_LOCAL definitions. Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2017-07-15Merge #533not-a-robot[bot]
533: Small fixes r=badboy
2017-06-15Small fixesamallia
2017-05-15Fix leak if setsockopt failsFrederik Deweerdt
2016-12-30Fix __redisSetErrorFromErrno() can not get error string.Jin Qing
snprintf() may change errno.
2016-07-07fix: should close socket fd when retry connet remote (tcp)WSL
2015-11-18Fix potential race in 'invalid timeout' testsTom Lee
It's possible for the call to connect() to succeed on the very first try, in which case the logic for checking for invalid timeout fields is never executed. When this happens, the tests fail because they expect a REDIS_ERR_IO but no such failure has occurred. Tests aside, this is a potential source of irritating and hard-to-find intermittent bugs. This patch forces the validation to occur early so that we get predictable behavior whenever an invalid timeout is specified.
2015-04-30Renamed redisContext struct member 'unix' to 'unix_sock' to avoid ↵Alex Balashov
encountering defined constant 'unix' in GNU C environment (see commit d8145d79ce715054980938c751067ebaa541573c). Not all code using hiredis can compile using '-std=c99', and/or not all users are able to easily make that change to the build process of various open-source projects, so it is more pragmatic to choose a different identifier that does not impose this requirement.
2015-04-16Change copyright date and add copyright holderJan-Erik Rediger
2015-04-16Implement a reconnect method for the client contextJan-Erik Rediger
Originally implemented by @abedra as part of #306. In case a write or read times out, we force an error state, because we can't guarantuee that the next read will get the right data. Instead we need to reconnect to have a clean-state connection, which is now easily possible with this method.