skalibs

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

unixmessage_handle.c (456B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/unixmessage.h>
      4 
      5 int unixmessage_handle (unixmessage_receiver *b, unixmessage_handler_func_ref f, void *p)
      6 {
      7   unsigned int count = 0 ;
      8   while (count < UNIXMESSAGE_MAXREADS || unixmessage_receiver_hasmsginbuf(b))
      9   {
     10     unixmessage m ;
     11     int r = unixmessage_receive(b, &m) ;
     12     if (r < 0) return -1 ;
     13     if (!r) break ;
     14     r = (*f)(&m, p) ;
     15     if (r <= 0) return r-2 ;
     16     count++ ;
     17   }
     18   return (int)count ;
     19 }