From d6ba26951fc873ed7b029773c297a7fc0d606a9e Mon Sep 17 00:00:00 2001 From: Mackenzie Straight Date: Fri, 18 Feb 2005 04:01:29 +0000 Subject: [PATCH] fix win32 server socket bug, update makefile --- Makefile.win32 | 2 +- library/compiler/alien-types.factor | 8 +++---- library/io/win32-server.factor | 18 +++++++++------ library/win32/winsock.factor | 4 ++-- native/fixnum.c | 34 ++++++++++++++--------------- native/fixnum.h | 4 ++++ 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Makefile.win32 b/Makefile.win32 index ce44f6f074..b5a5cdd149 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -22,7 +22,7 @@ OBJS = $(WIN32_OBJS) native\arithmetic.o native\array.o native\bignum.o \ native\word.o native\compiler.o \ native\ffi.o native\boolean.o \ native\debug.o \ - native\hashtable.o native\walk.o + native\hashtable.o native\scan.o \ default: @echo "Run 'make' with one of the following parameters:" diff --git a/library/compiler/alien-types.factor b/library/compiler/alien-types.factor index 8ccdda177e..dfab976f78 100644 --- a/library/compiler/alien-types.factor +++ b/library/compiler/alien-types.factor @@ -156,8 +156,8 @@ global [ "c-types" set ] bind [ alien-2 ] "getter" set [ set-alien-2 ] "setter" set 2 "width" set - "box_cell" "boxer" set - "unbox_cell" "unboxer" set + "box_unsigned_2" "boxer" set + "unbox_unsigned_2" "unboxer" set ] "ushort" define-c-type [ @@ -172,8 +172,8 @@ global [ "c-types" set ] bind [ alien-1 ] "getter" set [ set-alien-1 ] "setter" set 1 "width" set - "box_cell" "boxer" set - "unbox_cell" "unboxer" set + "box_unsigned_1" "boxer" set + "unbox_unsigned_1" "unboxer" set ] "uchar" define-c-type [ diff --git a/library/io/win32-server.factor b/library/io/win32-server.factor index d20d5b18ed..20697eaa61 100644 --- a/library/io/win32-server.factor +++ b/library/io/win32-server.factor @@ -77,14 +77,18 @@ SYMBOL: socket : listen-socket ( socket -- ) 20 wsa-listen 0 = [ handle-socket-error ] unless ; -C: win32-client-stream ( buf stream -- stream ) - [ set-win32-client-stream-delegate ] keep >r - buffer-ptr 0 32 32 - dup >r dup >r - GetAcceptExSockaddrs r> r> drop +: sockaddr>string ( sockaddr -- string ) dup sockaddr-in-port ntohs swap sockaddr-in-addr inet-ntoa - [ , ":" , unparse , ] make-string - r> [ set-win32-client-stream-host ] keep ; + [ , ":" , unparse , ] make-string ; + +: extract-remote-host ( buffer -- host ) + buffer-ptr 0 32 32 + dup >r + GetAcceptExSockaddrs r> indirect-pointer-value sockaddr>string ; + +C: win32-client-stream ( buf stream -- stream ) + [ set-win32-client-stream-delegate extract-remote-host ] keep + [ set-win32-client-stream-host ] keep ; M: win32-client-stream client-stream-host win32-client-stream-host ; diff --git a/library/win32/winsock.factor b/library/win32/winsock.factor index 407c37457a..3fc03d4faa 100644 --- a/library/win32/winsock.factor +++ b/library/win32/winsock.factor @@ -58,10 +58,10 @@ END-STRUCT alien-invoke ; : htons ( short -- short ) - "short" "winsock" "htons" [ "short" ] alien-invoke ; + "ushort" "winsock" "htons" [ "ushort" ] alien-invoke ; : ntohs ( short -- short ) - "short" "winsock" "ntohs" [ "short" ] alien-invoke ; + "ushort" "winsock" "ntohs" [ "ushort" ] alien-invoke ; : wsa-bind ( socket sockaddr len -- status ) "int" "winsock" "bind" [ "void*" "sockaddr-in*" "int" ] alien-invoke ; diff --git a/native/fixnum.c b/native/fixnum.c index 589131b455..233e135925 100644 --- a/native/fixnum.c +++ b/native/fixnum.c @@ -203,26 +203,24 @@ void primitive_fixnum_not(void) drepl(tag_fixnum(~untag_fixnum_fast(dpeek()))); } -/* FFI calls this */ -void box_signed_1(signed char integer) -{ - dpush(tag_integer(integer)); +#define DEFBOX(name,type) \ +void name (type integer) \ +{ \ + dpush(tag_integer(integer)); \ } -/* FFI calls this */ -void box_signed_2(signed short integer) -{ - dpush(tag_integer(integer)); +#define DEFUNBOX(name,type) \ +type name(void) \ +{ \ + return to_fixnum(dpop()); \ } -/* FFI calls this */ -signed char unbox_signed_1(void) -{ - return to_fixnum(dpop()); -} +DEFBOX(box_signed_1, signed char) +DEFBOX(box_signed_2, signed short) +DEFBOX(box_unsigned_1, unsigned char) +DEFBOX(box_unsigned_2, unsigned short) +DEFUNBOX(unbox_signed_1, signed char) +DEFUNBOX(unbox_signed_2, signed short) +DEFUNBOX(unbox_unsigned_1, unsigned char) +DEFUNBOX(unbox_unsigned_2, unsigned short) -/* FFI calls this */ -signed short unbox_signed_2(void) -{ - return to_fixnum(dpop()); -} diff --git a/native/fixnum.h b/native/fixnum.h index d91602f096..87f7080333 100644 --- a/native/fixnum.h +++ b/native/fixnum.h @@ -30,5 +30,9 @@ void primitive_fixnum_greatereq(void); void primitive_fixnum_not(void); DLLEXPORT void box_signed_1(signed char integer); DLLEXPORT void box_signed_2(signed short integer); +DLLEXPORT void box_unsigned_1(unsigned char integer); +DLLEXPORT void box_unsigned_2(unsigned short integer); DLLEXPORT signed char unbox_signed_1(void); DLLEXPORT signed short unbox_signed_2(void); +DLLEXPORT unsigned char unbox_unsigned_1(void); +DLLEXPORT unsigned short unbox_unsigned_2(void);