Receives a string. Returns true if it gets one. See SendString.
| 284 | |
| 285 | // Receives a string. Returns true if it gets one. See SendString. |
| 286 | bool PtoP::RecvString(int fd, std::string *str, size_t maxlen) { |
| 287 | char buf[maxlen]; |
| 288 | for (int tries = 0; tries < kMaxTries;) { |
| 289 | ssize_t nread = read(fd, buf, sizeof buf); |
| 290 | if (nread > 0) { |
| 291 | *str = std::string(buf, nread); |
| 292 | return true; |
| 293 | } |
| 294 | if (nread != -1 || (errno != EAGAIN && errno != EWOULDBLOCK)) { |
| 295 | break; |
| 296 | } |
| 297 | if (++tries < kMaxTries) { |
| 298 | std::this_thread::sleep_for(short_sleep); |
| 299 | } |
| 300 | } |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | // Send message to parent or child, figuring out which way |
| 305 | // automatically. |
nothing calls this directly
no outgoing calls
no test coverage detected