GENERIC: wait-for-events ( ms mx -- )
: input-available ( fd mx -- )
- remove-input-callbacks [ resume ] each ;
+ reads>> delete-at* drop [ resume ] each ;
: output-available ( fd mx -- )
- remove-output-callbacks [ resume ] each ;
+ writes>> delete-at* drop [ resume ] each ;
M: fd cancel-operation ( fd -- )
dup disposed>> [ drop ] [
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types combinators io.unix.backend
kernel math.bitwise sequences struct-arrays unix unix.kqueue
-unix.time ;
+unix.time assocs ;
IN: io.unix.kqueue
-TUPLE: kqueue-mx < mx events monitors ;
+TUPLE: kqueue-mx < mx events ;
: max-events ( -- n )
#! We read up to 256 events at a time. This is an arbitrary
: <kqueue-mx> ( -- mx )
kqueue-mx new-mx
- H{ } clone >>monitors
kqueue dup io-error >>fd
max-events "kevent" <struct-array> >>events ;
M: kqueue-mx add-output-callback ( thread fd mx -- )
[ call-next-method ] [
- [ EVFILT_WRITE EV_DELETE make-kevent ] dip
+ [ EVFILT_WRITE { EV_ADD EV_ONESHOT } flags make-kevent ] dip
register-kevent
] 2bi ;
-: cancel-input-callbacks ( fd mx -- seq )
- [
- [ EVFILT_READ EV_DELETE make-kevent ] dip
- register-kevent
- ] [ remove-input-callbacks ] 2bi ;
-
-: cancel-output-callbacks ( fd mx -- seq )
- [
- [ EVFILT_WRITE EV_DELETE make-kevent ] dip
- register-kevent
- ] [ remove-output-callbacks ] 2bi ;
+M: kqueue-mx remove-input-callbacks ( fd mx -- seq )
+ 2dup reads>> key? [
+ [ call-next-method ] [
+ [ EVFILT_READ EV_DELETE make-kevent ] dip
+ register-kevent
+ ] 2bi
+ ] [ 2drop f ] if ;
-M: fd cancel-operation ( fd -- )
- dup disposed>> [ drop ] [
- fd>>
- mx get-global
- [ cancel-input-callbacks [ t swap resume-with ] each ]
- [ cancel-output-callbacks [ t swap resume-with ] each ]
- 2bi
- ] if ;
+M: kqueue-mx remove-output-callbacks ( fd mx -- seq )
+ 2dup writes>> key? [
+ [
+ [ EVFILT_WRITE EV_DELETE make-kevent ] dip
+ register-kevent
+ ] [ call-next-method ] 2bi
+ ] [ 2drop f ] if ;
: wait-kevent ( mx timespec -- n )
[
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: io.unix.macosx
-USING: io.unix.bsd io.backend system ;
+USING: io.unix.backend io.unix.bsd io.unix.kqueue io.backend
+namespaces system ;
+
+M: macosx init-io ( -- )
+ <kqueue-mx> mx set-global ;
macosx set-io-backend
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax system sequences vocabs.loader words ;
+USING: alien.syntax system sequences vocabs.loader words
+accessors ;
IN: unix.kqueue
<< "unix.kqueue." os name>> append require >>