From 81a6a9639a5650082fcc78f5c83c4dfee79eaeb2 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 22 Aug 2013 14:05:07 +0200 Subject: [PATCH] Use listenToPort() in cluster.c as well. --- src/cluster.c | 27 +++++++++------------------ src/redis.h | 1 + 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 82a4d74ef..fdd47fe0c 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -226,7 +226,7 @@ void clusterSaveConfigOrDie(void) { } void clusterInit(void) { - int saveconf = 0, j; + int saveconf = 0; server.cluster = zmalloc(sizeof(clusterState)); server.cluster->myself = NULL; @@ -252,25 +252,16 @@ void clusterInit(void) { saveconf = 1; } if (saveconf) clusterSaveConfigOrDie(); - /* We need a listening TCP port for our cluster messaging needs */ + + /* We need a listening TCP port for our cluster messaging needs. */ server.cfd_count = 0; - if (server.bindaddr_count == 0) server.bindaddr[0] = NULL; - for (j = 0; j < server.bindaddr_count || j == 0; j++) { - server.cfd[j] = anetTcpServer( - server.neterr, server.port+REDIS_CLUSTER_PORT_INCR, - server.bindaddr[j]); - if (server.cfd[j] == -1) { - redisLog(REDIS_WARNING, - "Opening cluster listening TCP socket %s:%d: %s", - server.bindaddr[j] ? server.bindaddr[j] : "*", - server.port+REDIS_CLUSTER_PORT_INCR, - server.neterr); - exit(1); - } - if (aeCreateFileEvent(server.el, server.cfd[j], AE_READABLE, - clusterAcceptHandler, NULL) == AE_ERR) redisPanic("Unrecoverable error creating Redis Cluster file event."); - server.cfd_count++; + if (listenToPort(server.port+REDIS_CLUSTER_PORT_INCR, + server.cfd,&server.cfd_count) == REDIS_ERR) + { + exit(1); } + + /* The slots -> keys map is a sorted set. Init it. */ server.cluster->slots_to_keys = zslCreate(); } diff --git a/src/redis.h b/src/redis.h index b5241b3fd..1a0523218 100644 --- a/src/redis.h +++ b/src/redis.h @@ -1096,6 +1096,7 @@ int getClientLimitClassByName(char *name); char *getClientLimitClassName(int class); void flushSlavesOutputBuffers(void); void disconnectSlaves(void); +int listenToPort(int port, int *fds, int *count); #ifdef __GNUC__ void addReplyErrorFormat(redisClient *c, const char *fmt, ...)