skalibs

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

textmessage_handle.c (481B)


      1 /* ISC license. */
      2 
      3 #include <sys/uio.h>
      4 #include <skalibs/textmessage.h>
      5 
      6 int textmessage_handle (textmessage_receiver *tr, textmessage_handler_func_ref f, void *p)
      7 {
      8   unsigned int count = 0 ;
      9   while (count < TEXTMESSAGE_MAXREADS || textmessage_receiver_hasmsginbuf(tr))
     10   {
     11     struct iovec v ;
     12     int r = textmessage_receive(tr, &v) ;
     13     if (r < 0) return -1 ;
     14     if (!r) break ;
     15     r = (*f)(&v, p) ;
     16     if (r <= 0) return r-2 ;
     17     count++ ;
     18   }
     19   return (int)count ;
     20 }