非阻塞式connect的Windows实现

     下面是connect的MSDN文档。由划线部分可知,当socket设置为非阻塞模式时,connect发起后会立即返回,然而,“三次握手”却依然进行,此时,connect返回SOCKET_ERROR,WSAGetLastError()返回WSAEWOULDBLOCK。如果需要判断connect是否成功,可以使用select()函数,当connect成功时,socket文件描述符写就绪;当connect失败时,socket文件描述符异常就绪。
Return Value
     If no error occurs, connect returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.
    On a blocking socket, the return value indicates success or failure of the connection attempt.
    With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. In this case, there are three possible scenarios:
     • Use the select function to determine the completion of the connection request by checking to see if
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值