MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sendSync

Function sendSync

app/redis-6.2.6/src/redis-cli.c:7092–7127  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

7090 * slaveMode() and getRDB().
7091 * returns 0 in case an EOF marker is used. */
7092unsigned long long sendSync(redisContext *c, char *out_eof) {
7093 /* To start we need to send the SYNC command and return the payload.
7094 * The hiredis client lib does not understand this part of the protocol
7095 * and we don't want to mess with its buffers, so everything is performed
7096 * using direct low-level I/O. */
7097 char buf[4096], *p;
7098 ssize_t nread;
7099
7100 /* Send the SYNC command. */
7101 if (cliWriteConn(c, "SYNC\r\n", 6) != 6) {
7102 fprintf(stderr,"Error writing to master\n");
7103 exit(1);
7104 }
7105
7106 /* Read $<payload>\r\n, making sure to read just up to "\n" */
7107 p = buf;
7108 while(1) {
7109 nread = readConn(c,p,1);
7110 if (nread <= 0) {
7111 fprintf(stderr,"Error reading bulk length while SYNCing\n");
7112 exit(1);
7113 }
7114 if (*p == '\n' && p != buf) break;
7115 if (*p != '\n') p++;
7116 }
7117 *p = '\0';
7118 if (buf[0] == '-') {
7119 fprintf(stderr, "SYNC with master failed: %s\n", buf);
7120 exit(1);
7121 }
7122 if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= RDB_EOF_MARK_SIZE) {
7123 memcpy(out_eof, buf+5, RDB_EOF_MARK_SIZE);
7124 return 0;
7125 }
7126 return strtoull(buf+1,NULL,10);
7127}
7128
7129static void slaveMode(void) {
7130 static char eofmark[RDB_EOF_MARK_SIZE];

Callers 2

slaveModeFunction · 0.85
getRDBFunction · 0.85

Calls 4

cliWriteConnFunction · 0.85
readConnFunction · 0.85
strncmpFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected