quit-responder fix, pointless and misguided type number rearrangement

cvs
Slava Pestov 2004-10-31 19:36:42 +00:00
parent 4af94c0dc3
commit 7451cfb339
26 changed files with 221 additions and 200 deletions

View File

@ -1,4 +1,4 @@
CC = gcc CC = gcc34
DEFAULT_CFLAGS = -Wall -export-dynamic -g $(SITE_CFLAGS) DEFAULT_CFLAGS = -Wall -export-dynamic -g $(SITE_CFLAGS)
DEFAULT_LIBS = -lm DEFAULT_LIBS = -lm

View File

@ -1,9 +1,6 @@
FFI:
- add a socket timeout - add a socket timeout
- fix error postoning -- not all errors thrown by i/o code are - fix error postoning -- not all errors thrown by i/o code are
postponed postponed
- quit responder breaks with multithreading
+ compiler/ffi: + compiler/ffi:
@ -39,7 +36,6 @@ FFI:
+ listener/plugin: + listener/plugin:
- clean up listener's action popups
- accept multi-line input in listener - accept multi-line input in listener
- don't show listener on certain commands - don't show listener on certain commands
- NPE in ErrorHighlight - NPE in ErrorHighlight

View File

@ -96,33 +96,16 @@ USE: url-encoding
] catch ; ] catch ;
: httpd-connection ( socket -- ) : httpd-connection ( socket -- )
#! We're single-threaded in Java Factor, and "http-server" get accept [ httpd-client ] in-thread drop ;
#! multi-threaded in CFactor.
java? [
httpd-client
] [
[
httpd-client
] in-thread drop
] ifte ;
: quit-flag ( -- ? ) : httpd-loop ( -- )
global [ "httpd-quit" get ] bind ; [ httpd-connection ] forever ;
: clear-quit-flag ( -- )
global [ "httpd-quit" off ] bind ;
: httpd-loop ( server -- server )
quit-flag [
dup dup accept httpd-connection
httpd-loop
] unless ;
: (httpd) ( port -- ) : (httpd) ( port -- )
<server> [ <server> "http-server" set [
httpd-loop httpd-loop
] [ ] [
swap fclose clear-quit-flag rethrow "http-server" get fclose rethrow
] catch ; ] catch ;
: httpd ( port -- ) : httpd ( port -- )

View File

@ -27,12 +27,12 @@
IN: quit-responder IN: quit-responder
USE: combinators USE: combinators
USE: namespaces
USE: stdio
USE: stack
USE: httpd USE: httpd
USE: httpd-responder USE: httpd-responder
USE: namespaces
USE: stack
USE: stdio
USE: streams
: quit-prohibited ( -- ) : quit-prohibited ( -- )
"404 quit prohibited" httpd-error ; "404 quit prohibited" httpd-error ;
@ -43,5 +43,5 @@ USE: httpd-responder
"quit-prohibited" get [ "quit-prohibited" get [
quit-prohibited quit-prohibited
] [ ] [
global [ t "httpd-quit" set ] bind "http-server" get fclose
] ifte ; ] ifte ;

View File

@ -94,12 +94,10 @@ USE: words
: f-type 6 ; : f-type 6 ;
: t-type 7 ; : t-type 7 ;
: array-type 8 ; : array-type 8 ;
: vector-type 9 ; : bignum-type 9 ;
: string-type 10 ; : float-type 10 ;
: sbuf-type 11 ; : vector-type 11 ;
: handle-type 12 ; : string-type 12 ;
: bignum-type 13 ;
: float-type 14 ;
: immediate ( x tag -- tagged ) swap tag-bits shift bitor ; : immediate ( x tag -- tagged ) swap tag-bits shift bitor ;
: >header ( id -- tagged ) header-tag immediate ; : >header ( id -- tagged ) header-tag immediate ;

View File

