IceObjC::StreamAcceptor::StreamAcceptor(const StreamEndpointIPtr& endpoint, const InstancePtr& instance, const string& host, int port) : _endpoint(endpoint), _instance(instance), _addr(getAddressForServer(host, port, instance->protocolSupport(), instance->preferIPv6(), true)) { #ifdef SOMAXCONN _backlog = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", SOMAXCONN); #else _backlog = instance->properties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511); #endif try { _fd = createSocket(false, _addr); setBlock(_fd, false); setTcpBufSize(_fd, _instance); setReuseAddress(_fd, true); } catch(...) { _fd = INVALID_SOCKET; throw; } }
IceSSL::AcceptorI::AcceptorI(const InstancePtr& instance, const string& adapterName, const string& host, int port) : _instance(instance), _adapterName(adapterName), _logger(instance->communicator()->getLogger()), _addr(IceInternal::getAddressForServer(host, port, instance->protocolSupport())) #ifdef ICE_USE_IOCP , _acceptFd(INVALID_SOCKET), _info(IceInternal::SocketOperationRead) #endif { #ifdef SOMAXCONN _backlog = instance->communicator()->getProperties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", SOMAXCONN); #else _backlog = instance->communicator()->getProperties()->getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511); #endif _fd = IceInternal::createSocket(false, _addr.ss_family); #ifdef ICE_USE_IOCP _acceptBuf.resize((sizeof(sockaddr_storage) + 16) * 2); #endif IceInternal::setBlock(_fd, false); IceInternal::setTcpBufSize(_fd, _instance->communicator()->getProperties(), _logger); #ifndef _WIN32 // // Enable SO_REUSEADDR on Unix platforms to allow re-using the // socket even if it's in the TIME_WAIT state. On Windows, // this doesn't appear to be necessary and enabling // SO_REUSEADDR would actually not be a good thing since it // allows a second process to bind to an address even it's // already bound by another process. // // TODO: using SO_EXCLUSIVEADDRUSE on Windows would probably // be better but it's only supported by recent Windows // versions (XP SP2, Windows Server 2003). // IceInternal::setReuseAddress(_fd, true); #endif if(_instance->networkTraceLevel() >= 2) { Trace out(_logger, _instance->networkTraceCategory()); out << "attempting to bind to ssl socket " << toString(); } const_cast<struct sockaddr_storage&>(_addr) = IceInternal::doBind(_fd, _addr); }