// ------------------------------------------------------------- // bindSocket() -- bind the socket to an address, and configure // the send and receive buffers. // ------------------------------------------------------------- bool UdpUnicastHandler::bindSocket() { // --- // Our base class will bind the socket // --- bool ok = BaseClass::bindSocket(); if (ok) { struct sockaddr_in addr; // Working address structure bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = getLocalAddr(); if (getLocalPort() != 0) addr.sin_port = htons (getLocalPort()); else addr.sin_port = htons(getPort()); if (::bind(socketNum, reinterpret_cast<const struct sockaddr*>(&addr), sizeof(addr)) == SOCKET_ERROR) { std::perror("UdpUnicastHandler::bindSocket(): bind error"); return false; } if (!setSendBuffSize()) return false; if (!setRecvBuffSize()) return false; } return ok; }
// ------------------------------------------------------------- // bindSocket() -- bind the socket to an address, and configure // the send and receive buffers. // ------------------------------------------------------------- bool TcpClient::bindSocket() { // --- // Our base class will bind the socket // --- bool ok = BaseClass::bindSocket(); if (ok) { if (!setSendBuffSize()) return false; if (!setRecvBuffSize()) return false; } return ok; }