Working on epoll
parent
cc9646c80d
commit
81c5b413f4
|
@ -1,7 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.c-types kernel io.nonblocking io.unix.backend
|
||||
bit-arrays sequences assocs unix math namespaces structs ;
|
||||
bit-arrays sequences assocs unix unix.linux.epoll math
|
||||
namespaces structs ;
|
||||
IN: io.unix.epoll
|
||||
|
||||
TUPLE: epoll-mx events ;
|
||||
|
@ -18,17 +19,17 @@ TUPLE: epoll-mx events ;
|
|||
|
||||
GENERIC: io-task-events ( task -- n )
|
||||
|
||||
M: input-task drop EPOLLIN ;
|
||||
M: input-task io-task-events drop EPOLLIN ;
|
||||
|
||||
M: output-task drop EPOLLOUT ;
|
||||
M: output-task io-task-events drop EPOLLOUT ;
|
||||
|
||||
: make-event ( task -- event )
|
||||
"epoll-event" <c-object>
|
||||
over io-task-events over set-epoll-event-events
|
||||
over io-task-fd over set-epoll-fd ;
|
||||
swap io-task-fd over set-epoll-event-fd ;
|
||||
|
||||
: do-epoll-ctl ( task mx what -- )
|
||||
>r >r make-event r> mx-fd r> pick event-data *int roll
|
||||
>r >r make-event r> mx-fd r> pick epoll-event-fd roll
|
||||
epoll_ctl io-error ;
|
||||
|
||||
M: epoll-mx register-io-task ( task mx -- )
|
||||
|
@ -37,9 +38,9 @@ M: epoll-mx register-io-task ( task mx -- )
|
|||
M: epoll-mx unregister-io-task ( task mx -- )
|
||||
EPOLL_CTL_DEL do-epoll-ctl ;
|
||||
|
||||
: wait-kevent ( mx timeout -- n )
|
||||
>r mx-fd epoll-mx-events max-events r> epoll_wait
|
||||
dup multiplexer-error ;
|
||||
: wait-event ( mx timeout -- n )
|
||||
>r { mx-fd epoll-mx-events } get-slots max-events
|
||||
r> epoll_wait dup multiplexer-error ;
|
||||
|
||||
: epoll-read-task ( mx fd -- )
|
||||
over mx-reads at* [ handle-io-task ] [ 2drop ] if ;
|
||||
|
@ -51,7 +52,9 @@ M: epoll-mx unregister-io-task ( task mx -- )
|
|||
epoll-event-fd 2dup epoll-read-task epoll-write-task ;
|
||||
|
||||
: handle-events ( mx n -- )
|
||||
[ over epoll-mx-events kevent-nth handle-kevent ] with each ;
|
||||
[
|
||||
over epoll-mx-events epoll-event-nth handle-event
|
||||
] with each ;
|
||||
|
||||
M: epoll-mx wait-for-events ( ms mx -- )
|
||||
dup rot wait-kevent handle-kevents ;
|
||||
dup rot wait-event handle-events ;
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: io.unix.linux
|
||||
USING: io.unix.backend io.unix.select namespaces kernel assocs ;
|
||||
USING: io.backend io.unix.backend io.unix.launcher io.unix.epoll
|
||||
namespaces kernel assocs unix.process ;
|
||||
|
||||
TUPLE: linux-io ;
|
||||
|
||||
INSTANCE: linux-io unix-io
|
||||
|
||||
M: linux-io init-io ( -- )
|
||||
start-wait-loop
|
||||
<epoll-mx> mx set-global ;
|
||||
<epoll-mx> mx set-global
|
||||
start-wait-loop ;
|
||||
|
||||
M: linux-io wait-for-pid ( pid -- status )
|
||||
[ kqueue-mx get-global add-pid-task stop ] curry callcc1 ;
|
||||
M: linux-io wait-for-process ( pid -- status )
|
||||
wait-for-pid ;
|
||||
|
||||
T{ linux-io } io-backend set-global
|
||||
|
|
|
@ -5,6 +5,6 @@ system vocabs.loader ;
|
|||
{
|
||||
{ [ bsd? ] [ "io.unix.bsd" ] }
|
||||
{ [ macosx? ] [ "io.unix.bsd" ] }
|
||||
{ [ linux? ] [ "io.unix.backend.linux" ] }
|
||||
{ [ solaris? ] [ "io.unix.backend.solaris" ] }
|
||||
{ [ linux? ] [ "io.unix.linux" ] }
|
||||
{ [ solaris? ] [ "io.unix.solaris" ] }
|
||||
} cond require
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: unix.linux.epoll
|
||||
USING: alien.syntax ;
|
||||
USING: alien.syntax math ;
|
||||
|
||||
FUNCTION: int epoll_create ( int size ) ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue