getpeername returning ENOTCONN for a connected socket

Steven Hartland killing at multiplay.co.uk
Sun Jan 23 19:44:53 UTC 2011


I've been trying to debug an issue where a call to getpeername
on a connected tcp socket returns ENOTCONN with no prior errors
being reported by previous socket calls.

At first I thought this was perl / perl module bug but I've now
reproduced the behaviour with a small native c client.

The flow is:-
0. socket
1. connect
2. getpeername
3. send
4. recv <- 14 bytes
5. sleep(1)
6. getpeername
7. send
8. recv <- 0 bytes
9. getpeername
10. send
11. recv <- 0 bytes
12. getpeername <- error ENOTCONN

Now given no previous errors from either connect, send or recv
if the connection has been terminated by the other end, which
tcpdump shows its has (RST), I would expect to get ECONNRESET
from getpeername and not ENOTCONN.

The only case I would expect ENOTCONN is if either no connect
call had been made or if it was unsuccessful.

Am I missing something here, is ENOTCONN and expected result
from a previously connected socket with no other indication
of error?

    Regards
    Steve

================================================
This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. 

In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337
or return the E.mail to postmaster at multiplay.co.uk.



More information about the freebsd-net mailing list