2 This file is part of catta.
4 catta is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 catta is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with catta; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <catta/watch.h>
31 #include <catta/timeval.h>
32 #include <catta/gccmacro.h>
34 static const CattaPoll *api = NULL;
37 #include <catta/simple-watch.h>
38 static CattaSimplePoll *simple_poll = NULL;
40 #include <catta/thread-watch.h>
41 static CattaThreadedPoll *threaded_poll = NULL;
44 static void callback(CattaWatch *w, int fd, CattaWatchEvent event, CATTA_GCC_UNUSED void *userdata) {
46 if (event & CATTA_WATCH_IN) {
50 if ((r = read(fd, &c, 1)) <= 0) {
51 fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
56 printf("Read: %c\n", c >= 32 && c < 127 ? c : '.');
60 static void wakeup(CattaTimeout *t, CATTA_GCC_UNUSED void *userdata) {
64 printf("Wakeup #%i\n", i++);
68 catta_simple_poll_quit(simple_poll);
70 catta_threaded_poll_quit(threaded_poll);
73 catta_elapse_time(&tv, 1000, 0);
74 api->timeout_update(t, &tv);
78 int main(CATTA_GCC_UNUSED int argc, CATTA_GCC_UNUSED char *argv[]) {
82 simple_poll = catta_simple_poll_new();
84 api = catta_simple_poll_get(simple_poll);
87 threaded_poll = catta_threaded_poll_new();
88 assert(threaded_poll);
89 api = catta_threaded_poll_get(threaded_poll);
93 api->watch_new(api, 0, CATTA_WATCH_IN, callback, NULL);
95 catta_elapse_time(&tv, 1000, 0);
96 api->timeout_new(api, &tv, wakeup, NULL);
100 catta_simple_poll_loop(simple_poll);
101 catta_simple_poll_free(simple_poll);
104 catta_threaded_poll_start(threaded_poll);
106 fprintf(stderr, "Now doing some stupid stuff ...\n");
108 fprintf(stderr, "... stupid stuff is done.\n");
110 catta_threaded_poll_free(threaded_poll);