summaryrefslogtreecommitdiff
path: root/net.c
AgeCommit message (Collapse)Author
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.
2015-01-05Fix errno error buffers to not clobber errorsMatt Stancliff
The strerror_r API has two flavors depending on system options. The bad flavor uses a static buffer for returning results, so if you save the pointer from strerror_r, the string you're referencing becomes useless if anybody else calls strerror_r again The good flavor does what you expect: it writes the error to your buffer. This commit uses strerror_r directly if it's a good version or copies the static buffer into our private buffer if it's a bad version. Thanks to gemorin for explaining the problem and drafting a fix. Fixes #239
2015-01-05Fix build under kfreebsdChris Lamb
Signed-off-by: Chris Lamb <chris@chris-lamb.co.uk> [Instead of checking for "not solaris" we feature detect for availability of what we want, then remove the system that advertises compatability but doesn't actually provide it (given our assumptions about what we're guarding).] Closes #254
2015-01-05Add support for SO_REUSEADDRmike
[This introduces some new API functions.] * Adds new flag to the connection context indicating SO_REUSEADDR should be set. * Adds max number of retries constant for when connect() hits EADDRNOTAVAIL. * Adds new function, redisAsyncConnectBindWithReuse(), letting clients enable this functionality. [Removed trailing whitespace in new header lines.] Closes #264
2014-09-18Fix getaddrinfo() memory leakMatt Stancliff
See antirez/redis#2012 for the leak causing unbounded memory growth.
2014-04-09File descriptors can be 0Pieter Noordhuis
2014-04-09Fix const correctnessPieter Noordhuis
2014-04-09Fix build under SolarisMatt Stancliff
Solaris doesn't define the TCP options we try to set. Let's ignore those under Solaris. Closes #207
2014-04-08Add ability to bind source address on connectMatt Stancliff
Some environments require binding to specific source addresses instead of letting the system determine which IP a connection should originate from. Closes #233
2014-04-08Stop redisCheckSocketError from more than checkingMatt Stancliff
redisCheckSocketError should only CheckSocketError and not close any misbehaving sockets. If CheckSocketError discovers a problem, the caller will discover the contest is in ERR and will start destroying the context (which involves finalizing all callbacks (which may still be using fd for something, so we should not close fd until all callbacks have been told we are failing) and eventually close the fd in redisFree() immediately before the context is released).
2014-04-08Remove possiblity of multiple close on same fdMatt Stancliff
With all the async connects and disconnects and error handling going on in hiredis, we need to centralize how we close our fd and set it so it doesn't get re-closed. Prior to this commit, sometimes we'd close(fd), run an async error handler, then call close(fd) again. To stop multiple closes, we now set fd to -1 after we free it, but that requires not passing fd as an independent argument to functions. This commit moves all fd usage to c->fd. Since the context has a fd field and all functions receive the context, it makes more sense to use the fd inside of c instead of passing along fd as an independent argument. Also, by only using c->fd, we can set c->fd after we close it to signify we shouldn't re-close the same fd again. This does change one semi-public interface function redisCheckSocketError() to only take (context) instead of (context, fd). A search on github returned zero occasions of people using redisCheckSocketError() outside of net.{c,h} in hiredis itself. Commit inspired by the bug report at: https://groups.google.com/forum/#!topic/redis-db/mQm46XkIPOY Thanks go out to Thijs for trying high-frequency reconnects on a host that isn't there. Closes #230
2013-07-11Minimal IPv6 support.antirez
redisContextConnectTcp() is now able to use IPv6 addresses if there is no IPv4 address found resolving the specified hostname.
2013-07-10Mark the timeout parameter as const in various functionsNoah Williamsson
The struct timeval argument in redisConnectWithTimeout(), redisConnectUnixWithTimeout(), redisSetTimeout(), redisContextSetTimeout(), redisContextConnectTcp() and redisContextConnectUnix() is never modified and can therefore be marked as const. Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
2013-07-10WhitespacePieter Noordhuis
2013-05-07Fix possible uninitialized value access due to strerror_r errorEugene Bolotin
2013-05-01Make redisKeepAlive work on OSXPieter Noordhuis
2013-04-30Make KeepAlive optionalAllen.Dou
Make Connection KeepAlive being optional instead of default.
2013-04-19SetKeepAliveAllen.Dou
Keep client alive even though no command was sent to server for a long time.
2013-03-14Set error when invalid timeout value is given to redisConnectWithTimeoutAaron Bedra
Closes #154 This commit properly sets the error value inside of redisContextWaitReady when an invalid sec or usec value is provided. Tests for each case are provided to demonstrate that the issue is properly fixed and to avoid regression. Signed-off-by: Aaron Bedra <aaron@aaronbedra.com>
2012-04-18Use poll() instead of select() inside redisContextWaitReady()Mark Ellzey
The current select() is limiting in instances where the fd num is > FD_SETSIZE. Since redisContextWaitReady() only processes a single fd, select would still fail. For compatibility reasons I have converted select() over to poll(), eliminating this problem.
2011-07-20Merge pull request #47 from geoffgarside/addrinfoPieter Noordhuis
Use getaddrinfo
2011-07-10Put back missing socket error check after select(2)Pieter Noordhuis
2011-06-27Extract function to check a socket for errorsPieter Noordhuis
2011-06-18Fix incorrect "no route to host" errors.Geoff Garside
If getaddrinfo(3) includes an AF_INET6 address before an AF_INET address on a host with only IPv4 network connectivity then the redisContextConnectTcp call would fail with "no route to host". This commit fixes this issue by specifically handling the errno EHOSTUNREACH error and entering another iteration of the addrinfo loop. This will allow following AF_INET addresses to be attempted.
2011-06-17Use getaddrinfo(3) in redisContextConnectTcp.Geoff Garside
Change redisContextConnectTcp() function to use getaddrinfo(3) to perform address resolution, socket creation and connection. Resolved addresses are limited to those reachable by the AF_INET family.
2011-06-17Add redisSetReuseAddr(c, fd) static function.Geoff Garside
Extract setting SO_REUSEADDR socket option into separate function so the same code can be more easily used by redisCreateSocket and other functions.
2011-04-21Update licensePieter Noordhuis
2011-04-21Use static buffer for error string on contextPieter Noordhuis
2011-02-04Fix copying timeval for timeoutPieter Noordhuis
2011-02-04Use select(2) for enforce a timeout on blocking connect(2)Pieter Noordhuis
2011-01-07Return error on socket timeout for a blocking contextPieter Noordhuis
2010-12-29LicensePieter Noordhuis
2010-12-16Solaris doesn't know AF_LOCALPieter Noordhuis
2010-12-16Add myself to license in some filesPieter Noordhuis
2010-12-01Wait with setting CONNECTED until there is an fdPieter Noordhuis
2010-11-22Make error messages consistent in casingPieter Noordhuis
2010-11-03Add functiont to net.c to connect to a unix socketPieter Noordhuis
2010-11-03Move code in net.c to separate functionsPieter Noordhuis
2010-11-02Make setError receive an sdsPieter Noordhuis
2010-11-02Strip net.c down to the bare minimumPieter Noordhuis
2010-11-02Move anet.{c,h} to net.{c,h}Pieter Noordhuis