From 104811942f5fd30bd3ad46d91f0ea57fcccf2572 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sat, 4 May 2019 13:18:27 +0800 Subject: [PATCH] fixing read-line on network ports --- eval.c | 4 ++++ include/chibi/eval.h | 1 + lib/chibi/io/io.scm | 8 +++----- opcodes.c | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/eval.c b/eval.c index 59aad5c3..9e282900 100644 --- a/eval.c +++ b/eval.c @@ -1309,6 +1309,10 @@ sexp sexp_get_port_fileno (sexp ctx, sexp self, sexp_sint_t n, sexp port) { return sexp_make_fixnum(fd); return SEXP_FALSE; } +sexp sexp_stream_portp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port) { + sexp_assert_type(ctx, sexp_portp, SEXP_IPORT, port); + return sexp_make_boolean(sexp_stream_portp(port)); +} #endif #if SEXP_USE_STATIC_LIBS diff --git a/include/chibi/eval.h b/include/chibi/eval.h index 99e673ae..de308ebb 100644 --- a/include/chibi/eval.h +++ b/include/chibi/eval.h @@ -239,6 +239,7 @@ SEXP_API sexp sexp_9p_respond (sexp ctx, sexp self, sexp_sint_t n, sexp req, sex SEXP_API sexp sexp_9p_responderror (sexp ctx, sexp self, sexp_sint_t n, sexp req); #else SEXP_API sexp sexp_get_port_fileno (sexp ctx, sexp self, sexp_sint_t n, sexp port); +SEXP_API sexp sexp_stream_portp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port); #endif #if SEXP_USE_SIMPLIFY diff --git a/lib/chibi/io/io.scm b/lib/chibi/io/io.scm index ba5f98f4..49112657 100644 --- a/lib/chibi/io/io.scm +++ b/lib/chibi/io/io.scm @@ -77,7 +77,8 @@ (define (%read-line n in) (cond - ((port-fileno in) + ((stream-port? in) ;;(port-fileno in) + (port-line-set! in (+ 1 (port-line in))) (%%read-line n in)) (else (let ((out (open-output-string))) @@ -105,13 +106,10 @@ (let ((in (if (pair? o) (car o) (current-input-port))) (n (if (and (pair? o) (pair? (cdr o))) (car (cdr o)) 8192))) (let ((res (%read-line n in))) - (cond-expand - (string-streams - (port-line-set! in (+ 1 (port-line in))))) (if (not res) eof (let ((len (string-length res))) - (cond + (cond ;; strip crlf ((and (> len 0) (eqv? #\newline (string-ref res (- len 1)))) (if (and (> len 1) (eqv? #\return (string-ref res (- len 2)))) (substring res 0 (- len 2)) diff --git a/opcodes.c b/opcodes.c index 9add203e..f4554b23 100644 --- a/opcodes.c +++ b/opcodes.c @@ -258,6 +258,7 @@ _OP(SEXP_OPC_SETTER, SEXP_OP_SLOTN_SET, 4, 0, SEXP_VOID, _I(SEXP_OBJECT), _I(SEX #include "opt/plan9-opcodes.c" #else _FN1(_I(SEXP_OBJECT), _I(SEXP_IPORT), "port-fileno", 0, sexp_get_port_fileno), +_FN1(_I(SEXP_BOOLEAN), _I(SEXP_IPORT), "stream-port?", 0, sexp_stream_portp_op), #endif _FN0(_I(SEXP_ENV), "current-environment", 0, sexp_current_environment), #if SEXP_USE_MODULES