@ -80,7 +80,7 @@ USE: stdio
"/library/format.factor" "/library/format.factor"
"/library/platform/native/unparser.factor" "/library/platform/native/unparser.factor"
"/library/styles.factor" "/library/presentation.factor"
"/library/vocabulary-style.factor" "/library/vocabulary-style.factor"
"/library/prettyprint.factor" "/library/prettyprint.factor"
"/library/platform/native/debugger.factor" "/library/platform/native/debugger.factor"

View File

@ -106,6 +106,9 @@ USE: words
: callstack-overflow-error ( obj -- ) : callstack-overflow-error ( obj -- )
drop "Callstack overflow" print ; drop "Callstack overflow" print ;
: port-closed-error ( obj -- )
"Port closed: " write . ;
: kernel-error. ( obj n -- str ) : kernel-error. ( obj n -- str )
{ {
expired-error expired-error
@ -127,6 +130,7 @@ USE: words
datastack-overflow-error datastack-overflow-error
callstack-underflow-error callstack-underflow-error
callstack-overflow-error callstack-overflow-error
port-closed-error
} vector-nth execute ; } vector-nth execute ;
: kernel-error? ( obj -- ? ) : kernel-error? ( obj -- ? )

View File

@ -59,23 +59,23 @@ USE: vectors
: hashcode ( obj -- hash ) : hashcode ( obj -- hash )
#! If two objects are =, they must have equal hashcodes. #! If two objects are =, they must have equal hashcodes.
{ {
nop nop ! 0
word-hashcode word-hashcode ! 1
cons-hashcode cons-hashcode ! 2
default-hashcode default-hashcode ! 3
>fixnum >fixnum ! 4
>fixnum >fixnum ! 5
default-hashcode default-hashcode ! 6
default-hashcode default-hashcode ! 7
default-hashcode default-hashcode ! 8
vector-hashcode >fixnum ! 9
str-hashcode >fixnum ! 10
sbuf-hashcode vector-hashcode ! 11
default-hashcode str-hashcode ! 12
>fixnum sbuf-hashcode ! 13
>fixnum default-hashcode ! 14
default-hashcode default-hashcode ! 15
default-hashcode default-hashcode ! 16
} generic ; } generic ;
IN: math DEFER: number= ( defined later... ) IN: math DEFER: number= ( defined later... )
@ -83,24 +83,24 @@ IN: kernel
: = ( obj obj -- ? ) : = ( obj obj -- ? )
#! Push t if a is isomorphic to b. #! Push t if a is isomorphic to b.
{ {
number= number= ! 0
eq? eq? ! 1
cons= cons= ! 2
eq? eq? ! 3
number= number= ! 4
number= number= ! 5
eq? eq? ! 6
eq? eq? ! 7
eq? eq? ! 8
vector= number= ! 9
str= number= ! 10
sbuf= vector= ! 11
eq? str= ! 12
number= sbuf= ! 13
number= eq? ! 14
eq? eq? ! 15
eq? eq? ! 16
} generic ; } generic ;
: 2= ( a b c d -- ? ) : 2= ( a b c d -- ? )
#! Test if a = c, b = d. #! Test if a = c, b = d.

View File

