/** @fn int32_t CTCPClientAsync::ConnectAsync(const char* szIP, HPR_INT32 nPort) * @brief * @param[in] szIP * @param[in] nPort * @return 返回值为0 */ int32_t CTCPClientAsync::ConnectAsync( const char* szIP, int nPort ) { SetRemoteIP(szIP); SetRemotePort(nPort); //windows:这种做法对select没有用 //linux:这个做法也没有效果 //S_SetSendTimeOut(GetSocket(), 10); SOCKET_IO_INFO("connect remote ip: %s, port: %d.", szIP, nPort); if (S_Connect(GetSocket(), szIP, nPort) != 0) { #if (defined(_WIN32) || defined(_WIN64)) int32_t nError = ::GetLastError(); if (nError != WSAEWOULDBLOCK) #else int32_t nError = errno; if (nError != EINPROGRESS) #endif { //连接出错 SOCKET_IO_ERROR("connect error, errno: %d.", nError); DoException(GetSocketID(), SOCKET_IO_TCP_CONNECT_FAILED); } else { //连接建立已启动,但是还未成功 } //对于tcp client来说,在此处在加入io中 m_pio->Add_Handler(this); //对于windows/linux 的select来说,connect需要激活可写事件 //对于epoll来说,激活的是EPOLLERR? m_pio->Add_WriteEvent(this); } else { //对于tcp client来说,在此处在加入io中 m_pio->Add_Handler(this); //对于windows/linux 的select来说,connect需要激活可写事件 //对于epoll来说,激活的是EPOLLERR? m_pio->Add_WriteEvent(this); //连接成功,一般连接的是本地端口可能会立即成功 OnConnect(TRUE); } return 0; }
// // Copy constructor - takes a previously filled TSockAddr and // parses it for result fields. Useful for client code only. // EXPORT_C TIrdaSockAddr::TIrdaSockAddr(const TSockAddr &aAddr) /** Copy constructor. Assumes that the source address is an IrDA socket address. @param aAddr A socket address assumed to be valid IrDA socket address. */ { SetFamily(KIrdaAddrFamily); SetPort(aAddr.Port()); SetRemoteDevAddr(TIrdaSockAddr::Cast(aAddr).GetRemoteDevAddr()); SetHostDevAddr(TIrdaSockAddr::Cast(aAddr).GetHostDevAddr()); SetSniffStatus(TIrdaSockAddr::Cast(aAddr).GetSniffStatus()); SetSolicitedStatus(TIrdaSockAddr::Cast(aAddr).GetSolicitedStatus()); SetIrlapVersion(TIrdaSockAddr::Cast(aAddr).GetIrlapVersion()); SetCharacterSet(TIrdaSockAddr::Cast(aAddr).GetCharacterSet()); SetFirstServiceHintByte(TIrdaSockAddr::Cast(aAddr).GetFirstServiceHintByte()); SetSecondServiceHintByte(TIrdaSockAddr::Cast(aAddr).GetSecondServiceHintByte()); SetServiceHintByteCount(TIrdaSockAddr::Cast(aAddr).GetServiceHintByteCount()); SetHomePort(TIrdaSockAddr::Cast(aAddr).GetHomePort()); SetRemotePort(TIrdaSockAddr::Cast(aAddr).GetRemotePort()); SetUserLen(sizeof(SIrdaAddr)); }