问题
I'm connecting a socket asynchronously (O_NONBLOCK + connect). POSIX standard specifies that after socket has been connected is should signal the event by making the file descriptor for the socket ready for writing. It doesn't seem to say anything about failures during async connect.
When testing it on Linux, it seems that sometimes I'm getting POLLOUT and sometimes POLLERR in this situation. Is there any pattern in the behaviour? Can I make it report the errors in a single way? Does POSIX say something I have overlooked?
回答1:
D. J. Bernstein has some stuff that looks like it might be relevant: http://cr.yp.to/docs/connect.html. In particular he suggests several different ways to get errors out.
The UNIX Socket FAQ has a section on Connect with timeout, that includes getting the error from a failed connection using getsockopt
来源:https://stackoverflow.com/questions/574533/how-is-an-error-reported-from-async-socket-connect