epoll almost works

db4
Slava 2008-01-23 03:07:15 -05:00
parent 68ac7b81d4
commit 09eb56d0c2
4 changed files with 10 additions and 7 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007 Slava Pestov.
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: init kernel system ;
USING: init kernel system namespaces ;
IN: io.backend
SYMBOL: io-backend

View File

@ -29,13 +29,15 @@ M: output-task io-task-events drop EPOLLOUT ;
swap io-task-fd over set-epoll-event-fd ;
: do-epoll-ctl ( task mx what -- )
>r >r make-event r> mx-fd r> pick epoll-event-fd roll
>r mx-fd r> rot dup io-task-fd swap make-event
epoll_ctl io-error ;
M: epoll-mx register-io-task ( task mx -- )
EPOLL_CTL_ADD do-epoll-ctl ;
2dup EPOLL_CTL_ADD do-epoll-ctl
delegate register-io-task ;
M: epoll-mx unregister-io-task ( task mx -- )
2dup delegate unregister-io-task
EPOLL_CTL_DEL do-epoll-ctl ;
: wait-event ( mx timeout -- n )
@ -46,7 +48,7 @@ M: epoll-mx unregister-io-task ( task mx -- )
over mx-reads at* [ handle-io-task ] [ 2drop ] if ;
: epoll-write-task ( mx fd -- )
over mx-reads at* [ handle-io-task ] [ 2drop ] if ;
over mx-writes at* [ handle-io-task ] [ 2drop ] if ;
: handle-event ( mx kevent -- )
epoll-event-fd 2dup epoll-read-task epoll-write-task ;

View File

@ -15,4 +15,4 @@ M: linux-io init-io ( -- )
M: linux-io wait-for-process ( pid -- status )
wait-for-pid ;
T{ linux-io } set-io-backend
T{ linux-io } io-backend set-global ! set-io-backend

View File

@ -9,7 +9,8 @@ FUNCTION: int epoll_ctl ( int epfd, int op, int fd, epoll_event* event ) ;
C-STRUCT: epoll-event
{ "uint" "events" }
{ "uint" "fd" } ;
{ "uint" "fd" }
{ "uint" "padding" } ;
FUNCTION: int epoll_wait ( int epfd, epoll_event* events, int maxevents, int timeout ) ;