Be nice with the CPU in fd_{read,write}_all()

This commit is contained in:
angt
2015-11-01 19:16:51 +01:00
parent b77fd86f2a
commit 5951a560af

View File

@@ -263,7 +263,14 @@ static ssize_t fd_read_all (int fd, void *data, size_t size)
{
size_t done = 0;
struct pollfd pollfd = {
.fd = fd,
.events = POLLIN,
};
while (done<size) {
poll(&pollfd, 1, -1);
ssize_t ret = fd_read(fd, data+done, size-done);
if (!ret)
@@ -280,7 +287,14 @@ static ssize_t fd_write_all (int fd, const void *data, size_t size)
{
size_t done = 0;
struct pollfd pollfd = {
.fd = fd,
.events = POLLOUT,
};
while (done<size) {
poll(&pollfd, 1, -1);
ssize_t ret = fd_write(fd, data+done, size-done);
if (!ret)