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

#include <skalibs/unixmessage.h>

int unixmessage_handle (unixmessage_receiver *b, unixmessage_handler_func_ref f, void *p)
{
  unsigned int count = 0 ;
  while (count < UNIXMESSAGE_MAXREADS || unixmessage_receiver_hasmsginbuf(b))
  {
    unixmessage m ;
    int r = unixmessage_receive(b, &m) ;
    if (r < 0) return -1 ;
    if (!r) break ;
    r = (*f)(&m, p) ;
    if (r <= 0) return r-2 ;
    count++ ;
  }
  return (int)count ;
}