13 static void handle(Socket
*, int, int);
19 static struct timespec ivalts
;
23 sockinit(Handle f
, void *x
, int64 ns
)
28 ivalts
.tv_sec
= ns
/ 1000000000;
29 ivalts
.tv_nsec
= ns
% 1000000000;
39 sockwant(Socket
*s
, int rw
)
41 struct kevent ev
= {};
42 struct timespec ts
= {};
44 if (!s
->added
&& !rw
) {
55 ev
.filter
= EVFILT_READ
;
58 ev
.filter
= EVFILT_WRITE
;
61 // check only for hangup
62 ev
.filter
= EVFILT_READ
;
63 ev
.fflags
= NOTE_LOWAT
;
68 return kevent(kq
, &ev
, 1, NULL
, 0, &ts
);
76 int64 e
, t
= nanoseconds();
80 r
= kevent(kq
, NULL
, 0, evs
, n
, &ivalts
);
81 if (r
== -1 && errno
!= EINTR
) {
94 handle(evs
[i
].udata
, evs
[i
].filter
, evs
[i
].flags
);
102 handle(Socket
*s
, int filt
, int flags
)
104 if (flags
& EV_EOF
) {
106 } else if (filt
== EVFILT_READ
) {
108 } else if (filt
== EVFILT_WRITE
) {