I have added 'connected' method to Feersum::Connection::Handle #11

wants to merge 3 commits into


None yet
2 participants

luben commented Jul 13, 2011

It is standard feature for socket handles. I find it useful in order to clean up connections closed from clients. It is meaningful only on write handles but I do not know how to make work only on writers.


stash commented Jul 13, 2011


Thanks for sending me a pull request! :)

Even though getpeername() can result in ENOTCONN, I'm pretty sure that the only reliable way to test if a socket is "connected" is to try write to it and detect EPIPE/ENOTCONN/etc. That being said, if you know that getpeername() works cross-platform and can point me to some documentation, I'd stand happily corrected.

If you could also add unit tests and documentation to Feersum::Connection::Handle, I'd appreciate it.


luben commented Jul 13, 2011

I have looked in IO::Socket and it uses getpeername. This does not detect sockets in CLOSE_WAIT state but detects sockets that look like this in lsof output:

perl 5455 nobody 2183u sock 0,5 0t0 122379659 can't identify protocol

I suspect that after some time (tcp timeout maybe) sockets in CLOSE_WAIT state are closed and not associated with TCP any more.

I have tried another approach: use recv with MSG_PEEK in order to see if the socket is in CLOSE_WAIT state. It works but I am not sure how cross-platform it is. Also the current approach with getpeername is consistent with IO::Socket so it is least surprising option.

I will write docs for the feature. Also I will write test for the connected state, it will be difficult to test disconnected state.

I will ping you with another pull request for docs and tests.

Best regards

luben commented Jul 13, 2011

I have added the test and documentation.

@luben luben closed this Jul 13, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment