1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-29 13:01:30 +00:00

Update fcntl F_SETFL usage. (#144)

This changes from `FASYNC` to `O_ASYNC`, `FNDELAY` to `O_NONBLOCK`,
and `O_NDELAY` to `O_NONBLOCK`. These are the modern names.

`O_NONBLOCK` is part of the POSIX standard. However, `O_ASYNC` is
specific to Linux and BSD. It is not available on Solaris, where
we still need to use `FASYNC`. Also, the behavior of having I/O
trigger a `SIGIO` signal is not in POSIX, since the `SIGIO` signal
is not in POSIX. Instead, it is only the behavior of having `SIGURG`
being signalled for out of band data that is specified.

We also takes this opportunity to collapse some multi-line calls
to get the flags, store it into a temp, and then set them, to
just doing it in one line, skipping the stored temporary value.

We also change one instance of `65535 - FNDELAY` to `~O_NONBLOCK`.

Closes interlisp/medley#85.
This commit is contained in:
Bruce Mitchener
2020-12-31 08:28:34 +07:00
committed by GitHub
parent 3b1bdd225f
commit 6adb79840d
16 changed files with 42 additions and 58 deletions

View File

@@ -28,6 +28,11 @@
#include <unistd.h>
#endif /* DOS */
#ifdef OS5
/* Solaris doesn't define O_ASYNC, yet still defines FASYNC. */
#define O_ASYNC FASYNC
#endif
#include "lispemul.h"
#include "lispmap.h"
#include "lsptypes.h"
@@ -106,7 +111,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
addr_class = LispNumToCInt(nameConn);
protocol = LispNumToCInt(proto);
result = socket(addr_class, protocol, 0);
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
fcntl(result, F_SETOWN, getpid());
return (GetSmallp(result));
@@ -130,7 +135,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
perror("TCP connect");
return (NIL);
}
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY);
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK);
fcntl(result, F_SETOWN, getpid());
return (GetSmallp(result));
@@ -203,7 +208,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
int oldmask = sigblock(sigmask(SIGIO));
#endif /* SYSVSIGNALS */
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
fcntl(result, F_SETOWN, getpid());
if (listen(result, 5) == -1) {
@@ -236,7 +241,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
if (errno != EWOULDBLOCK) perror("TCP Accept");
return (NIL);
}
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY);
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK);
fcntl(result, F_SETOWN, getpid());
return (GetSmallp(result));
@@ -274,7 +279,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
close(result);
return (NIL);
}
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
fcntl(result, F_SETOWN, getpid());
FD_SET(result, &LispIOFds); /* so we get interrupts */