1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-02-07 16:51:21 +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

@@ -779,7 +779,6 @@ void init_ether() {
differences are in commented-out code below
(not ifdefed because they're untested...)
*/
int flags;
struct strioctl si;
unsigned long snaplen = 0;
@@ -822,8 +821,7 @@ void init_ether() {
return;
}
flags = fcntl(ether_fd, F_GETFL, 0);
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_NONBLOCK);
} else {
I_Give_Up:
@@ -858,7 +856,7 @@ void init_ether() {
#else /* OS4 */
if (getuid() != geteuid()) {
if ((ether_fd = open("/dev/nit", O_RDWR | FASYNC)) >= 0) {
if ((ether_fd = open("/dev/nit", O_RDWR | O_ASYNC)) >= 0) {
/* it's open, now query it and find out its name and address */
/* JRB - must document that LDE uses the first net board as
found by SIOCGIFCONF (see if(4)). Maybe we need an option
@@ -1020,7 +1018,7 @@ void init_ether() {
#endif /* USE_DLPI */
#endif /* PKTFILTER -- jds 23 sep 96 unmatched if fix */
#ifndef PKTFILTER
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | FASYNC | FNDELAY) < 0)
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK) < 0)
perror("Ether setup SETFLAGS fcntl");
if (fcntl(ether_fd, F_SETOWN, getpid()) < 0) perror("Ether setup SETOWN");
#else /* PKTFILTER */