void SocketIPv4::connect(const SocketAddressIPv4 &addr) { struct sockaddr_in targetSockAddr = addr.getSockAddr(); if (::connect(m_socket, (const sockaddr *)&targetSockAddr, addr.getAddrLen()) == SOCKET_ERROR) { throw SocketException(); } AutoLock l(&m_mutex); if (m_peerAddr) { delete m_peerAddr; } m_peerAddr = new SocketAddressIPv4(*(struct sockaddr_in *)&targetSockAddr); m_isBound = false; }
void SocketIPv4::bind(const SocketAddressIPv4 &addr) { struct sockaddr_in bindSockaddr = addr.getSockAddr(); if (::bind(m_socket, (const sockaddr *)&bindSockaddr, addr.getAddrLen()) == SOCKET_ERROR) { throw SocketException(); } AutoLock l(&m_mutex); if (m_localAddr) { delete m_localAddr; } m_localAddr = new SocketAddressIPv4(*(struct sockaddr_in*)&bindSockaddr); m_isBound = true; }