Mercurial > hgrepos > FreeBSD > ports > net > turnserver
comparison files/patch-src_apps_common_hiredis__libevent2.c @ 4:9a1ee735f28f
Patch to allow redis connections by a Unix socket.
Also document the new "socket" keyword for redis connections
in the example configuration file.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 27 Mar 2020 15:07:57 +0100 |
| parents | |
| children | 4a6383e57d12 |
comparison
equal
deleted
inserted
replaced
| 3:244ecaf25a6f | 4:9a1ee735f28f |
|---|---|
| 1 --- src/apps/common/hiredis_libevent2.c.orig 2019-03-02 21:06:19 UTC | |
| 2 +++ src/apps/common/hiredis_libevent2.c | |
| 3 @@ -55,6 +55,7 @@ struct redisLibeventEvents | |
| 4 char *ip; | |
| 5 int port; | |
| 6 char *pwd; | |
| 7 + char *usocket; | |
| 8 int db; | |
| 9 }; | |
| 10 | |
| 11 @@ -223,12 +224,13 @@ void send_message_to_redis(redis_context_handle rch, c | |
| 12 | |
| 13 ///////////////////////// Attach ///////////////////////////////// | |
| 14 | |
| 15 -redis_context_handle redisLibeventAttach(struct event_base *base, char *ip0, int port0, char *pwd, int db) | |
| 16 +redis_context_handle redisLibeventAttach(struct event_base *base, char *ip0, int port0, char *pwd, char *usocket, int db) | |
| 17 { | |
| 18 | |
| 19 struct redisLibeventEvents *e = NULL; | |
| 20 redisAsyncContext *ac = NULL; | |
| 21 | |
| 22 + char sockpath[256] = "\0"; | |
| 23 char ip[256]; | |
| 24 if(ip0 && ip0[0]) | |
| 25 STRCPY(ip,ip0); | |
| 26 @@ -239,7 +241,14 @@ redis_context_handle redisLibeventAttach(struct event_ | |
| 27 if(port0>0) | |
| 28 port=port0; | |
| 29 | |
| 30 - ac = redisAsyncConnect(ip, port); | |
| 31 + if(usocket) | |
| 32 + STRCPY(sockpath, usocket); | |
| 33 + | |
| 34 + if(usocket) { | |
| 35 + ac = redisAsyncConnectUnix(sockpath); | |
| 36 + } else { | |
| 37 + ac = redisAsyncConnect(ip, port); | |
| 38 + } | |
| 39 if (!ac) { | |
| 40 fprintf(stderr,"Error: %s:%s\n", ac->errstr, ac->c.errstr); | |
| 41 return NULL; | |
| 42 @@ -256,6 +265,11 @@ redis_context_handle redisLibeventAttach(struct event_ | |
| 43 e->port = port; | |
| 44 if(pwd) | |
| 45 e->pwd = turn_strdup(pwd); | |
| 46 + if (usocket) { | |
| 47 + e->usocket = turn_strdup(usocket); | |
| 48 + } else { | |
| 49 + e->usocket = NULL; | |
| 50 + } | |
| 51 e->db = db; | |
| 52 | |
| 53 /* Register functions to start/stop listening for events */ | |
| 54 @@ -277,6 +291,7 @@ redis_context_handle redisLibeventAttach(struct event_ | |
| 55 e); | |
| 56 | |
| 57 if (e->rev == NULL || e->wev == NULL) { | |
| 58 + /* XXX FIXME TBD: free e->ip, e->pwd, e->usocket */ | |
| 59 turn_free(e, sizeof(struct redisLibeventEvents)); | |
| 60 return NULL; | |
| 61 } | |
| 62 @@ -327,7 +342,11 @@ static void redis_reconnect(struct redisLibeventEvents | |
| 63 e->context = NULL; | |
| 64 } | |
| 65 | |
| 66 - ac = redisAsyncConnect(e->ip, e->port); | |
| 67 + if(e->usocket) { | |
| 68 + ac = redisAsyncConnectUnix(e->usocket); | |
| 69 + } else { | |
| 70 + ac = redisAsyncConnect(e->ip, e->port); | |
| 71 + } | |
| 72 if(!ac) { | |
| 73 return; | |
| 74 } |
