+ if (connectWithMaster() == REDIS_OK) {
+ redisLog(REDIS_NOTICE,"MASTER <-> SLAVE sync started");
+ }
+ }
+
+ /* If we have attached slaves, PING them from time to time.
+ * So slaves can implement an explicit timeout to masters, and will
+ * be able to detect a link disconnection even if the TCP connection
+ * will not actually go down. */
+ if (!(server.cronloops % (server.repl_ping_slave_period*10))) {
+ listIter li;
+ listNode *ln;
+
+ listRewind(server.slaves,&li);
+ while((ln = listNext(&li))) {
+ redisClient *slave = ln->value;
+
+ /* Don't ping slaves that are in the middle of a bulk transfer
+ * with the master for first synchronization. */
+ if (slave->replstate == REDIS_REPL_SEND_BULK) continue;
+ if (slave->replstate == REDIS_REPL_ONLINE) {
+ /* If the slave is online send a normal ping */
+ addReplySds(slave,sdsnew("*1\r\n$4\r\nPING\r\n"));
+ } else {
+ /* Otherwise we are in the pre-synchronization stage.
+ * Just a newline will do the work of refreshing the
+ * connection last interaction time, and at the same time
+ * we'll be sure that being a single char there are no
+ * short-write problems. */
+ if (write(slave->fd, "\n", 1) == -1) {
+ /* Don't worry, it's just a ping. */
+ }
+ }