1 /** 2 * D header file for FreeBSD. 3 * 4 * Copyright: Copyright Martin Nowak 2012. 5 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 * Authors: Martin Nowak 7 */ 8 9 /* Copyright Martin Nowak 2012. 10 * Distributed under the Boost Software License, Version 1.0. 11 * (See accompanying file LICENSE or copy at 12 * http://www.boost.org/LICENSE_1_0.txt) 13 */ 14 module core.sys.freebsd.sys.event; 15 16 version (FreeBSD): 17 extern (C): 18 nothrow: 19 @nogc: 20 21 import core.stdc.stdint; // intptr_t, uintptr_t 22 import core.sys.posix.time; // timespec 23 24 enum 25 { 26 EVFILT_READ = -1, 27 EVFILT_WRITE = -2, 28 EVFILT_AIO = -3, /* attached to aio requests */ 29 EVFILT_VNODE = -4, /* attached to vnodes */ 30 EVFILT_PROC = -5, /* attached to struct proc */ 31 EVFILT_SIGNAL = -6, /* attached to struct proc */ 32 EVFILT_TIMER = -7, /* timers */ 33 EVFILT_PROCDESC = -8, /* attached to process descriptors */ 34 EVFILT_FS = -9, /* filesystem events */ 35 EVFILT_LIO = -10, /* attached to lio requests */ 36 EVFILT_USER = -11, /* User events */ 37 EVFILT_SENDFILE = -12, /* attached to sendfile requests */ 38 EVFILT_SYSCOUNT = 11, 39 } 40 41 extern(D) void EV_SET(kevent_t* kevp, typeof(kevent_t.tupleof) args) 42 { 43 *kevp = kevent_t(args); 44 } 45 46 struct kevent_t 47 { 48 uintptr_t ident; /* identifier for this event */ 49 short filter; /* filter for event */ 50 ushort flags; 51 uint fflags; 52 intptr_t data; 53 void *udata; /* opaque user data identifier */ 54 } 55 56 enum 57 { 58 /* actions */ 59 EV_ADD = 0x0001, /* add event to kq (implies enable) */ 60 EV_DELETE = 0x0002, /* delete event from kq */ 61 EV_ENABLE = 0x0004, /* enable event */ 62 EV_DISABLE = 0x0008, /* disable event (not reported) */ 63 EV_FORCEONESHOT = 0x0100, /* enable _ONESHOT and force trigger */ 64 65 /* flags */ 66 EV_ONESHOT = 0x0010, /* only report one occurrence */ 67 EV_CLEAR = 0x0020, /* clear event state after reporting */ 68 EV_RECEIPT = 0x0040, /* force EV_ERROR on success, data=0 */ 69 EV_DISPATCH = 0x0080, /* disable event after reporting */ 70 71 EV_SYSFLAGS = 0xF000, /* reserved by system */ 72 EV_DROP = 0x1000, /* note should be dropped */ 73 EV_FLAG1 = 0x2000, /* filter-specific flag */ 74 EV_FLAG2 = 0x4000, /* filter-specific flag */ 75 76 /* returned values */ 77 EV_EOF = 0x8000, /* EOF detected */ 78 EV_ERROR = 0x4000, /* error, data contains errno */ 79 } 80 81 enum 82 { 83 /* 84 * data/hint flags/masks for EVFILT_USER, shared with userspace 85 * 86 * On input, the top two bits of fflags specifies how the lower twenty four 87 * bits should be applied to the stored value of fflags. 88 * 89 * On output, the top two bits will always be set to NOTE_FFNOP and the 90 * remaining twenty four bits will contain the stored fflags value. 91 */ 92 NOTE_FFNOP = 0x00000000, /* ignore input fflags */ 93 NOTE_FFAND = 0x40000000, /* AND fflags */ 94 NOTE_FFOR = 0x80000000, /* OR fflags */ 95 NOTE_FFCOPY = 0xc0000000, /* copy fflags */ 96 NOTE_FFCTRLMASK = 0xc0000000, /* masks for operations */ 97 NOTE_FFLAGSMASK = 0x00ffffff, 98 99 NOTE_TRIGGER = 0x01000000, /* Cause the event to be 100 triggered for output. */ 101 102 /* 103 * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace 104 */ 105 NOTE_LOWAT = 0x0001, /* low water mark */ 106 NOTE_FILE_POLL = 0x0002, /* behave like poll() */ 107 108 /* 109 * data/hint flags for EVFILT_VNODE, shared with userspace 110 */ 111 NOTE_DELETE = 0x0001, /* vnode was removed */ 112 NOTE_WRITE = 0x0002, /* data contents changed */ 113 NOTE_EXTEND = 0x0004, /* size increased */ 114 NOTE_ATTRIB = 0x0008, /* attributes changed */ 115 NOTE_LINK = 0x0010, /* link count changed */ 116 NOTE_RENAME = 0x0020, /* vnode was renamed */ 117 NOTE_REVOKE = 0x0040, /* vnode access was revoked */ 118 NOTE_OPEN = 0x0080, /* vnode was opened */ 119 NOTE_CLOSE = 0x0100, /* file closed, fd did not 120 allowed write */ 121 NOTE_CLOSE_WRITE = 0x0200, /* file closed, fd did allowed 122 write */ 123 NOTE_READ = 0x0400, /* file was read */ 124 125 /* 126 * data/hint flags for EVFILT_PROC and EVFILT_PROCDESC, shared with userspace 127 */ 128 NOTE_EXIT = 0x80000000, /* process exited */ 129 NOTE_FORK = 0x40000000, /* process forked */ 130 NOTE_EXEC = 0x20000000, /* process exec'd */ 131 NOTE_PCTRLMASK = 0xf0000000, /* mask for hint bits */ 132 NOTE_PDATAMASK = 0x000fffff, /* mask for pid */ 133 134 /* additional flags for EVFILT_PROC */ 135 NOTE_TRACK = 0x00000001, /* follow across forks */ 136 NOTE_TRACKERR = 0x00000002, /* could not track child */ 137 NOTE_CHILD = 0x00000004, /* am a child process */ 138 139 /* additional flags for EVFILT_TIMER */ 140 NOTE_SECONDS = 0x00000001, /* data is seconds */ 141 NOTE_MSECONDS = 0x00000002, /* data is milliseconds */ 142 NOTE_USECONDS = 0x00000004, /* data is microseconds */ 143 NOTE_NSECONDS = 0x00000008, /* data is nanoseconds */ 144 } 145 146 int kqueue(); 147 int kevent(int kq, const kevent_t *changelist, int nchanges, 148 kevent_t *eventlist, int nevents, 149 const timespec *timeout); 150