summaryrefslogtreecommitdiff
path: root/src/libunixonacid/unixmessage_handle.c
blob: db92b6c9404005412051dc28a08e524ba01ae04d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* ISC license. */

#include <skalibs/unixmessage.h>

int unixmessage_handle (unixmessage_receiver_t *b, unixmessage_handler_func_t *f, void *p)
{
  unsigned int n = UNIXMESSAGE_MAXREADS ;
  int count = 0 ;
  while (n--)
  {
    unixmessage_t m ;
    register int r = unixmessage_receive(b, &m) ;
    if (r < 0) return -1 ;
    if (!r) break ;
    r = (*f)(&m, p) ;
    if (r <= 0) return r ;
    count++ ;
  }
  return count ;
}