Permalink
Browse files

don't listen on network until db is loaded from disk

  • Loading branch information...
1 parent 223a059 commit 3bd1305dffc55beff2ce0e5c5aa747e6e455d846 @cxreg committed Feb 8, 2010
Showing with 12 additions and 3 deletions.
  1. +8 −3 anet.c
  2. +1 −0 anet.h
  3. +3 −0 redis.c
View
@@ -237,12 +237,17 @@ int anetTcpServer(char *err, int port, char *bindaddr)
close(s);
return ANET_ERR;
}
- if (listen(s, 511) == -1) { /* the magic 511 constant is from nginx */
+ return s;
+}
+
+int anetListen(char *err, int serversock) {
+ if (listen(serversock, 511) == -1) { /* the magic 511 constant is from nginx */
anetSetError(err, "listen: %s\n", strerror(errno));
- close(s);
+ close(serversock);
return ANET_ERR;
}
- return s;
+
+ return 0;
}
int anetAccept(char *err, int serversock, char *ip, int *port)
View
@@ -40,6 +40,7 @@ int anetTcpNonBlockConnect(char *err, char *addr, int port);
int anetRead(int fd, char *buf, int count);
int anetResolve(char *err, char *host, char *ipbuf);
int anetTcpServer(char *err, int port, char *bindaddr);
+int anetListen(char *err, int serversock);
int anetAccept(char *err, int serversock, char *ip, int *port);
int anetWrite(int fd, char *buf, int count);
int anetNonBlock(char *err, int fd);
View
@@ -8372,6 +8372,9 @@ int main(int argc, char **argv) {
if (rdbLoad(server.dbfilename) == REDIS_OK)
redisLog(REDIS_NOTICE,"DB loaded from disk: %ld seconds",time(NULL)-start);
}
+
+ anetListen(server.neterr, server.fd);
+
redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port);
aeSetBeforeSleepProc(server.el,beforeSleep);
aeMain(server.el);

0 comments on commit 3bd1305

Please sign in to comment.