File: api.c

package info (click to toggle)
libuev 2.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: sh: 4,665; ansic: 1,428; makefile: 102
file content (34 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (3)
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
33
34
#include "check.h"

uev_t timer, file;
int   counter = 10;

static void cb(uev_t *w, void *arg, int events)
{
	if (UEV_ERROR == events)
		fprintf(stderr, "timer watcher failed, ignoring ...\n");

	if (counter--)
		return;

	uev_exit(w->ctx);
}

int main(void)
{
	uev_ctx_t ctx;
	FILE *fp;

	uev_init(&ctx);
	uev_timer_init(&ctx, &timer, cb, NULL, 100, 100);

	fp = fopen("/dev/one", "r");
	if (fp)
		uev_io_init(&ctx, &file, cb, NULL, fileno(fp), UEV_READ);

	uev_run(&ctx, 0);

	uev_exit(&ctx);	/* Should not hang event loop, troglobit/uftpd#16 */

	return 0;
}