Closed Lethja closed 8 months ago
Ok. Try to add a call to dbug_init()
and look for EINTR
.
I'm not sure what the cause is
Trying this patch:
--- a/src/getname.c
+++ b/src/getname.c
@@ -113,12 +113,14 @@ int W32_CALL getpeername (int s, struct sockaddr *name, socklen_t *namelen)
return (-1);
}
+#if 0
if (!(socket->so_state & SS_ISCONNECTED))
{
SOCK_DEBUGF ((", ENOTCONN"));
SOCK_ERRNO (ENOTCONN);
return (-1);
}
+#endif
VERIFY_RW (name, *namelen);
it works:
Server listening on 10.0.0.7:12345...
Accepted connection: 10.0.0.10:59905
Echoed data back to client: 10.0.0.10:59905
Echoed data back to client: 10.0.0.10:59905
Echoed data back to client: 10.0.0.10:59905
Connection closed by client: 10.0.0.10:59905
But I'm not sure it's a good idea or what other implications it has.
Maybe:
--- a/src/getname.c
+++ b/src/getname.c
@@ -113,7 +113,7 @@ int W32_CALL getpeername (int s, struct sockaddr *name, socklen_t *namelen)
return (-1);
}
- if (!(socket->so_state & SS_ISCONNECTED))
+ if (!socket->remote_addr)
{
SOCK_DEBUGF ((", ENOTCONN"));
SOCK_ERRNO (ENOTCONN);
Although current behavior is technically correct, according to Linux and BSD man pages.
@jwt27 Tried it. Works for the 1st client pressing ^C
. But a new nc ...
never connects!
And BTW, the code about had an issue with Dr. Watson on MSVC/clang-cl when exiting. This was needed:
#ifdef WATT32
#include <tcp.h>
+ #define close(s) closesocket(s)
#endif
Works for me on djgpp. But I have seen the issue before where accept()
sometimes ignores new connections. That seems to be a separate bug.
@jwt27 I'm committing your fix above. Thanks.
Fixed in https://github.com/gvanem/Watt-32/commit/d52978297f83a9526052d5a0180410f6d507396e. Closing as completed.
Watt32s
getpeername()
will return an error if called after a TCP session has been reset by the remote peer. The application will not be able to access information about the connection that just closed. This is contrary to Linux and Winsock wheregetpeername()
will continue to return successfully until an explicitclose()
/closesocket()
is called.Sample code to reproduce: