non blocking socket select returns 1 after connect

前端 未结 2 447
遇见更好的自我
遇见更好的自我 2020-12-21 10:29

First of all I would like to say that this is another problem than this one: Similar but not the same

My code looks like this:

struct addrinfo hints,         


        
2条回答
  •  一个人的身影
    2020-12-21 10:29

    This is correct behavior, because a pending error causes a socket to become both readable and writable. As with any other system call, you need to check for error conditions explicitly. You could include the socket in the exception fdset (the fourth argument to select()), and pick up a notification directly, or you could check later for an error in a number of ways.

    Be careful of writing to the socket, as a SIGPIPE could happen. In general, you should set a SIGPIPE handler and handle the error synchronously with EPIPE.

提交回复
热议问题