chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0c3c428
)
util: minor simplification for loop_write() and loop_read()
author
Lennart Poettering
<lennart@poettering.net>
Fri, 12 Dec 2014 02:12:58 +0000
(
03:12
+0100)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 12 Dec 2014 12:35:32 +0000
(13:35 +0100)
src/shared/util.c
patch
|
blob
|
history
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 273552f62222ea579244ae1244e08b1a62d993f3..254b5637ae8c161acbcc581b929c8207db8c95a2 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-2268,21
+2268,25
@@
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
ssize_t k;
k = read(fd, p, nbytes);
ssize_t k;
k = read(fd, p, nbytes);
- if (k < 0 && errno == EINTR)
- continue;
+ if (k < 0) {
+ if (errno == EINTR)
+ continue;
-
if (k < 0 &&
errno == EAGAIN && do_poll) {
+
if (
errno == EAGAIN && do_poll) {
- /* We knowingly ignore any return value here,
- * and expect that any error/EOF is reported
- * via read() */
+
/* We knowingly ignore any return value here,
+
* and expect that any error/EOF is reported
+
* via read() */
- fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
- continue;
+ fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
+ continue;
+ }
+
+ return n > 0 ? n : -errno;
}
}
- if (k
<
= 0)
- return n
> 0 ? n : (k < 0 ? -errno : 0)
;
+ if (k
=
= 0)
+ return n;
p += k;
nbytes -= k;
p += k;
nbytes -= k;
@@
-2294,7
+2298,6
@@
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
const uint8_t *p = buf;
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
const uint8_t *p = buf;
- ssize_t n = 0;
assert(fd >= 0);
assert(buf);
assert(fd >= 0);
assert(buf);
@@
-2305,26
+2308,27
@@
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
ssize_t k;
k = write(fd, p, nbytes);
ssize_t k;
k = write(fd, p, nbytes);
- if (k < 0 && errno == EINTR)
- continue;
+ if (k < 0) {
+ if (errno == EINTR)
+ continue;
- if (k < 0 && errno == EAGAIN && do_poll) {
+ if (errno == EAGAIN && do_poll) {
+ /* We knowingly ignore any return value here,
+ * and expect that any error/EOF is reported
+ * via write() */
- /* We knowingly ignore any return value here,
- * and expect that any error/EOF is reported
- * via write() */
+ fd_wait_for_event(fd, POLLOUT, USEC_INFINITY);
+ continue;
+ }
- fd_wait_for_event(fd, POLLOUT, USEC_INFINITY);
- continue;
+ return -errno;
}
}
- if (k <= 0)
- /* We were not done yet, and a write error occured. */
- return errno ? -errno : -EIO;
+ if (k == 0) /* Can't really happen */
+ return -EIO;
p += k;
nbytes -= k;
p += k;
nbytes -= k;
- n += k;
}
return 0;
}
return 0;