mirror of
https://github.com/angt/secret
synced 2025-01-31 19:57:34 +01:00
Add IO timeout
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
parent
50ab07f92c
commit
f2d0b64d35
1 changed files with 6 additions and 4 deletions
10
secret.c
10
secret.c
|
@ -71,14 +71,15 @@ static int
|
|||
s_read(int fd, void *data, size_t size)
|
||||
{
|
||||
size_t done = 0;
|
||||
struct pollfd pfd = {.fd = fd, .events = POLLIN};
|
||||
|
||||
while (done < size) {
|
||||
ssize_t r = read(fd, (char *)data + done, size - done);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r == (ssize_t)-1) switch (errno) {
|
||||
case EAGAIN: continue;
|
||||
case EINTR: s_exit(1); // XXX
|
||||
case EAGAIN: if (!poll(&pfd, 1, 200)) return 1; /* FALLTHRU */
|
||||
case EINTR: continue;
|
||||
default: s_fatal("read: %s", strerror(errno));
|
||||
}
|
||||
done += r;
|
||||
|
@ -90,14 +91,15 @@ static int
|
|||
s_write(int fd, const void *data, size_t size)
|
||||
{
|
||||
size_t done = 0;
|
||||
struct pollfd pfd = {.fd = fd, .events = POLLOUT};
|
||||
|
||||
while (done < size) {
|
||||
ssize_t r = write(fd, (const char *)data + done, size - done);
|
||||
if (r == 0)
|
||||
break;
|
||||
if (r == (ssize_t)-1) switch (errno) {
|
||||
case EAGAIN: continue;
|
||||
case EINTR: s_exit(1); // XXX
|
||||
case EAGAIN: if (!poll(&pfd, 1, 200)) return 1; /* FALLTHRU */
|
||||
case EINTR: continue;
|
||||
default: s_fatal("write: %s", strerror(errno));
|
||||
}
|
||||
done += r;
|
||||
|
|
Loading…
Add table
Reference in a new issue