@ -97,14 +97,14 @@ USE: words
(not-=) (not-=)
(not-=) (not-=)
(not-=) (not-=)
(not-=)
(not-=)
(not-=)
(not-=)
bignum= bignum=
float= float=
(not-=) (not-=)
(not-=) (not-=)
(not-=)
(not-=)
(not-=)
(not-=)
} 2generic ; } 2generic ;
: + ( x y -- x+y ) : + ( x y -- x+y )
@ -118,14 +118,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum+ bignum+
float+ float+
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: - ( x y -- x-y ) : - ( x y -- x-y )
@ -139,14 +139,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum- bignum-
float- float-
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: * ( x y -- x*y ) : * ( x y -- x*y )
@ -160,14 +160,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum* bignum*
float* float*
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: / ( x y -- x/y ) : / ( x y -- x/y )
@ -181,14 +181,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
ratio ratio
float/f float/f
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: /i ( x y -- x/y ) : /i ( x y -- x/y )
@ -202,14 +202,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum/i bignum/i
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: /f ( x y -- x/y ) : /f ( x y -- x/y )
@ -223,14 +223,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum/f bignum/f
float/f float/f
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: mod ( x y -- x%y ) : mod ( x y -- x%y )
@ -244,14 +244,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum-mod bignum-mod
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: /mod ( x y -- x/y x%y ) : /mod ( x y -- x/y x%y )
@ -265,14 +265,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum/mod bignum/mod
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: bitand ( x y -- x&y ) : bitand ( x y -- x&y )
@ -286,14 +286,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum-bitand bignum-bitand
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: bitor ( x y -- x|y ) : bitor ( x y -- x|y )
@ -307,14 +307,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum-bitor bignum-bitor
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: bitxor ( x y -- x^y ) : bitxor ( x y -- x^y )
@ -328,14 +328,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum-bitxor bignum-bitxor
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: bitnot ( x -- ~x ) : bitnot ( x -- ~x )
@ -349,14 +349,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum-bitnot bignum-bitnot
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} generic ; } generic ;
: shift ( x n -- x<<n ) : shift ( x n -- x<<n )
@ -370,14 +370,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum-shift bignum-shift
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: < ( x y -- ? ) : < ( x y -- ? )
@ -391,14 +391,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum< bignum<
float< float<
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: <= ( x y -- ? ) : <= ( x y -- ? )
@ -412,14 +412,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum<= bignum<=
float<= float<=
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: > ( x y -- ? ) : > ( x y -- ? )
@ -433,14 +433,14 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum> bignum>
float> float>
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;
: >= ( x y -- ? ) : >= ( x y -- ? )
@ -454,12 +454,12 @@ USE: words
no-method no-method
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
bignum>= bignum>=
float>= float>=
no-method no-method
no-method no-method
no-method
no-method
no-method
no-method
} 2generic ; } 2generic ;

View File

