Merge branch 'ipv6'
This commit is contained in:
commit
cc3ee45325
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
#include <hiredis.h>
|
#include <hiredis.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char **argv) {
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
redisContext *c;
|
redisContext *c;
|
||||||
redisReply *reply;
|
redisReply *reply;
|
||||||
|
const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1";
|
||||||
|
int port = (argc > 2) ? atoi(argv[2]) : 6379;
|
||||||
|
|
||||||
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
|
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
|
||||||
c = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
|
c = redisConnectWithTimeout(hostname, port, timeout);
|
||||||
if (c == NULL || c->err) {
|
if (c == NULL || c->err) {
|
||||||
if (c) {
|
if (c) {
|
||||||
printf("Connection error: %s\n", c->errstr);
|
printf("Connection error: %s\n", c->errstr);
|
||||||
|
8
net.c
8
net.c
@ -255,10 +255,18 @@ int redisContextConnectTcp(redisContext *c, const char *addr, int port, const st
|
|||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
/* Try with IPv6 if no IPv4 address was found. We do it in this order since
|
||||||
|
* in a Redis client you can't afford to test if you have IPv6 connectivity
|
||||||
|
* as this would add latency to every connect. Otherwise a more sensible
|
||||||
|
* route could be: Use IPv6 if both addresses are available and there is IPv6
|
||||||
|
* connectivity. */
|
||||||
|
if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
|
||||||
|
hints.ai_family = AF_INET6;
|
||||||
if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
|
if ((rv = getaddrinfo(addr,_port,&hints,&servinfo)) != 0) {
|
||||||
__redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv));
|
__redisSetError(c,REDIS_ERR_OTHER,gai_strerror(rv));
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (p = servinfo; p != NULL; p = p->ai_next) {
|
for (p = servinfo; p != NULL; p = p->ai_next) {
|
||||||
if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
|
if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user