mirror of
https://repo.or.cz/socat.git
synced 2025-07-05 20:46:34 +00:00
writefull() respects total inactivity timeout
This commit is contained in:
parent
1878ae93fd
commit
1154e69d3e
12 changed files with 31 additions and 15 deletions
13
sysutils.c
13
sysutils.c
|
@ -32,10 +32,15 @@ const int one = 1;
|
|||
Then we can test partial write with something like:
|
||||
socat -d4 -lu -b 262144 -u /dev/zero,readbytes=262144 -,o-nonblock |{ sleep 3; wc -c; }
|
||||
*/
|
||||
ssize_t writefull(int fd, const void *buff, size_t bytes) {
|
||||
ssize_t writefull(
|
||||
int fd,
|
||||
const void *buff,
|
||||
size_t bytes,
|
||||
const struct timeval *tmo0) {
|
||||
size_t writt = 0;
|
||||
ssize_t chk;
|
||||
struct pollfd pfd;
|
||||
struct timeval tmo = { 0 };
|
||||
int rc;
|
||||
|
||||
while (1) {
|
||||
|
@ -51,7 +56,11 @@ ssize_t writefull(int fd, const void *buff, size_t bytes) {
|
|||
pfd.fd = fd;
|
||||
pfd.events = POLLOUT;
|
||||
pfd.revents = 0;
|
||||
rc = xiopoll(&pfd, 1, NULL);
|
||||
if (tmo0 != NULL) {
|
||||
tmo.tv_sec = tmo0->tv_sec;
|
||||
tmo.tv_usec = tmo0->tv_usec;
|
||||
}
|
||||
rc = xiopoll(&pfd, 1, (tmo.tv_sec!=0 || tmo.tv_usec!=0) ? &tmo : NULL);
|
||||
if (rc == 0) {
|
||||
Notice("inactivity timeout triggered");
|
||||
errno = ETIMEDOUT;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue