~ubuntu-branches/ubuntu/dapper/libevent/dapper

« back to all changes in this revision

Viewing changes to test/test-weof.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Law
  • Date: 2004-05-16 15:36:39 UTC
  • Revision ID: james.westby@ubuntu.com-20040516153639-9j1p0j1nei5rz6uv
Tags: upstream-0.8
ImportĀ upstreamĀ versionĀ 0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Compile with:
 
3
 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
 
4
 */
 
5
 
 
6
#include <sys/types.h>
 
7
#include <sys/stat.h>
 
8
#include <sys/time.h>
 
9
#include <sys/socket.h>
 
10
#include <fcntl.h>
 
11
#include <stdlib.h>
 
12
#include <stdio.h>
 
13
#include <string.h>
 
14
#include <signal.h>
 
15
#include <unistd.h>
 
16
#include <errno.h>
 
17
 
 
18
#include <event.h>
 
19
 
 
20
int pair[2];
 
21
int test_okay = 1;
 
22
int called = 0;
 
23
 
 
24
void
 
25
write_cb(int fd, short event, void *arg)
 
26
{
 
27
        char *test = "test string";
 
28
        int len;
 
29
 
 
30
        len = write(fd, test, strlen(test) + 1);
 
31
 
 
32
        printf("%s: write %d%s\n", __func__,
 
33
            len, len ? "" : " - means EOF");
 
34
 
 
35
        if (len > 0) {
 
36
                if (!called)
 
37
                        event_add(arg, NULL);
 
38
                close(pair[0]);
 
39
        } else if (called == 1)
 
40
                test_okay = 0;
 
41
 
 
42
        called++;
 
43
}
 
44
 
 
45
int
 
46
main (int argc, char **argv)
 
47
{
 
48
        struct event ev;
 
49
 
 
50
        if (signal(SIGPIPE, SIG_IGN) == SIG_IGN)
 
51
                return (1);
 
52
 
 
53
        if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1)
 
54
                return (1);
 
55
 
 
56
        /* Initalize the event library */
 
57
        event_init();
 
58
 
 
59
        /* Initalize one event */
 
60
        event_set(&ev, pair[1], EV_WRITE, write_cb, &ev);
 
61
 
 
62
        event_add(&ev, NULL);
 
63
 
 
64
        event_dispatch();
 
65
 
 
66
        return (test_okay);
 
67
}
 
68