//TODO: timeout retry int TcpSocket::Connect(InetAddress& addr) { if(-1 == ::connect(sockfd_, (SA *)&addr.GetAddr(), sizeof(addr.GetAddr()))) { FILE_LOG(logERROR)<<" connect error"; return -1; } return 0; }
int TcpSocket::Bind(InetAddress& addr) { bool ret = addr.IsValid(); if(false == ret) { FILE_LOG(logERROR)<<__FILE__<<" "<<__LINE__<<" address is invalid"; return -1; } if(-1 == ::bind(sockfd_, (SA*)(&addr.GetAddr()), sizeof(addr.GetAddr()))) { FILE_LOG(logERROR)<<__FILE__<<" "<<__LINE__<<" bind address error"; return -1; } return 0; }
int TcpSocket::Accept(InetAddress& addr) { int res = -1; socklen_t addrlen = sizeof(addr); res = ::accept(sockfd_, (SA *)&addr.GetAddr(), &addrlen); if(res == -1) { FILE_LOG(logERROR)<<__FILE__<<" "<<__LINE__<<" accept error"; return res; } return res; }
void Socket::Bind(InetAddress const &addr) { if (bind(GetHandle(), addr.GetAddr(), addr.GetSize()) == -1) throw SocketException("Failed to bind socket", errno); }