From 5d861a3399d7757c63dfda58c9daa1c9f442f391 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 15 Feb 1988 18:08:46 +0000 Subject: [PATCH] made to work --- lang/occam/lib/channel.c | 30 +++++++++++++++++++++++++++++- lang/occam/lib/par_misc.e | 4 ++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lang/occam/lib/channel.c b/lang/occam/lib/channel.c index e66aabbe6..161c81e42 100644 --- a/lang/occam/lib/channel.c +++ b/lang/occam/lib/channel.c @@ -116,6 +116,13 @@ static int timeout(); int chan_any(c) register chan *c; { +#ifdef __BSD4_2 +#include +#ifndef O_NDELAY +#define O_NDELAY FNDELAY +#endif + int flags; +#endif switch (c->type) { case C_T_FILE: if ((c->f.flgs&C_F_READAHEAD)!=0) @@ -132,6 +139,24 @@ int chan_any(c) register chan *c; deadlock=0; /* No deadlock while waiting for key */ + /* Unfortunately, the mechanism that was used + here does not work on all Unix systems. + On BSD 4.2 and newer, the "read" is + automatically restarted. Therefore, on + these systems, we try it with non-blocking + reads + */ +#ifdef __BSD4_2 + flags = fcntl(fileno(fp), F_GETFL, 0); + fcntl(fileno(fp), F_SETFL, flags | O_NDELAY); + errno = 0; + ch = getc(fp); + fcntl(fileno(fp), F_SETFL, flags); + if (errno == EWOULDBLOCK) { + clearerr(fp); + return 0; + } +#else signal(SIGALRM, timeout); alarm(1); @@ -141,8 +166,11 @@ int chan_any(c) register chan *c; signal(SIGALRM, SIG_IGN); alarm(0); - if (errno==EINTR) + if (errno==EINTR) { + clearerr(fp); return 0; + } +#endif else { if (!feof(fp)) { c->f.flgs|=C_F_READAHEAD; diff --git a/lang/occam/lib/par_misc.e b/lang/occam/lib/par_misc.e index d96bc67cb..5ddc02d2e 100644 --- a/lang/occam/lib/par_misc.e +++ b/lang/occam/lib/par_misc.e @@ -12,6 +12,7 @@ exp $top_save pro $top_save, 0 + mes 11 loe 0 lae 4 ; load line number and file name loi EM_PSIZE @@ -37,11 +38,14 @@ exp $top_load pro $top_load, 0 + mes 11 lal 0 loi EM_PSIZE dup EM_PSIZE loi EM_PSIZE sti EM_PSIZE ; copy pointer from argument 0 to new frame + lal 0 + loi EM_PSIZE loi EM_PSIZE ; load indirect to str 1 ; restore SP dup EM_PSIZE ; givesargument 0 again -- 2.34.1