win32 client sockets

cvs
Mackenzie Straight 2005-08-31 22:42:52 +00:00
parent acc09fb4e0
commit eb1a085ddb
2 changed files with 30 additions and 1 deletions

View File

@ -42,7 +42,7 @@ SYMBOL: socket
WSAGetLastError [
ERROR_IO_PENDING ERROR_SUCCESS
] member? [
win32-error-message throw
WSAGetLastError win32-error-message throw
] unless ;
: new-socket ( -- socket )
@ -97,6 +97,12 @@ M: win32-server expire ( -- )
timeout get [ millis cutoff get > [ socket get CancelIo ] when ] when
] bind ;
: client-sockaddr ( host port -- sockaddr )
setup-sockaddr [
>r gethostbyname handle-socket-error hostent-addr
r> set-sockaddr-in-addr
] keep ;
IN: io
: accept ( server -- client )
win32-server-this [
@ -111,3 +117,8 @@ IN: io
dupd <win32-client-stream> swap buffer-free
] bind ;
: <client> ( host port -- stream )
maybe-init-winsock client-sockaddr new-socket
[ swap "sockaddr-in" c-size connect drop handle-socket-error ] keep
dup add-completion <win32-stream> <line-reader> ;

View File

@ -85,3 +85,21 @@ END-STRUCT
: GetAcceptExSockaddrs ( stack effect is too long to put here -- )
"void" "mswsock" "GetAcceptExSockaddrs"
[ "void*" "int" "int" "int" "void*" "void*" "void*" "void*" ] alien-invoke ;
BEGIN-STRUCT: hostent
FIELD: char* name
FIELD: void* aliases
FIELD: short addrtype
FIELD: short length
FIELD: void* addr-list
END-STRUCT
: hostent-addr hostent-addr-list *void* *uint ;
: gethostbyname ( name -- hostent )
"hostent*" "winsock" "gethostbyname" [ "char*" ] alien-invoke ;
: connect ( socket sockaddr addrlen -- int )
"int" "winsock" "connect" [ "void*" "sockaddr-in*" "int" ]
alien-invoke ;