commit c1c948027e25f932dc9cc311722d3a4b44fcaf64 from: Stefan Sperling via: Thomas Adam date: Sat Mar 30 17:17:56 2024 UTC introduce got_poll_read_full_timeout() Upcoming gotd code needs to avoid infinite network socket read timeouts. commit - db6421918d528a8d1b0670409025c43ee4aa52ce commit + c1c948027e25f932dc9cc311722d3a4b44fcaf64 blob - 4f41b7577755f2ed3b7dcbb4e217ed32d08d0bde blob + 7f3896a299ca2c51b65a3d3e6c5fafe1452500d2 --- lib/got_lib_poll.h +++ lib/got_lib_poll.h @@ -15,6 +15,8 @@ */ const struct got_error *got_poll_fd(int fd, int events, int timeout); +const struct got_error *got_poll_read_full_timeout(int, size_t *, void *, + size_t, size_t, int); const struct got_error *got_poll_read_full(int, size_t *, void *, size_t, size_t); const struct got_error *got_poll_write_full(int, const void *, off_t); blob - 395fd95072c2e4346a204fa2ac44eb11c2dc9cd4 blob + 0d2d79bde766ba0de787feb2149ccba209ae2a4a --- lib/pollfd.c +++ lib/pollfd.c @@ -65,8 +65,8 @@ got_poll_fd(int fd, int events, int timeout) } const struct got_error * -got_poll_read_full(int fd, size_t *len, void *buf, size_t bufsize, - size_t minbytes) +got_poll_read_full_timeout(int fd, size_t *len, void *buf, size_t bufsize, + size_t minbytes, int timeout) { const struct got_error *err = NULL; size_t have = 0; @@ -76,7 +76,7 @@ got_poll_read_full(int fd, size_t *len, void *buf, siz return got_error(GOT_ERR_NO_SPACE); while (have < minbytes) { - err = got_poll_fd(fd, POLLIN, INFTIM); + err = got_poll_fd(fd, POLLIN, timeout); if (err) return err; r = read(fd, buf + have, bufsize - have); @@ -92,6 +92,14 @@ got_poll_read_full(int fd, size_t *len, void *buf, siz } const struct got_error * +got_poll_read_full(int fd, size_t *len, void *buf, size_t bufsize, + size_t minbytes) +{ + return got_poll_read_full_timeout(fd, len, buf, bufsize, + minbytes, INFTIM); +} + +const struct got_error * got_poll_write_full(int fd, const void *buf, off_t len) { const struct got_error *err = NULL;