void CTCPSocket::connect(const CNetworkAddress& addr) { { CLock lock(&m_mutex); // fail on attempts to reconnect if (m_socket == NULL || m_connected) { sendConnectionFailedEvent("busy"); return; } try { if (ARCH->connectSocket(m_socket, addr.getAddress())) { sendEvent(getConnectedEvent()); onConnected(); } else { // connection is in progress m_writable = true; } } catch (XArchNetwork& e) { throw XSocketConnect(e.what()); } } setJob(newJob()); }
void CTCPSocket::bind(const CNetworkAddress& addr) { try { ARCH->bindSocket(m_socket, addr.getAddress()); } catch (XArchNetworkAddressInUse& e) { throw XSocketAddressInUse(e.what()); } catch (XArchNetwork& e) { throw XSocketBind(e.what()); } }
void CTCPListenSocket::bind(const CNetworkAddress& addr) { try { CLock lock(m_mutex); ARCH->setReuseAddrOnSocket(m_socket, true); ARCH->bindSocket(m_socket, addr.getAddress()); ARCH->listenOnSocket(m_socket); CSocketMultiplexer::getInstance()->addSocket(this, new TSocketMultiplexerMethodJob<CTCPListenSocket>( this, &CTCPListenSocket::serviceListening, m_socket, true, false)); } catch (XArchNetworkAddressInUse& e) { throw XSocketAddressInUse(e.what()); } catch (XArchNetwork& e) { throw XSocketBind(e.what()); } }