1
0
Fork 0
mirror of https://repo.or.cz/socat.git synced 2025-06-17 22:46:50 +00:00

Correct undesired logging of complete write()

This commit is contained in:
Gerhard Rieger 2025-01-16 11:59:01 +01:00
parent 29f9e4db92
commit 2dd1452f25
2 changed files with 13 additions and 5 deletions

View file

@ -18,6 +18,8 @@ Corrections:
addresses the explicit socksport (2nd address parameter) was ignored. addresses the explicit socksport (2nd address parameter) was ignored.
Thanks to Jakub Fišer for reporting this bug. Thanks to Jakub Fišer for reporting this bug.
Do not log simple successful write with NOTICE level.
Building: Building:
Disabling certain features during configure could break build process. Disabling certain features during configure could break build process.

View file

@ -27,6 +27,11 @@ const int one = 1;
Returns <0 on unhandled error, errno valid Returns <0 on unhandled error, errno valid
Will only return <0 or bytes Will only return <0 or bytes
*/ */
/* Assuming your pipe size is 65536 - find out with:
filan -i 1 |grep F_GETPIPE_SZ |sed 's|.*\(F_GETPIPE_SZ=[1-9][0-9]*\).*|\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) {
size_t writt = 0; size_t writt = 0;
ssize_t chk; ssize_t chk;
@ -40,16 +45,17 @@ 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); continue; Sleep(1);
continue;
default: return -1; default: return -1;
} }
} else if (writt+chk < bytes) { } else if (writt+chk < bytes) {
Warn4("write(%d, %p, "F_Zu"): only wrote "F_Zu" bytes, trying to continue (rev.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);
writt += chk; writt += chk;
} else { } else if (writt == 0) {
writt = bytes; /* First attempt, write complete - no extra message */
break; return chk;
} }
} }
Notice3("write(%d, %p, "F_Zu") completed", fd, (const char *)buff, bytes); Notice3("write(%d, %p, "F_Zu") completed", fd, (const char *)buff, bytes);