fd read and write: avoid redundant O_NONBLOCK flag setting
This commit is contained in:
parent
b2509614e2
commit
2679638e74
|
@ -6554,10 +6554,12 @@ static int try_get_fd_char(int fd, int *ready)
|
||||||
unsigned char buf[1];
|
unsigned char buf[1];
|
||||||
|
|
||||||
old_flags = fcntl(fd, F_GETFL, 0);
|
old_flags = fcntl(fd, F_GETFL, 0);
|
||||||
|
if (!(old_flags & MZ_NONBLOCKING))
|
||||||
fcntl(fd, F_SETFL, old_flags | MZ_NONBLOCKING);
|
fcntl(fd, F_SETFL, old_flags | MZ_NONBLOCKING);
|
||||||
do {
|
do {
|
||||||
c = read(fd, buf, 1);
|
c = read(fd, buf, 1);
|
||||||
} while ((c == -1) && errno == EINTR);
|
} while ((c == -1) && errno == EINTR);
|
||||||
|
if (!(old_flags & MZ_NONBLOCKING))
|
||||||
fcntl(fd, F_SETFL, old_flags);
|
fcntl(fd, F_SETFL, old_flags);
|
||||||
|
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
|
@ -6857,10 +6859,12 @@ static intptr_t fd_get_string_slow(Scheme_Input_Port *port,
|
||||||
int old_flags;
|
int old_flags;
|
||||||
|
|
||||||
old_flags = fcntl(fip->fd, F_GETFL, 0);
|
old_flags = fcntl(fip->fd, F_GETFL, 0);
|
||||||
|
if (!(old_flags & MZ_NONBLOCKING))
|
||||||
fcntl(fip->fd, F_SETFL, old_flags | MZ_NONBLOCKING);
|
fcntl(fip->fd, F_SETFL, old_flags | MZ_NONBLOCKING);
|
||||||
do {
|
do {
|
||||||
bc = read(fip->fd, target + target_offset, target_size);
|
bc = read(fip->fd, target + target_offset, target_size);
|
||||||
} while ((bc == -1) && errno == EINTR);
|
} while ((bc == -1) && errno == EINTR);
|
||||||
|
if (!(old_flags & MZ_NONBLOCKING))
|
||||||
fcntl(fip->fd, F_SETFL, old_flags);
|
fcntl(fip->fd, F_SETFL, old_flags);
|
||||||
|
|
||||||
if ((bc == -1) && (errno == EAGAIN)) {
|
if ((bc == -1) && (errno == EAGAIN)) {
|
||||||
|
@ -8125,6 +8129,7 @@ static intptr_t flush_fd(Scheme_Output_Port *op,
|
||||||
intptr_t amt;
|
intptr_t amt;
|
||||||
|
|
||||||
flags = fcntl(fop->fd, F_GETFL, 0);
|
flags = fcntl(fop->fd, F_GETFL, 0);
|
||||||
|
if (!(flags & MZ_NONBLOCKING))
|
||||||
fcntl(fop->fd, F_SETFL, flags | MZ_NONBLOCKING);
|
fcntl(fop->fd, F_SETFL, flags | MZ_NONBLOCKING);
|
||||||
|
|
||||||
amt = buflen - offset;
|
amt = buflen - offset;
|
||||||
|
@ -8141,6 +8146,7 @@ static intptr_t flush_fd(Scheme_Output_Port *op,
|
||||||
} while ((len == -1) && (errno == EAGAIN) && (amt > 0));
|
} while ((len == -1) && (errno == EAGAIN) && (amt > 0));
|
||||||
|
|
||||||
errsaved = errno;
|
errsaved = errno;
|
||||||
|
if (!(flags & MZ_NONBLOCKING))
|
||||||
fcntl(fop->fd, F_SETFL, flags);
|
fcntl(fop->fd, F_SETFL, flags);
|
||||||
|
|
||||||
full_write_buffer = (errsaved == EAGAIN);
|
full_write_buffer = (errsaved == EAGAIN);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user