io.sockets.windows: wrap ioctlsocket and related constants to enable

setting sockets in non-blocking mode
db4
Björn Lindqvist 2014-03-27 19:38:08 +01:00 committed by Doug Coleman
parent 4676ff921a
commit ee19a97869
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,20 @@
USING: accessors continuations io.sockets io.sockets.windows kernel sequences tools.test
urls windows.winsock ;
IN: io.sockets.windows.tests
: google-socket ( -- socket )
URL" http://www.google.com" url-addr resolve-host first
SOCK_STREAM open-socket ;
{ } [
google-socket
{ FIONBIO FIONREAD } [
google-socket swap execute( -- x )
[ 1 set-ioctl-socket ] [ 0 set-ioctl-socket ] 2bi
] each drop
] unit-test
{ t } [
[ google-socket 1337 -8 set-ioctl-socket ]
[ [ winsock-exception? ] [ n>> 10045 = ] bi and ] recover
] unit-test

View File

@ -11,6 +11,9 @@ IN: io.sockets.windows
: set-socket-option ( handle level opt -- )
[ handle>> ] 2dip 1 int <ref> dup byte-length setsockopt socket-error ;
: set-ioctl-socket ( handle cmd arg -- )
[ handle>> ] 2dip ulong <ref> ioctlsocket socket-error ;
M: windows addrinfo-error ( n -- )
winsock-return-check ;

View File

@ -88,6 +88,10 @@ CONSTANT: IPPROTO_TCP 6
CONSTANT: IPPROTO_UDP 17
CONSTANT: IPPROTO_RM 113
CONSTANT: FIOASYNC 0x8004667d
CONSTANT: FIONBIO 0x8004667e
CONSTANT: FIONREAD 0x4004667f
CONSTANT: WSA_FLAG_OVERLAPPED 1
ALIAS: WSA_WAIT_EVENT_0 WAIT_OBJECT_0
ALIAS: WSA_MAXIMUM_WAIT_EVENTS MAXIMUM_WAIT_OBJECTS
@ -166,6 +170,7 @@ STRUCT: fd_set
LIBRARY: winsock
FUNCTION: int setsockopt ( SOCKET s, int level, int optname, c-string optval, int optlen ) ;
FUNCTION: int ioctlsocket ( SOCKET s, long cmd, ulong* *argp ) ;
FUNCTION: ushort htons ( ushort n ) ;
FUNCTION: ushort ntohs ( ushort n ) ;