Always returns a positive number < len. len must be > 0! */
| 382 | |
| 383 | /* Always returns a positive number < len. len must be > 0! */ |
| 384 | static size_t read_nofail(int fd, void *buf, size_t len) |
| 385 | { |
| 386 | ssize_t i; |
| 387 | assert(len > 0); |
| 388 | |
| 389 | i = cli_read(fd, buf, len); |
| 390 | if (i == 0) |
| 391 | errx(ERROR_TALKING_TO_LIGHTNINGD, |
| 392 | "reading response: socket closed"); |
| 393 | else if (i < 0) |
| 394 | err(ERROR_TALKING_TO_LIGHTNINGD, "reading response"); |
| 395 | return i; |
| 396 | } |
| 397 | |
| 398 | /* We rely on the fact that lightningd terminates all JSON RPC responses with |
| 399 | * "\n\n", so we can stream even if we can't parse. */ |