MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / syncReadLine

Function syncReadLine

src/syncio.cpp:125–145  ·  view source on GitHub ↗

Read a line making sure that every char will not require more than 'timeout' * milliseconds to be read. * * On success the number of bytes read is returned, otherwise -1. * On success the string is always correctly terminated with a 0 byte. */

Source from the content-addressed store, hash-verified

123 * On success the number of bytes read is returned, otherwise -1.
124 * On success the string is always correctly terminated with a 0 byte. */
125ssize_t syncReadLine(int fd, char *ptr, ssize_t size, long long timeout) {
126 ssize_t nread = 0;
127
128 size--;
129 while(size) {
130 char c;
131
132 if (syncRead(fd,&c,1,timeout) == -1) return -1;
133 if (c == '\n') {
134 *ptr = '\0';
135 if (nread && *(ptr-1) == '\r') *(ptr-1) = '\0';
136 return nread;
137 } else {
138 *ptr++ = c;
139 *ptr = '\0';
140 nread++;
141 }
142 size--;
143 }
144 return nread;
145}

Callers 1

connSocketSyncReadLineFunction · 0.85

Calls 1

syncReadFunction · 0.85

Tested by

no test coverage detected