2 * Copyright (C) 2001 Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: test_reactor.c,v 1.2 2002/08/21 10:42:21 rich Exp $
37 #include "pthr_reactor.h"
39 static void set_flag (void *data) { int *flag = (int *) data; *flag = 1; }
40 static void set_flag_h (int s, int e, void *data) { int *flag = (int *) data; *flag = 1; }
46 reactor_handle h1, h2;
47 int flag1 = 0, flag2 = 0, flag3 = 0;
52 /* Create some pipes. */
53 if (pipe (p1) < 0) { perror ("pipe"); exit (1); }
54 if (pipe (p2) < 0) { perror ("pipe"); exit (1); }
56 if (fcntl (p1[0], F_SETFL, O_NONBLOCK) < 0) { perror ("fcntl"); exit (1); }
57 if (fcntl (p1[1], F_SETFL, O_NONBLOCK) < 0) { perror ("fcntl"); exit (1); }
58 if (fcntl (p2[0], F_SETFL, O_NONBLOCK) < 0) { perror ("fcntl"); exit (1); }
59 if (fcntl (p2[1], F_SETFL, O_NONBLOCK) < 0) { perror ("fcntl"); exit (1); }
61 /* Register read handlers. */
62 h1 = reactor_register (p1[0], REACTOR_READ, set_flag_h, &flag1);
63 h2 = reactor_register (p2[0], REACTOR_READ, set_flag_h, &flag2);
65 /* Register a prepoll handler. */
66 pre1 = reactor_register_prepoll (global_pool, set_flag, &flag3);
68 /* Write something and check the flags. */
84 reactor_unregister (h1);
85 reactor_unregister (h2);
86 reactor_unregister_prepoll (pre1);
88 /* Register a timer function. */
89 t1 = reactor_set_timer (global_pool, 1000, set_flag, &flag1);