I/O fixes

db4
Slava Pestov 2008-01-24 19:21:10 -04:00
parent c3d286651a
commit 783e63781f
3 changed files with 17 additions and 10 deletions

View File

@ -106,9 +106,14 @@ M: f parse-sockaddr nip ;
[ ] unfold nip [ ] subset ;
: prepare-resolve-host ( host serv passive? -- host' serv' flags )
#! If the port is a number, we resolve for 'http' then
#! change it later. This is a workaround for a FreeBSD
#! getaddrinfo() limitation -- on Windows, Linux and Mac,
#! we can convert a number to a string and pass that as the
#! service name, but on FreeBSD this gives us an unknown
#! service error.
>r
>r string>char-alien r>
dup integer? [ port-override set f ] [ string>char-alien ] if
dup integer? [ port-override set "http" ] when
r> AI_PASSIVE 0 ? ;
M: object resolve-host ( host serv passive? -- seq )

0
extra/io/sockets/sockets.factor Normal file → Executable file
View File

View File

@ -116,25 +116,27 @@ M: windows-nt-io add-completion ( handle -- )
: lookup-callback ( GetQueuedCompletion-args -- callback )
io-hash get-global delete-at* drop ;
: wait-for-io ( timeout -- continuation/f )
: handle-overlapped ( timeout -- ? )
wait-for-overlapped [
GetLastError dup expected-io-error? [
2drop f
2drop t
] [
dup eof? [
drop lookup-callback
dup io-callback-port t swap set-port-eof?
io-callback-continuation
] [
(win32-error-string) swap lookup-callback
[ io-callback-port set-port-error ] keep
io-callback-continuation
] if
] if io-callback-continuation schedule-thread f
] if
] [
lookup-callback io-callback-continuation
lookup-callback
io-callback-continuation schedule-thread f
] if ;
: drain-overlapped ( timeout -- )
handle-overlapped [ 0 drain-overlapped ] unless ;
: maybe-expire ( io-callbck -- )
io-callback-port
dup timeout? [
@ -144,10 +146,10 @@ M: windows-nt-io add-completion ( handle -- )
] if ;
: cancel-timeout ( -- )
io-hash get-global values [ maybe-expire ] each ;
io-hash get-global [ nip maybe-expire ] assoc-each ;
M: windows-nt-io io-multiplex ( ms -- )
cancel-timeout wait-for-io [ schedule-thread ] when* ;
cancel-timeout drain-overlapped ;
M: windows-nt-io init-io ( -- )
<master-completion-port> master-completion-port set-global