static int read_message(struct xs_handle *h, int nonblocking);
-static void setnonblock(int fd, int nonblock) {
- int esave = errno;
+static bool setnonblock(int fd, int nonblock) {
int flags = fcntl(fd, F_GETFL);
if (flags == -1)
- goto out;
+ return false;
if (nonblock)
flags |= O_NONBLOCK;
else
flags &= ~O_NONBLOCK;
- fcntl(fd, F_SETFL, flags);
-out:
- errno = esave;
+ if (fcntl(fd, F_SETFL, flags) == -1)
+ return false;
+
+ return true;
}
int xs_fileno(struct xs_handle *h)
if (!len)
return true;
- if (nonblocking)
- setnonblock(fd, 1);
+ if (nonblocking && !setnonblock(fd, 1))
+ return false;
while (len) {
int done;
len -= done;
if (nonblocking) {
- setnonblock(fd, 0);
nonblocking = 0;
+ if (!setnonblock(fd, 0))
+ goto out_false;
}
}