made to work
authorceriel <none@none>
Mon, 15 Feb 1988 18:08:46 +0000 (18:08 +0000)
committerceriel <none@none>
Mon, 15 Feb 1988 18:08:46 +0000 (18:08 +0000)
lang/occam/lib/channel.c
lang/occam/lib/par_misc.e

index e66aabb..161c81e 100644 (file)
@@ -116,6 +116,13 @@ static int timeout();
 
 int chan_any(c) register chan *c;
 {
+#ifdef __BSD4_2
+#include <fcntl.h>
+#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;
index d96bc67..5ddc02d 100644 (file)
@@ -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
 
  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