summaryrefslogtreecommitdiff
path: root/lib/tests/udp-server.c
blob: ce0136a6dea3fa9f04c91f4a8088677afff0ad54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdlib.h>
#include <stdio.h>
#include "udp.h"

ssize_t
handle_data (const uint8_t *buf, ssize_t len)
{
  return hd (buf, len);
}

int
main (int argc, char *argv[])
{
  int n, i;
  struct timeval tv;
  struct polldata *data;

#define TIMEOUT 1 		/* Seconds.  */

  tv.tv_sec = TIMEOUT;
  tv.tv_usec = 0;
  data = udp_server (argv[1], &tv, handle_data);

  for (i = 0, n = udp_poll (data); n == 0 && i < 3; n = udp_poll (data), i++)
    {
      fprintf (stderr, "waiting another %ld second%s\n",
	       tv.tv_sec, tv.tv_sec > 1 ? "s" : "");
    }

  udp_free_polldata (data);
  return (n <= 0);
}