对于同步socket,二者一样,使用errno更方便一些。
对于异步socket,使用SO_ERROR,此值在真正的数据到来之前已经被设置,所以比errno更灵敏。
以下是Unix网络编程的原话:
If SO_ERROR is nonzero when the process calls read and there is no data to return, read returns–1 with errno set to the value of so_error (p. 516 of TCPv2). The value of so_error is then reset to 0. If there is data queued for the socket, that data is returned by read instead of the error condition. If so_error is nonzero when the process calls write, –1 is returned with errno set to the value of so_error (p. 495 of TCPv2) and so_error is reset to 0.