Overview
| Artifact ID: | fd48a74265eeecd5b7a0e08519d6b19cd3848af74b60b4dd8281cf81dccf044b |
|---|---|
| Ticket: | 7586dbc9f53aad9e461dc547c1e83de06bd1382b
fconfigure -sockname fails with "invalid argument" after a failed async connect |
| User & Date: | serhiy.storchaka on 2026-10-28 12:45:51 |
Changes
- icomment:
<tt>getsockname()</tt> on a socket whose non-blocking connect to a closed loopback port was refused: <table border="1" cellpadding="3"> <tr><th>System</th><th>getsockname()</th><th>getpeername()</th></tr> <tr><td>Linux 7.0</td><td>local address and port</td><td>ENOTCONN</td></tr> <tr><td>FreeBSD 15.1</td><td>local address and port</td><td>ENOTCONN</td></tr> <tr><td>Windows 11</td><td>wildcard address and a port</td><td>WSAENOTCONN</td></tr> <tr><td>OpenIndiana</td><td>wildcard address, port 0</td><td>ENOTCONN</td></tr> <tr><td>NetBSD 10.1</td><td>EINVAL</td><td>ENOTCONN</td></tr> <tr><td>OpenBSD 7.9</td><td>EINVAL</td><td>ENOTCONN</td></tr> <tr><td>DragonFly 6.4</td><td>ECONNRESET (IPv4), EINVAL (IPv6)</td><td>ENOTCONN</td></tr> </table> So after a failed async connect, <tt>-sockname</tt> returns a meaningless address on some systems and raises an error on others, and on the latter plain <tt>fconfigure $s</tt> fails too. <tt>-peername</tt> raises an error everywhere. Possible fixes: raise an error on all systems, as <tt>-peername</tt> already does and <tt>-sockname</tt> does on the BSDs, but skip it for plain <tt>fconfigure $s</tt>; or return "", as while the connect is pending, which no system does now. With the error, socket-14.16 and 14.17 would still need to accept either result. win/tclWinSock.c has the same structure.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"