1
0
Fork 0
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:
Gerhard Rieger 2025-01-10 19:41:34 +01:00
parent 1878ae93fd
commit 1154e69d3e
12 changed files with 31 additions and 15 deletions

View file

@ -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;