@ -181,6 +181,7 @@ IN: syntax
: #{ : #{
#! Read #{ real imaginary #} #! Read #{ real imaginary #}
scan str>number scan str>number rect> "}" expect parsed ; scan str>number scan str>number rect> "}" expect parsed ;
parsing
! Comments ! Comments
: ( ")" until parsed-stack-effect ; parsing : ( ")" until parsed-stack-effect ; parsing

View File

@ -180,7 +180,7 @@ USE: words
[ client-socket | " host port -- in out " ] [ client-socket | " host port -- in out " ]
[ server-socket | " port -- server " ] [ server-socket | " port -- server " ]
[ close-port | " port -- " ] [ close-port | " port -- " ]
[ add-accept-io-task | " callback server -- " ] [ add-accept-io-task | " server callback -- " ]
[ accept-fd | " server -- host port in out " ] [ accept-fd | " server -- host port in out " ]
[ can-read-line? | " port -- ? " ] [ can-read-line? | " port -- ? " ]
[ add-read-line-io-task | " port callback -- " ] [ add-read-line-io-task | " port callback -- " ]

View File

@ -32,12 +32,12 @@ IN: words : word? ( obj -- ? ) type 1 eq? ;
IN: lists : cons? ( obj -- ? ) type 2 eq? ; IN: lists : cons? ( obj -- ? ) type 2 eq? ;
IN: math : ratio? ( obj -- ? ) type 4 eq? ; IN: math : ratio? ( obj -- ? ) type 4 eq? ;
IN: math : complex? ( obj -- ? ) type 5 eq? ; IN: math : complex? ( obj -- ? ) type 5 eq? ;
IN: vectors : vector? ( obj -- ? ) type 9 eq? ; IN: math : bignum? ( obj -- ? ) type 9 eq? ;
IN: strings : string? ( obj -- ? ) type 10 eq? ; IN: math : float? ( obj -- ? ) type 10 eq? ;
IN: strings : sbuf? ( obj -- ? ) type 11 eq? ; IN: vectors : vector? ( obj -- ? ) type 11 eq? ;
IN: io-internals : port? ( obj -- ? ) type 12 eq? ; IN: strings : string? ( obj -- ? ) type 12 eq? ;
IN: math : bignum? ( obj -- ? ) type 13 eq? ; IN: strings : sbuf? ( obj -- ? ) type 13 eq? ;
IN: math : float? ( obj -- ? ) type 14 eq? ; IN: io-internals : port? ( obj -- ? ) type 14 eq? ;
IN: alien : dll? ( obj -- ? ) type 15 eq? ; IN: alien : dll? ( obj -- ? ) type 15 eq? ;
IN: alien : alien? ( obj -- ? ) type 16 eq? ; IN: alien : alien? ( obj -- ? ) type 16 eq? ;
@ -54,12 +54,12 @@ IN: kernel
[ 6 | "f" ] [ 6 | "f" ]
[ 7 | "t" ] [ 7 | "t" ]
[ 8 | "array" ] [ 8 | "array" ]
[ 9 | "vector" ] [ 9 | "bignum" ]
[ 10 | "string" ] [ 10 | "float" ]
[ 11 | "sbuf" ] [ 11 | "vector" ]
[ 12 | "port" ] [ 12 | "string" ]
[ 13 | "bignum" ] [ 13 | "sbuf" ]
[ 14 | "float" ] [ 14 | "port" ]
[ 15 | "dll" ] [ 15 | "dll" ]
[ 16 | "alien" ] [ 16 | "alien" ]
! These values are only used by the kernel for error ! These values are only used by the kernel for error

View File

@ -133,12 +133,12 @@ DEFER: unparse
unparse-f unparse-f
unparse-t unparse-t
unparse-unknown unparse-unknown
>dec
unparse-float
unparse-unknown unparse-unknown
unparse-str unparse-str
unparse-unknown unparse-unknown
unparse-unknown unparse-unknown
>dec
unparse-float
unparse-unknown unparse-unknown
unparse-unknown unparse-unknown
} generic ; } generic ;

View File

@ -46,8 +46,7 @@ USE: unparser
: (style) ( name -- style ) "styles" get get* ; : (style) ( name -- style ) "styles" get get* ;
: default-style ( -- style ) "default" (style) ; : default-style ( -- style ) "default" (style) ;
: style ( name -- style ) : style ( name -- style ) (style) [ default-style ] unless* ;
(style) [ default-style ] unless* ;
: set-style ( style name -- ) "styles" get set* ; : set-style ( style name -- ) "styles" get set* ;
<namespace> "styles" set <namespace> "styles" set

View File

@ -25,13 +25,13 @@
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: words IN: presentation
USE: combinators USE: combinators
USE: lists USE: lists
USE: kernel USE: kernel
USE: namespaces USE: namespaces
USE: stack USE: stack
USE: presentation USE: words
: vocab-style ( vocab -- style ) : vocab-style ( vocab -- style )
#! Each vocab has a style object specifying how words are #! Each vocab has a style object specifying how words are

View File

