netstring_timed_get.c (565B)
1 /* ISC license. */ 2 3 #include <errno.h> 4 #include <skalibs/buffer.h> 5 #include <skalibs/netstring.h> 6 #include <skalibs/iopause.h> 7 #include <skalibs/unix-timed.h> 8 9 int netstring_timed_get (buffer *b, stralloc *sa, tain const *deadline, tain *stamp) 10 { 11 iopause_fd x = { .fd = buffer_fd(b), .events = IOPAUSE_READ } ; 12 size_t w = 0 ; 13 for (;;) 14 { 15 int r = netstring_get(b, sa, &w) ; 16 if (r > 0) return r ; 17 if (r < 0) return 0 ; 18 r = iopause_stamp(&x, 1, deadline, stamp) ; 19 if (r < 0) return 0 ; 20 else if (!r) return (errno = ETIMEDOUT, 0) ; 21 } 22 }