skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

unixmessage_timed_receive.c (725B)


      1 /* ISC license. */
      2 
      3 #include <sys/types.h>
      4 
      5 #include <skalibs/functypes.h>
      6 #include <skalibs/unix-timed.h>
      7 #include <skalibs/unixmessage.h>
      8 
      9 typedef struct unixmessage_getter_s unixmessage_getter, *unixmessage_getter_ref ;
     10 struct unixmessage_getter_s
     11 {
     12   unixmessage_receiver *b ;
     13   unixmessage *m ;
     14 } ;
     15 
     16 static int getfd (unixmessage_getter *g)
     17 {
     18   return unixmessage_receiver_fd(g->b) ;
     19 }
     20 
     21 static ssize_t get (unixmessage_getter *g)
     22 {
     23   return unixmessage_receive(g->b, g->m) ;
     24 }
     25 
     26 int unixmessage_timed_receive (unixmessage_receiver *b, unixmessage *m, tain const *deadline, tain *stamp)
     27 {
     28   unixmessage_getter g = { .b = b, .m = m } ;
     29   return timed_get(&g, (init_func_ref)&getfd, (get_func_ref)&get, deadline, stamp) ;
     30 }