@ -4,6 +4,7 @@ CELL arithmetic_type(CELL obj1, CELL obj2)
{ {
CELL type1 = type_of(obj1); CELL type1 = type_of(obj1);
CELL type2 = type_of(obj2); CELL type2 = type_of(obj2);
CELL type; CELL type;
switch(type1) switch(type1)

View File

@ -31,7 +31,7 @@ void primitive_throw(void)
void general_error(CELL error, CELL tagged) void general_error(CELL error, CELL tagged)
{ {
CELL c = cons(error,cons(tagged,F)); CELL c = cons(error,cons(tagged,F));
if(userenv[BREAK_ENV] == 0) if(userenv[BREAK_ENV] == F)
{ {
/* Crash at startup */ /* Crash at startup */
fprintf(stderr,"Error thrown before BREAK_ENV set\n"); fprintf(stderr,"Error thrown before BREAK_ENV set\n");

View File

@ -17,6 +17,7 @@
#define ERROR_DATASTACK_OVERFLOW (16<<3) #define ERROR_DATASTACK_OVERFLOW (16<<3)
#define ERROR_CALLSTACK_UNDERFLOW (17<<3) #define ERROR_CALLSTACK_UNDERFLOW (17<<3)
#define ERROR_CALLSTACK_OVERFLOW (18<<3) #define ERROR_CALLSTACK_OVERFLOW (18<<3)
#define ERROR_CLOSED (19<<3)
void fatal_error(char* msg, CELL tagged); void fatal_error(char* msg, CELL tagged);
void critical_error(char* msg, CELL tagged); void critical_error(char* msg, CELL tagged);

View File

@ -52,7 +52,6 @@ IO_TASK* add_io_task(
} }
void remove_io_task( void remove_io_task(
IO_TASK_TYPE type,
PORT* port, PORT* port,
IO_TASK* io_tasks, IO_TASK* io_tasks,
int* fd_count) int* fd_count)
@ -67,14 +66,6 @@ void remove_io_task(
*fd_count = *fd_count - 1; *fd_count = *fd_count - 1;
} }
void remove_io_tasks(PORT* port)
{
remove_io_task(IO_TASK_READ_LINE,port,
read_io_tasks,&read_fd_count);
remove_io_task(IO_TASK_WRITE,port,
write_io_tasks,&write_fd_count);
}
bool perform_copy_from_io_task(PORT* port, PORT* other_port) bool perform_copy_from_io_task(PORT* port, PORT* other_port)
{ {
if(port->buf_fill == 0) if(port->buf_fill == 0)
@ -124,7 +115,9 @@ void primitive_add_copy_io_task(void)
write_io_tasks,&write_fd_count); write_io_tasks,&write_fd_count);
} }
bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks) /* We set closed to true if there are closed fd's in the set. */
bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks,
bool* closed)
{ {
bool retval = false; bool retval = false;
int i; int i;
@ -135,6 +128,8 @@ bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks)
{ {
if(typep(PORT_TYPE,io_tasks[i].port)) if(typep(PORT_TYPE,io_tasks[i].port))
{ {
if(untag_port(io_tasks[i].port)->closed)
*closed = true;
retval = true; retval = true;
FD_SET(i,fdset); FD_SET(i,fdset);
} }
@ -153,7 +148,7 @@ CELL pop_io_task_callback(
CONS* callbacks = untag_cons(io_tasks[fd].callbacks); CONS* callbacks = untag_cons(io_tasks[fd].callbacks);
CELL callback = callbacks->car; CELL callback = callbacks->car;
if(callbacks->cdr == F) if(callbacks->cdr == F)
remove_io_task(type,port,io_tasks,fd_count); remove_io_task(port,io_tasks,fd_count);
else else
io_tasks[fd].callbacks = callbacks->cdr; io_tasks[fd].callbacks = callbacks->cdr;
return callback; return callback;
@ -208,13 +203,26 @@ CELL perform_io_tasks(fd_set* fdset, IO_TASK* io_tasks, int* fd_count)
for(i = 0; i < *fd_count; i++) for(i = 0; i < *fd_count; i++)
{ {
IO_TASK io_task = io_tasks[i];
if(typep(PORT_TYPE,io_task.port))
{
PORT* port = untag_port(io_task.port);
if(port->closed)
{
return pop_io_task_callback(
io_task.type,port,
io_tasks,fd_count);
}
}
if(FD_ISSET(i,fdset)) if(FD_ISSET(i,fdset))
{ {
if(io_tasks[i].port == F) if(io_task.port == F)
critical_error("select() returned fd for non-existent task",i); critical_error("select() returned fd for non-existent task",i);
else else
{ {
callback = perform_io_task(&io_tasks[i], callback = perform_io_task(&io_task,
io_tasks,fd_count); io_tasks,fd_count);
if(callback != F) if(callback != F)
return callback; return callback;
@ -230,26 +238,34 @@ CELL next_io_task(void)
{ {
CELL callback; CELL callback;
bool closed = false;
bool reading = set_up_fd_set(&read_fd_set, bool reading = set_up_fd_set(&read_fd_set,
read_fd_count,read_io_tasks); read_fd_count,read_io_tasks,&closed);
bool writing = set_up_fd_set(&write_fd_set, bool writing = set_up_fd_set(&write_fd_set,
write_fd_count,write_io_tasks); write_fd_count,write_io_tasks,&closed);
if(!reading && !writing) if(!reading && !writing && !closed)
general_error(ERROR_IO_TASK_NONE,F); general_error(ERROR_IO_TASK_NONE,F);
set_up_fd_set(&except_fd_set, set_up_fd_set(&except_fd_set,read_fd_count,read_io_tasks,&closed);
read_fd_count,read_io_tasks);
if(!closed)
{
select(read_fd_count > write_fd_count
? read_fd_count : write_fd_count,
&read_fd_set,&write_fd_set,&except_fd_set,NULL);
}
callback = perform_io_tasks(&read_fd_set,
read_io_tasks,&read_fd_count);
select(read_fd_count > write_fd_count ? read_fd_count : write_fd_count,
&read_fd_set,&write_fd_set,&except_fd_set,NULL);
callback = perform_io_tasks(&read_fd_set,read_io_tasks,&read_fd_count);
if(callback != F) if(callback != F)
return callback; return callback;
return perform_io_tasks(&write_fd_set,write_io_tasks,&write_fd_count); return perform_io_tasks(&write_fd_set,
write_io_tasks,&write_fd_count);
} }
void primitive_next_io_task(void) void primitive_next_io_task(void)
@ -262,6 +278,7 @@ void primitive_close(void)
/* This does not flush. */ /* This does not flush. */
PORT* port = untag_port(dpop()); PORT* port = untag_port(dpop());
close(port->fd); close(port->fd);
port->closed = true;
} }
void collect_io_tasks(void) void collect_io_tasks(void)

View File

@ -39,7 +39,6 @@ IO_TASK* add_io_task(
IO_TASK* io_tasks, IO_TASK* io_tasks,
int* fd_count); int* fd_count);
void remove_io_task( void remove_io_task(
IO_TASK_TYPE type,
PORT* port, PORT* port,
IO_TASK* io_tasks, IO_TASK* io_tasks,
int* fd_count); int* fd_count);
@ -52,7 +51,8 @@ CELL pop_io_task_callback(
PORT* port, PORT* port,
IO_TASK* io_tasks, IO_TASK* io_tasks,
int* fd_count); int* fd_count);
bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks); bool set_up_fd_set(fd_set* fdset, int fd_count, IO_TASK* io_tasks,
bool* closed);
CELL perform_io_task(IO_TASK* io_task, IO_TASK* io_tasks, int* fd_count); CELL perform_io_task(IO_TASK* io_task, IO_TASK* io_tasks, int* fd_count);
CELL perform_io_tasks(fd_set* fdset, IO_TASK* io_tasks, int* fd_count); CELL perform_io_tasks(fd_set* fdset, IO_TASK* io_tasks, int* fd_count);
CELL next_io_task(void); CELL next_io_task(void);

View File

@ -8,6 +8,8 @@ PORT* untag_port(CELL tagged)
/* after image load & save, ports are no longer valid */ /* after image load & save, ports are no longer valid */
if(p->fd == -1) if(p->fd == -1)
general_error(ERROR_EXPIRED,tagged); general_error(ERROR_EXPIRED,tagged);
/* if(p->closed)
general_error(ERROR_CLOSED,tagged); */
return p; return p;
} }
@ -15,6 +17,7 @@ PORT* port(PORT_MODE type, CELL fd)
{ {
PORT* port = allot_object(PORT_TYPE,sizeof(PORT)); PORT* port = allot_object(PORT_TYPE,sizeof(PORT));
port->type = type; port->type = type;
port->closed = false;
port->fd = fd; port->fd = fd;
port->buffer = NULL; port->buffer = NULL;
port->line = F; port->line = F;
@ -91,6 +94,8 @@ void pending_io_error(PORT* port)
port->io_error = F; port->io_error = F;
general_error(ERROR_IO,io_error); general_error(ERROR_IO,io_error);
} }
else if(port->closed)
general_error(ERROR_CLOSED,tag_object(port));
} }
void primitive_pending_io_error(void) void primitive_pending_io_error(void)

View File

@ -1,11 +1,16 @@
#define BUF_SIZE (8 * 1024) #define BUF_SIZE (8 * 1024)
typedef enum { PORT_READ, PORT_RECV, PORT_WRITE, PORT_SPECIAL } PORT_MODE; typedef enum {
PORT_READ,
PORT_RECV,
PORT_WRITE,
PORT_SPECIAL
} PORT_MODE;
typedef struct { typedef struct {
CELL header; CELL header;
/* one of PORT_READ, PORT_RECV, PORT_WRITE or PORT_SPECIAL */
PORT_MODE type; PORT_MODE type;
bool closed;
FIXNUM fd; FIXNUM fd;
STRING* buffer; STRING* buffer;

View File

@ -16,7 +16,7 @@ void run(void)
/* Error handling. */ /* Error handling. */
sigsetjmp(toplevel, 1); sigsetjmp(toplevel, 1);
for(;;) for(;;)
{ {
if(callframe == F) if(callframe == F)

View File

@ -25,13 +25,23 @@ CELL callframe;
CELL ds_bot; CELL ds_bot;
/* raw pointer to datastack top */ /* raw pointer to datastack top */
/* #define X86_STACK */
#ifdef X86_STACK
register CELL ds asm("%esi");
#else
CELL ds; CELL ds;
#endif
/* raw pointer to callstack bottom */ /* raw pointer to callstack bottom */
CELL cs_bot; CELL cs_bot;
/* raw pointer to callstack top */ /* raw pointer to callstack top */
#ifdef X86_STACK
register CELL cs asm("edi");
#else
CELL cs; CELL cs;
#endif
/* raw pointer to currently executing word */ /* raw pointer to currently executing word */
WORD* executing; WORD* executing;

View File

@ -143,6 +143,7 @@ void primitive_accept_fd(void)
PORT* p; PORT* p;
maybe_garbage_collection(); maybe_garbage_collection();
p = untag_port(dpop()); p = untag_port(dpop());
pending_io_error(p);
dpush(p->client_host); dpush(p->client_host);
dpush(p->client_port); dpush(p->client_port);
dpush(tag_object(port(PORT_RECV,p->client_socket))); dpush(tag_object(port(PORT_RECV,p->client_socket)));

View File

@ -25,12 +25,12 @@
CELL T; CELL T;
#define ARRAY_TYPE 8 #define ARRAY_TYPE 8
#define VECTOR_TYPE 9 #define BIGNUM_TYPE 9
#define STRING_TYPE 10 #define FLOAT_TYPE 10
#define SBUF_TYPE 11 #define VECTOR_TYPE 11
#define PORT_TYPE 12 #define STRING_TYPE 12
#define BIGNUM_TYPE 13 #define SBUF_TYPE 13
#define FLOAT_TYPE 14 #define PORT_TYPE 14
#define DLL_TYPE 15 #define DLL_TYPE 15
#define ALIEN_TYPE 16 #define ALIEN_TYPE 16