1 /**
2  * D header file for DragonFlyBSD.
3  *
4  * Copyright: Copyright Martin Nowak 2012.
5  * License:   $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Martin Nowak,Diederik de Groot(port:DragonFlyBSD)
7  * Copied:    From core/sys/freebsd/sys
8  */
9 module core.sys.dragonflybsd.sys.event;
10 
11 version (DragonFlyBSD):
12 
13 extern (C) nothrow @nogc @system:
14 
15 import core.stdc.stdint;    // intptr_t, uintptr_t
16 import core.sys.posix.time; // timespec
17 
18 enum
19 {
20     EVFILT_READ     =  -1,
21     EVFILT_WRITE    =  -2,
22     EVFILT_AIO      =  -3, /* attached to aio requests */
23     EVFILT_VNODE    =  -4, /* attached to vnodes */
24     EVFILT_PROC     =  -5, /* attached to struct proc */
25     EVFILT_SIGNAL   =  -6, /* attached to struct proc */
26     EVFILT_TIMER    =  -7, /* timers */
27     EVFILT_EXCEPT   =  -8, /* exceptional conditions */
28     EVFILT_USER     =  -9, /* user events */
29     EVFILT_FS       = -10, /* filesystem events */
30     EVFILT_MARKER   = 0xF, /* placemarker for tailq */
31     EVFILT_SYSCOUNT =  10,
32 }
33 
34 extern(D) void EV_SET(kevent_t* kevp, typeof(kevent_t.tupleof) args)
35 {
36     *kevp = kevent_t(args);
37 }
38 
39 struct kevent_t
40 {
41     uintptr_t    ident; /* identifier for this event */
42     short       filter; /* filter for event */
43     ushort       flags;
44     uint        fflags;
45     intptr_t      data;
46     void        *udata; /* opaque user data identifier */
47 }
48 
49 enum
50 {
51     /* actions */
52     EV_ADD          = 0x0001, /* add event to kq (implies enable) */
53     EV_DELETE       = 0x0002, /* delete event from kq */
54     EV_ENABLE       = 0x0004, /* enable event */
55     EV_DISABLE      = 0x0008, /* disable event (not reported) */
56 
57     /* flags */
58     EV_ONESHOT      = 0x0010, /* only report one occurrence */
59     EV_CLEAR        = 0x0020, /* clear event state after reporting */
60     EV_RECEIPT      = 0x0040, /* force EV_ERROR on success, data=0 */
61     EV_DISPATCH     = 0x0080, /* disable event after reporting */
62 
63     EV_SYSFLAGS     = 0xF000, /* reserved by system */
64     EV_FLAG1        = 0x2000, /* filter-specific flag */
65 
66     /* returned values */
67     EV_EOF          = 0x8000, /* EOF detected */
68     EV_ERROR        = 0x4000, /* error, data contains errno */
69     EV_NODATA       = 0x1000, /* EOF and no more data */
70 }
71 
72 enum
73 {
74     /*
75      * data/hint flags/masks for EVFILT_USER, shared with userspace
76      *
77      * On input, the top two bits of fflags specifies how the lower twenty four
78      * bits should be applied to the stored value of fflags.
79      *
80      * On output, the top two bits will always be set to NOTE_FFNOP and the
81      * remaining twenty four bits will contain the stored fflags value.
82      */
83     NOTE_FFNOP      = 0x00000000, /* ignore input fflags */
84     NOTE_FFAND      = 0x40000000, /* AND fflags */
85     NOTE_FFOR       = 0x80000000, /* OR fflags */
86     NOTE_FFCOPY     = 0xc0000000, /* copy fflags */
87     NOTE_FFCTRLMASK = 0xc0000000, /* masks for operations */
88     NOTE_FFLAGSMASK = 0x00ffffff,
89 
90     NOTE_TRIGGER    = 0x01000000, /* Cause the event to be
91                                   triggered for output. */
92 
93     /*
94      * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
95      */
96     NOTE_LOWAT      = 0x0001, /* low water mark */
97     NOTE_OOB        = 0x0002, /* OOB data on a socket */
98 
99     /*
100      * data/hint flags for EVFILT_VNODE, shared with userspace
101      */
102     NOTE_DELETE     = 0x0001, /* vnode was removed */
103     NOTE_WRITE      = 0x0002, /* data contents changed */
104     NOTE_EXTEND     = 0x0004, /* size increased */
105     NOTE_ATTRIB     = 0x0008, /* attributes changed */
106     NOTE_LINK       = 0x0010, /* link count changed */
107     NOTE_RENAME     = 0x0020, /* vnode was renamed */
108     NOTE_REVOKE     = 0x0040, /* vnode access was revoked */
109 
110     NOTE_EXIT       = 0x80000000, /* process exited */
111     NOTE_FORK       = 0x40000000, /* process forked */
112     NOTE_EXEC       = 0x20000000, /* process exec'd */
113     NOTE_PCTRLMASK  = 0xf0000000, /* mask for hint bits */
114     NOTE_PDATAMASK  = 0x000fffff, /* mask for pid */
115 
116     /* additional flags for EVFILT_PROC */
117     NOTE_TRACK      = 0x00000001, /* follow across forks */
118     NOTE_TRACKERR   = 0x00000002, /* could not track child */
119     NOTE_CHILD      = 0x00000004, /* am a child process */
120 }
121 
122 int kqueue();
123 int kevent(int kq, const kevent_t *changelist, int nchanges,
124            int nevents, const timespec *timeout);