mirror of
https://repo.or.cz/socat.git
synced 2025-06-17 22:46:50 +00:00
writefull() uses select()/poll() instead of sleep based polling
This commit is contained in:
parent
2dd1452f25
commit
1878ae93fd
2 changed files with 21 additions and 2 deletions
2
CHANGES
2
CHANGES
|
@ -20,6 +20,8 @@ Corrections:
|
||||||
|
|
||||||
Do not log simple successful write with NOTICE level.
|
Do not log simple successful write with NOTICE level.
|
||||||
|
|
||||||
|
On partial write to not poll with sleep() but use select()/poll().
|
||||||
|
|
||||||
Building:
|
Building:
|
||||||
Disabling certain features during configure could break build process.
|
Disabling certain features during configure could break build process.
|
||||||
|
|
||||||
|
|
21
sysutils.c
21
sysutils.c
|
@ -35,6 +35,9 @@ const int one = 1;
|
||||||
ssize_t writefull(int fd, const void *buff, size_t bytes) {
|
ssize_t writefull(int fd, const void *buff, size_t bytes) {
|
||||||
size_t writt = 0;
|
size_t writt = 0;
|
||||||
ssize_t chk;
|
ssize_t chk;
|
||||||
|
struct pollfd pfd;
|
||||||
|
int rc;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
chk = Write(fd, (const char *)buff + writt, bytes - writt);
|
chk = Write(fd, (const char *)buff + writt, bytes - writt);
|
||||||
if (chk < 0) {
|
if (chk < 0) {
|
||||||
|
@ -45,10 +48,22 @@ ssize_t writefull(int fd, const void *buff, size_t bytes) {
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
#endif
|
#endif
|
||||||
Warn4("write(%d, %p, "F_Zu"): %s", fd, (const char *)buff+writt, bytes-writt, strerror(errno));
|
Warn4("write(%d, %p, "F_Zu"): %s", fd, (const char *)buff+writt, bytes-writt, strerror(errno));
|
||||||
Sleep(1);
|
pfd.fd = fd;
|
||||||
|
pfd.events = POLLOUT;
|
||||||
|
pfd.revents = 0;
|
||||||
|
rc = xiopoll(&pfd, 1, NULL);
|
||||||
|
if (rc == 0) {
|
||||||
|
Notice("inactivity timeout triggered");
|
||||||
|
errno = ETIMEDOUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
default: return -1;
|
default:
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
} else if (chk == bytes) {
|
||||||
|
/* First attempt, complete write */
|
||||||
|
return chk;
|
||||||
} else if (writt+chk < bytes) {
|
} else if (writt+chk < bytes) {
|
||||||
Warn4("write(%d, %p, "F_Zu"): only wrote "F_Zu" bytes, trying to continue (meanwhile, other direction is blocked)",
|
Warn4("write(%d, %p, "F_Zu"): only wrote "F_Zu" bytes, trying to continue (meanwhile, other direction is blocked)",
|
||||||
fd, (const char *)buff+writt, bytes-writt, chk);
|
fd, (const char *)buff+writt, bytes-writt, chk);
|
||||||
|
@ -56,6 +71,8 @@ ssize_t writefull(int fd, const void *buff, size_t bytes) {
|
||||||
} else if (writt == 0) {
|
} else if (writt == 0) {
|
||||||
/* First attempt, write complete - no extra message */
|
/* First attempt, write complete - no extra message */
|
||||||
return chk;
|
return chk;
|
||||||
|
} else { /* write completed */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Notice3("write(%d, %p, "F_Zu") completed", fd, (const char *)buff, bytes);
|
Notice3("write(%d, %p, "F_Zu") completed", fd, (const char *)buff, bytes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue