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