Sends SYNC and reads the number of bytes in the payload. Used both by * slaveMode() and getRDB(). * returns 0 in case an EOF marker is used. */
| 6180 | * slaveMode() and getRDB(). |
| 6181 | * returns 0 in case an EOF marker is used. */ |
| 6182 | unsigned long long sendSync(redisContext *c, char *out_eof) { |
| 6183 | /* To start we need to send the SYNC command and return the payload. |
| 6184 | * The hiredis client lib does not understand this part of the protocol |
| 6185 | * and we don't want to mess with its buffers, so everything is performed |
| 6186 | * using direct low-level I/O. */ |
| 6187 | char buf[4096], *p; |
| 6188 | ssize_t nread; |
| 6189 | |
| 6190 | /* Send the SYNC command. */ |
| 6191 | if (cliWriteConn(c, "SYNC\r\n", 6) != 6) { |
| 6192 | fprintf(stderr,"Error writing to master\n"); |
| 6193 | exit(1); |
| 6194 | } |
| 6195 | |
| 6196 | /* Read $<payload>\r\n, making sure to read just up to "\n" */ |
| 6197 | p = buf; |
| 6198 | while(1) { |
| 6199 | nread = readConn(c,p,1); |
| 6200 | if (nread <= 0) { |
| 6201 | fprintf(stderr,"Error reading bulk length while SYNCing\n"); |
| 6202 | exit(1); |
| 6203 | } |
| 6204 | if (*p == '\n' && p != buf) break; |
| 6205 | if (*p != '\n') p++; |
| 6206 | } |
| 6207 | *p = '\0'; |
| 6208 | if (buf[0] == '-') { |
| 6209 | fprintf(stderr, "SYNC with master failed: %s\n", buf); |
| 6210 | exit(1); |
| 6211 | } |
| 6212 | if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= RDB_EOF_MARK_SIZE) { |
| 6213 | memcpy(out_eof, buf+5, RDB_EOF_MARK_SIZE); |
| 6214 | return 0; |
| 6215 | } |
| 6216 | return strtoull(buf+1,NULL,10); |
| 6217 | } |
| 6218 | |
| 6219 | static void slaveMode(void) { |
| 6220 | static char eofmark[RDB_EOF_MARK_SIZE]; |
no test coverage detected