From 474112c4ff9b647917a8cd72f648b9b2b18e397d Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Thu, 21 Jun 1990 20:02:06 +0000 Subject: [PATCH] Change `OS_channel_read' and `OS_channel_write' to be interruptable, so that any I/O can be interrupted by the user typing ^G. Fix minor thinko in `OS_channel_close' that caused the console I/O channels to be marked as closed even though they were still open. --- v7/src/microcode/osio.h | 3 +-- v7/src/microcode/uxio.c | 51 ++++++++++++-------------------------- v7/src/microcode/uxterm.c | 8 ++++-- v7/src/microcode/uxtty.c | 20 ++++++++------- v7/src/microcode/version.h | 4 +-- v8/src/microcode/version.h | 4 +-- 6 files changed, 38 insertions(+), 52 deletions(-) diff --git a/v7/src/microcode/osio.h b/v7/src/microcode/osio.h index 69fc60379..650b83ffc 100644 --- a/v7/src/microcode/osio.h +++ b/v7/src/microcode/osio.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/osio.h,v 1.1 1990/06/20 19:36:26 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/osio.h,v 1.2 1990/06/21 20:01:42 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -65,7 +65,6 @@ extern long EXFUN (OS_channel_read, (Tchannel channel, PTR buffer, size_t nbytes)); extern long EXFUN (OS_channel_write, (Tchannel channel, CONST PTR buffer, size_t nbytes)); -extern int EXFUN (OS_channel_read_char_interruptably, (Tchannel channel)); extern void EXFUN (OS_channel_write_string, (Tchannel channel, CONST char * string)); extern int EXFUN (OS_channel_nonblocking_p, (Tchannel channel)); diff --git a/v7/src/microcode/uxio.c b/v7/src/microcode/uxio.c index 75f107d9b..3bbe06153 100644 --- a/v7/src/microcode/uxio.c +++ b/v7/src/microcode/uxio.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxio.c,v 1.1 1990/06/20 19:37:14 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxio.c,v 1.2 1990/06/21 20:01:48 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -62,7 +62,7 @@ DEFUN_VOID (OS_channel_close_all) { Tchannel channel; for (channel = 0; (channel < OS_channel_table_size); channel += 1) - if ((CHANNEL_OPEN_P (channel)) && (! (CHANNEL_INTERNAL (channel)))) + if (CHANNEL_OPEN_P (channel)) OS_channel_close (channel); } @@ -90,8 +90,10 @@ void DEFUN (OS_channel_close, (channel), Tchannel channel) { if (! (CHANNEL_INTERNAL (channel))) - STD_VOID_SYSTEM_CALL ("close", (UX_close (CHANNEL_DESCRIPTOR (channel)))); - MARK_CHANNEL_CLOSED (channel); + { + STD_VOID_SYSTEM_CALL ("close", (UX_close (CHANNEL_DESCRIPTOR (channel)))); + MARK_CHANNEL_CLOSED (channel); + } } void @@ -139,16 +141,17 @@ DEFUN (OS_channel_read, (channel, buffer, nbytes), return (0); while (1) { - long scr = (UX_read ((CHANNEL_DESCRIPTOR (channel)), buffer, nbytes)); + long scr; + INTERRUPTABLE_EXTENT + (scr, (UX_read ((CHANNEL_DESCRIPTOR (channel)), buffer, nbytes))); if (scr < 0) { #ifdef ERRNO_NONBLOCK if (errno == ERRNO_NONBLOCK) return (-1); #endif - if (errno == EINTR) - continue; - error_system_call (errno, "read"); + UX_prim_check_errno ("read"); + continue; } if (scr > nbytes) error_external_return (); @@ -170,16 +173,17 @@ DEFUN (OS_channel_write, (channel, buffer, nbytes), return (0); while (1) { - long scr = (UX_write ((CHANNEL_DESCRIPTOR (channel)), buffer, nbytes)); + long scr; + INTERRUPTABLE_EXTENT + (scr, (UX_write ((CHANNEL_DESCRIPTOR (channel)), buffer, nbytes))); if (scr < 0) { #ifdef ERRNO_NONBLOCK if (errno == ERRNO_NONBLOCK) return (-1); #endif - if (errno == EINTR) - continue; - error_system_call (errno, "write"); + UX_prim_check_errno ("write"); + continue; } if (scr > nbytes) error_external_return (); @@ -203,29 +207,6 @@ DEFUN (OS_channel_write_dump_file, (channel, buffer, nbytes), return ((scr < 0) ? 0 : scr); } -int -DEFUN (OS_channel_read_char_interruptably, (channel), Tchannel channel) -{ - unsigned char c; - int nread; - while (1) - { - INTERRUPTABLE_EXTENT - (nread, (UX_read ((CHANNEL_DESCRIPTOR (channel)), ((PTR) (&c)), 1))); - if (nread >= 0) - break; -#ifdef ERRNO_NONBLOCK - if (errno == ERRNO_NONBLOCK) - { - nread = 0; - break; - } -#endif - UX_prim_check_errno ("read"); - } - return ((nread == 1) ? c : (-1)); -} - void DEFUN (OS_channel_write_string, (channel, string), Tchannel channel AND diff --git a/v7/src/microcode/uxterm.c b/v7/src/microcode/uxterm.c index ffe7637ae..4808a4e1a 100644 --- a/v7/src/microcode/uxterm.c +++ b/v7/src/microcode/uxterm.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxterm.c,v 1.1 1990/06/20 19:37:38 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxterm.c,v 1.2 1990/06/21 20:01:53 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -99,7 +99,11 @@ DEFUN (OS_terminal_read_char, (channel), Tchannel channel) return (c); } } - return (OS_channel_read_char_interruptably (channel)); + { + unsigned char c; + long nread = (OS_channel_read (channel, (&c), 1)); + return ((nread == 1) ? c : (-1)); + } } int diff --git a/v7/src/microcode/uxtty.c b/v7/src/microcode/uxtty.c index 98563b554..8e763507a 100644 --- a/v7/src/microcode/uxtty.c +++ b/v7/src/microcode/uxtty.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtty.c,v 1.1 1990/06/20 19:38:04 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtty.c,v 1.2 1990/06/21 20:01:58 cph Exp $ Copyright (c) 1990 Massachusetts Institute of Technology @@ -54,7 +54,6 @@ DEFUN_VOID (OS_tty_input_channel) static unsigned char DEFUN (tty_read_char, (immediate), int immediate) { - int c; if ((OS_channel_type (input_channel)) == channel_type_terminal) { transaction_begin (); @@ -63,20 +62,23 @@ DEFUN (tty_read_char, (immediate), int immediate) OS_terminal_nonbuffered (input_channel); else OS_terminal_buffered (input_channel); - c = (OS_terminal_read_char (input_channel)); - if (c == (-1)) - termination_eof (); - transaction_commit (); + { + int c = (OS_terminal_read_char (input_channel)); + if (c == (-1)) + termination_eof (); + transaction_commit (); + return ((unsigned char) c); + } } else { - c = (OS_channel_read_char_interruptably (input_channel)); - if (c == (-1)) + unsigned char c; + if ((OS_channel_read (input_channel, (&c), 1)) != 1) termination_eof (); if ((OS_channel_type (input_channel)) == channel_type_file) OS_tty_write_char (c); + return (c); } - return ((unsigned char) c); } unsigned char diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index be74b9f10..fdfffc05d 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.33 1990/06/20 20:00:58 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.34 1990/06/21 20:02:06 cph Exp $ Copyright (c) 1988, 1989, 1990 Massachusetts Institute of Technology @@ -46,7 +46,7 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 33 +#define SUBVERSION 34 #endif #ifndef UCODE_TABLES_FILENAME diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index a165963b5..1a35c5905 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.33 1990/06/20 20:00:58 cph Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.34 1990/06/21 20:02:06 cph Exp $ Copyright (c) 1988, 1989, 1990 Massachusetts Institute of Technology @@ -46,7 +46,7 @@ MIT in each case. */ #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 33 +#define SUBVERSION 34 #endif #ifndef UCODE_TABLES_FILENAME -- 2.25.1