public ProtocolInstance(Instance instance, short type, string protocol) { instance_ = instance; traceLevel_ = instance_.traceLevels().network; traceCategory_ = instance_.traceLevels().networkCat; logger_ = instance_.initializationData().logger; properties_ = instance_.initializationData().properties; type_ = type; protocol_ = protocol; }
public ProtocolInstance(Instance instance, short type, string protocol, bool secure) { instance_ = instance; traceLevel_ = instance_.traceLevels().network; traceCategory_ = instance_.traceLevels().networkCat; logger_ = instance_.initializationData().logger; properties_ = instance_.initializationData().properties; type_ = type; protocol_ = protocol; secure_ = secure; }
public ProtocolInstance(Ice.Communicator communicator, short type, string protocol, bool secure) { instance_ = Util.getInstance(communicator); traceLevel_ = instance_.traceLevels().network; traceCategory_ = instance_.traceLevels().networkCat; logger_ = instance_.initializationData().logger; properties_ = instance_.initializationData().properties; type_ = type; protocol_ = protocol; secure_ = secure; }
private void getEndpointsTrace(Reference @ref, EndpointI[] endpoints, bool cached) { if (endpoints != null && endpoints.Length > 0) { if (cached) { trace("found endpoints in locator table", @ref, endpoints); } else { trace("retrieved endpoints from locator, adding to locator table", @ref, endpoints); } } else { Instance instance = @ref.getInstance(); System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("no endpoints configured for "); if (@ref.getAdapterId().Length > 0) { s.Append("adapter\n"); s.Append("adapter = " + @ref.getAdapterId()); } else { s.Append("object\n"); s.Append("object = " + instance.identityToString(@ref.getIdentity())); } instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } }
// // Only for use by TcpEndpoint // internal TcpConnector(Instance instance, IPEndPoint addr, int timeout, string connectionId) { _instance = instance; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _addr = addr; _timeout = timeout; _connectionId = connectionId; _hashCode = _addr.GetHashCode(); _hashCode = 5 * _hashCode + _timeout; _hashCode = 5 * _hashCode + _connectionId.GetHashCode(); }
// // Only for use by TcpEndpoint // internal TcpConnector(Instance instance, EndPoint addr, NetworkProxy proxy, int timeout, string connectionId) { _instance = instance; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _addr = addr; _proxy = proxy; _timeout = timeout; _connectionId = connectionId; _hashCode = 5381; IceInternal.HashUtil.hashAdd(ref _hashCode, _addr); IceInternal.HashUtil.hashAdd(ref _hashCode, _timeout); IceInternal.HashUtil.hashAdd(ref _hashCode, _connectionId); }
internal TcpAcceptor(Instance instance, string host, int port) { instance_ = instance; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _backlog = instance.initializationData().properties.getPropertyAsIntWithDefault("Ice.TCP.Backlog", 511); try { _addr = Network.getAddressForServer(host, port, instance_.protocolSupport()); _fd = Network.createSocket(false, _addr.AddressFamily); Network.setBlock(_fd, false); #if !COMPACT Network.setTcpBufSize(_fd, instance_.initializationData().properties, _logger); #endif if(AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows) { // // 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). // Network.setReuseAddress(_fd, true); } if(_traceLevels.network >= 2) { string s = "attempting to bind to tcp socket " + Network.addrToString(_addr); _logger.trace(_traceLevels.networkCat, s); } _addr = Network.doBind(_fd, _addr); } catch(System.Exception) { _fd = null; throw; } }
// // Only for use by TcpConnector, TcpAcceptor // internal TcpTransceiver(Instance instance, Socket fd, EndPoint addr, NetworkProxy proxy, bool connected) { _fd = fd; _addr = addr; _proxy = proxy; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _state = connected ? StateConnected : StateNeedConnect; _desc = connected ? Network.fdToString(_fd, _proxy, _addr) : "<not connected>"; #if ICE_SOCKET_ASYNC_API _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted); #if SILVERLIGHT String policy = instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol"); if (policy.Equals("Http")) { _readEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; } else if (!String.IsNullOrEmpty(policy)) { _logger.warning("Ignoring invalid Ice.ClientAccessPolicyProtocol value `" + policy + "'"); } #endif #endif _maxSendPacketSize = Network.getSendBufferSize(fd); if (_maxSendPacketSize < 512) { _maxSendPacketSize = 0; } _maxReceivePacketSize = Network.getRecvBufferSize(fd); if (_maxReceivePacketSize < 512) { _maxReceivePacketSize = 0; } }
// // Only for use by TcpConnector, TcpAcceptor // internal TcpTransceiver(Instance instance, Socket fd, IPEndPoint addr, bool connected) { _fd = fd; _addr = addr; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _state = connected ? StateConnected : StateNeedConnect; _desc = connected ? Network.fdToString(_fd) : "<not connected>"; _maxSendPacketSize = Network.getSendBufferSize(fd); if(_maxSendPacketSize < 512) { _maxSendPacketSize = 0; } _maxReceivePacketSize = Network.getRecvBufferSize(fd); if(_maxReceivePacketSize < 512) { _maxReceivePacketSize = 0; } }
// // Only for use by UdpConnector. // internal UdpTransceiver(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl) { _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _addr = addr; _mcastInterface = mcastInterface; _mcastTtl = mcastTtl; _state = StateNeedConnect; _incoming = false; try { _fd = Network.createSocket(true, _addr.AddressFamily); setBufSize(instance); Network.setBlock(_fd, false); } catch(Ice.LocalException) { _fd = null; throw; } }
getObjectRequest(Reference @ref) { if (@ref.getInstance().traceLevels().location >= 1) { Instance instance = @ref.getInstance(); System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("searching for well-known object\nwell-known proxy = "); s.Append(@ref.ToString()); instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } lock (this) { Request request; if (_objectRequests.TryGetValue(@ref.getIdentity(), out request)) { return(request); } request = new ObjectRequest(this, @ref); _objectRequests.Add(@ref.getIdentity(), request); return(request); } }
getAdapterRequest(Reference @ref) { if (@ref.getInstance().traceLevels().location >= 1) { Instance instance = @ref.getInstance(); System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("searching for adapter by id\nadapter = "); s.Append(@ref.getAdapterId()); instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } lock (this) { Request request; if (_adapterRequests.TryGetValue(@ref.getAdapterId(), out request)) { return(request); } request = new AdapterRequest(this, @ref); _adapterRequests.Add(@ref.getAdapterId(), request); return(request); } }
public ThreadPool(Instance instance, string prefix, int timeout) { Ice.Properties properties = instance.initializationData().properties; _instance = instance; _dispatcher = instance.initializationData().dispatcher; _destroyed = false; _prefix = prefix; _threadIndex = 0; _inUse = 0; _serialize = properties.getPropertyAsInt(_prefix + ".Serialize") > 0; _serverIdleTime = timeout; string programName = properties.getProperty("Ice.ProgramName"); if (programName.Length > 0) { _threadPrefix = programName + "-" + _prefix; } else { _threadPrefix = _prefix; } // // We use just one thread as the default. This is the fastest // possible setting, still allows one level of nesting, and // doesn't require to make the servants thread safe. // int size = properties.getPropertyAsIntWithDefault(_prefix + ".Size", 1); if (size < 1) { string s = _prefix + ".Size < 1; Size adjusted to 1"; _instance.initializationData().logger.warning(s); size = 1; } int sizeMax = properties.getPropertyAsIntWithDefault(_prefix + ".SizeMax", size); if (sizeMax < size) { string s = _prefix + ".SizeMax < " + _prefix + ".Size; SizeMax adjusted to Size (" + size + ")"; _instance.initializationData().logger.warning(s); sizeMax = size; } int sizeWarn = properties.getPropertyAsInt(_prefix + ".SizeWarn"); if (sizeWarn != 0 && sizeWarn < size) { string s = _prefix + ".SizeWarn < " + _prefix + ".Size; adjusted SizeWarn to Size (" + size + ")"; _instance.initializationData().logger.warning(s); sizeWarn = size; } else if (sizeWarn > sizeMax) { string s = _prefix + ".SizeWarn > " + _prefix + ".SizeMax; adjusted SizeWarn to SizeMax (" + sizeMax + ")"; _instance.initializationData().logger.warning(s); sizeWarn = sizeMax; } int threadIdleTime = properties.getPropertyAsIntWithDefault(_prefix + ".ThreadIdleTime", 60); if (threadIdleTime < 0) { string s = _prefix + ".ThreadIdleTime < 0; ThreadIdleTime adjusted to 0"; _instance.initializationData().logger.warning(s); threadIdleTime = 0; } _size = size; _sizeMax = sizeMax; _sizeWarn = sizeWarn; _threadIdleTime = threadIdleTime; int stackSize = properties.getPropertyAsInt(_prefix + ".StackSize"); if (stackSize < 0) { string s = _prefix + ".StackSize < 0; Size adjusted to OS default"; _instance.initializationData().logger.warning(s); stackSize = 0; } _stackSize = stackSize; _priority = properties.getProperty(_prefix + ".ThreadPriority").Length > 0 ? Util.stringToThreadPriority(properties.getProperty(_prefix + ".ThreadPriority")) : Util.stringToThreadPriority(properties.getProperty("Ice.ThreadPriority")); if (_instance.traceLevels().threadPool >= 1) { string s = "creating " + _prefix + ": Size = " + _size + ", SizeMax = " + _sizeMax + ", SizeWarn = " + _sizeWarn; _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s); } _workItems = new Queue <ThreadPoolWorkItem>(); try { _threads = new List <WorkerThread>(); for (int i = 0; i < _size; ++i) { WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++); thread.start(_priority); _threads.Add(thread); } } catch (System.Exception ex) { string s = "cannot create thread for `" + _prefix + "':\n" + ex; _instance.initializationData().logger.error(s); destroy(); joinWithAllThreads(); throw; } }
private void getEndpointsException(Reference @ref, System.Exception exc) { try { throw exc; } catch (Ice.AdapterNotFoundException ex) { Instance instance = @ref.getInstance(); if (instance.traceLevels().location >= 1) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("adapter not found\n"); s.Append("adapter = " + @ref.getAdapterId()); instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } Ice.NotRegisteredException e = new Ice.NotRegisteredException(ex); e.kindOfObject = "object adapter"; e.id = @ref.getAdapterId(); throw e; } catch (Ice.ObjectNotFoundException ex) { Instance instance = @ref.getInstance(); if (instance.traceLevels().location >= 1) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("object not found\n"); s.Append("object = " + Ice.Util.identityToString(@ref.getIdentity(), instance.toStringMode())); instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } Ice.NotRegisteredException e = new Ice.NotRegisteredException(ex); e.kindOfObject = "object"; e.id = Ice.Util.identityToString(@ref.getIdentity(), instance.toStringMode()); throw e; } catch (Ice.NotRegisteredException) { throw; } catch (Ice.LocalException ex) { Instance instance = @ref.getInstance(); if (instance.traceLevels().location >= 1) { System.Text.StringBuilder s = new System.Text.StringBuilder(); s.Append("couldn't contact the locator to retrieve endpoints\n"); if (@ref.getAdapterId().Length > 0) { s.Append("adapter = " + @ref.getAdapterId() + "\n"); } else { s.Append("well-known proxy = " + @ref.ToString() + "\n"); } s.Append("reason = " + ex); instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } throw; } catch (System.Exception) { Debug.Assert(false); } }
// // Only for use by TcpConnector, TcpAcceptor // internal TcpTransceiver(Instance instance, Socket fd, EndPoint addr, bool connected) { _fd = fd; _addr = addr; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _state = connected ? StateConnected : StateNeedConnect; _desc = connected ? Network.fdToString(_fd) : "<not connected>"; #if ICE_SOCKET_ASYNC_API _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.RemoteEndPoint = _addr; _readEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.RemoteEndPoint = _addr; _writeEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted); #if SILVERLIGHT String policy = instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol"); if(policy.Equals("Http")) { _readEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; } else if(!String.IsNullOrEmpty(policy)) { _logger.warning("Ignoring invalid Ice.ClientAccessPolicyProtocol value `" + policy + "'"); } #endif #endif _maxSendPacketSize = Network.getSendBufferSize(fd); if(_maxSendPacketSize < 512) { _maxSendPacketSize = 0; } _maxReceivePacketSize = Network.getRecvBufferSize(fd); if(_maxReceivePacketSize < 512) { _maxReceivePacketSize = 0; } }
// // Only for use by UdpConnector. // internal UdpTransceiver(Instance instance, EndPoint addr, string mcastInterface, int mcastTtl) { _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _addr = addr; #if ICE_SOCKET_ASYNC_API _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.RemoteEndPoint = _addr; _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.RemoteEndPoint = _addr; _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted); #if SILVERLIGHT String policy = instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol"); if (policy.Equals("Http")) { _readEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; } else if (!String.IsNullOrEmpty(policy)) { _logger.warning("Ignoring invalid Ice.ClientAccessPolicyProtocol value `" + policy + "'"); } #endif #endif _mcastInterface = mcastInterface; _mcastTtl = mcastTtl; _state = StateNeedConnect; _incoming = false; try { _fd = Network.createSocket(true, _addr.AddressFamily); setBufSize(instance); #if !SILVERLIGHT Network.setBlock(_fd, false); if (AssemblyUtil.osx_) { // // On Windows, we delay the join for the mcast group after the connection // establishment succeeds. This is necessary for older Windows versions // where joining the group fails if the socket isn't bound. See ICE-5113. // if (Network.isMulticast((IPEndPoint)_addr)) { Network.setMcastGroup(_fd, ((IPEndPoint)_addr).Address, _mcastInterface); if (_mcastTtl != -1) { Network.setMcastTtl(_fd, _mcastTtl, _addr.AddressFamily); } } } #endif } catch (Ice.LocalException) { _fd = null; throw; } }
// // Only for use by UdpEndpoint. // internal UdpTransceiver(Instance instance, string host, int port, string mcastInterface, bool connect) { _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _state = connect ? StateNeedConnect : StateNotConnected; _incoming = true; try { _addr = Network.getAddressForServer(host, port, instance.protocolSupport(), instance.preferIPv6()); #if ICE_SOCKET_ASYNC_API _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.RemoteEndPoint = _addr; _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.RemoteEndPoint = _addr; _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted); #endif _fd = Network.createServerSocket(true, _addr.AddressFamily, instance.protocolSupport()); setBufSize(instance); #if !SILVERLIGHT Network.setBlock(_fd, false); #endif if (_traceLevels.network >= 2) { string s = "attempting to bind to udp socket " + Network.addrToString(_addr); _logger.trace(_traceLevels.networkCat, s); } #if !SILVERLIGHT if (Network.isMulticast((IPEndPoint)_addr)) { Network.setReuseAddress(_fd, true); _mcastAddr = (IPEndPoint)_addr; if (AssemblyUtil.platform_ == AssemblyUtil.Platform.Windows) { // // Windows does not allow binding to the mcast address itself // so we bind to INADDR_ANY (0.0.0.0) instead. As a result, // bi-directional connection won't work because the source // address won't the multicast address and the client will // therefore reject the datagram. // if (_addr.AddressFamily == AddressFamily.InterNetwork) { _addr = new IPEndPoint(IPAddress.Any, port); } else { _addr = new IPEndPoint(IPAddress.IPv6Any, port); } } _addr = Network.doBind(_fd, _addr); if (port == 0) { _mcastAddr.Port = ((IPEndPoint)_addr).Port; } Network.setMcastGroup(_fd, _mcastAddr.Address, mcastInterface); } else { if (AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows) { // // 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). // Network.setReuseAddress(_fd, true); } _addr = Network.doBind(_fd, _addr); } #endif if (_traceLevels.network >= 1) { StringBuilder s = new StringBuilder("starting to receive udp packets\n"); s.Append(ToString()); List <string> interfaces = Network.getHostsForEndpointExpand( Network.endpointAddressToString(_addr), instance.protocolSupport(), true); if (interfaces.Count != 0) { s.Append("\nlocal interfaces: "); s.Append(String.Join(", ", interfaces.ToArray())); } _logger.trace(_traceLevels.networkCat, s.ToString()); } } catch (Ice.LocalException) { _fd = null; throw; } }
// // Only for use by UdpConnector. // internal UdpTransceiver(Instance instance, EndPoint addr, string mcastInterface, int mcastTtl) { _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _addr = addr; #if ICE_SOCKET_ASYNC_API _readEventArgs = new SocketAsyncEventArgs(); _readEventArgs.RemoteEndPoint = _addr; _readEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted); _writeEventArgs = new SocketAsyncEventArgs(); _writeEventArgs.RemoteEndPoint = _addr; _writeEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ioCompleted); #if SILVERLIGHT String policy = instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol"); if(policy.Equals("Http")) { _readEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http; } else if(!String.IsNullOrEmpty(policy)) { _logger.warning("Ignoring invalid Ice.ClientAccessPolicyProtocol value `" + policy + "'"); } #endif #endif _mcastInterface = mcastInterface; _mcastTtl = mcastTtl; _state = StateNeedConnect; _incoming = false; try { _fd = Network.createSocket(true, _addr.AddressFamily); setBufSize(instance); #if !SILVERLIGHT Network.setBlock(_fd, false); if(AssemblyUtil.osx_) { // // On Windows, we delay the join for the mcast group after the connection // establishment succeeds. This is necessary for older Windows versions // where joining the group fails if the socket isn't bound. See ICE-5113. // if(Network.isMulticast((IPEndPoint)_addr)) { Network.setMcastGroup(_fd, ((IPEndPoint)_addr).Address, _mcastInterface); if(_mcastTtl != -1) { Network.setMcastTtl(_fd, _mcastTtl, _addr.AddressFamily); } } } #endif } catch(Ice.LocalException) { _fd = null; throw; } }
// // Only for use by UdpEndpoint. // internal UdpTransceiver(Instance instance, string host, int port, string mcastInterface, bool connect) { _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _stats = instance.initializationData().stats; _state = connect ? StateNeedConnect : StateNotConnected; _incoming = true; try { _addr = Network.getAddressForServer(host, port, instance.protocolSupport()); _fd = Network.createSocket(true, _addr.AddressFamily); setBufSize(instance); Network.setBlock(_fd, false); if(_traceLevels.network >= 2) { string s = "attempting to bind to udp socket " + Network.addrToString(_addr); _logger.trace(_traceLevels.networkCat, s); } if(Network.isMulticast(_addr)) { Network.setReuseAddress(_fd, true); _mcastAddr = _addr; if(AssemblyUtil.platform_ == AssemblyUtil.Platform.Windows) { // // Windows does not allow binding to the mcast address itself // so we bind to INADDR_ANY (0.0.0.0) instead. As a result, // bi-directional connection won't work because the source // address won't the multicast address and the client will // therefore reject the datagram. // if(_addr.AddressFamily == AddressFamily.InterNetwork) { _addr = new IPEndPoint(IPAddress.Any, port); } else { _addr = new IPEndPoint(IPAddress.IPv6Any, port); } } _addr = Network.doBind(_fd, _addr); if(port == 0) { _mcastAddr.Port = _addr.Port; } Network.setMcastGroup(_fd, _mcastAddr.Address, mcastInterface); } else { if(AssemblyUtil.platform_ != AssemblyUtil.Platform.Windows) { // // 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). // Network.setReuseAddress(_fd, true); } _addr = Network.doBind(_fd, _addr); } if(_traceLevels.network >= 1) { StringBuilder s = new StringBuilder("starting to receive udp packets\n"); s.Append(ToString()); List<string> interfaces = Network.getHostsForEndpointExpand(_addr.Address.ToString(), instance.protocolSupport(), true); if(interfaces.Count != 0) { s.Append("\nlocal interfaces: "); s.Append(String.Join(", ", interfaces.ToArray())); } _logger.trace(_traceLevels.networkCat, s.ToString()); } } catch(Ice.LocalException) { _fd = null; throw; } }
public ThreadPool(Instance instance, string prefix, int timeout) { Ice.Properties properties = instance.initializationData().properties; _instance = instance; _dispatcher = instance.initializationData().dispatcher; _destroyed = false; _prefix = prefix; _threadIndex = 0; _inUse = 0; _serialize = properties.getPropertyAsInt(_prefix + ".Serialize") > 0; _serverIdleTime = timeout; string programName = properties.getProperty("Ice.ProgramName"); if(programName.Length > 0) { _threadPrefix = programName + "-" + _prefix; } else { _threadPrefix = _prefix; } // // We use just one thread as the default. This is the fastest // possible setting, still allows one level of nesting, and // doesn't require to make the servants thread safe. // int size = properties.getPropertyAsIntWithDefault(_prefix + ".Size", 1); if(size < 1) { string s = _prefix + ".Size < 1; Size adjusted to 1"; _instance.initializationData().logger.warning(s); size = 1; } int sizeMax = properties.getPropertyAsIntWithDefault(_prefix + ".SizeMax", size); if(sizeMax < size) { string s = _prefix + ".SizeMax < " + _prefix + ".Size; SizeMax adjusted to Size (" + size + ")"; _instance.initializationData().logger.warning(s); sizeMax = size; } int sizeWarn = properties.getPropertyAsInt(_prefix + ".SizeWarn"); if(sizeWarn != 0 && sizeWarn < size) { string s = _prefix + ".SizeWarn < " + _prefix + ".Size; adjusted SizeWarn to Size (" + size + ")"; _instance.initializationData().logger.warning(s); sizeWarn = size; } else if(sizeWarn > sizeMax) { string s = _prefix + ".SizeWarn > " + _prefix + ".SizeMax; adjusted SizeWarn to SizeMax (" + sizeMax + ")"; _instance.initializationData().logger.warning(s); sizeWarn = sizeMax; } int threadIdleTime = properties.getPropertyAsIntWithDefault(_prefix + ".ThreadIdleTime", 60); if(threadIdleTime < 0) { string s = _prefix + ".ThreadIdleTime < 0; ThreadIdleTime adjusted to 0"; _instance.initializationData().logger.warning(s); threadIdleTime = 0; } _size = size; _sizeMax = sizeMax; _sizeWarn = sizeWarn; _threadIdleTime = threadIdleTime; int stackSize = properties.getPropertyAsInt(_prefix + ".StackSize"); if(stackSize < 0) { string s = _prefix + ".StackSize < 0; Size adjusted to OS default"; _instance.initializationData().logger.warning(s); stackSize = 0; } _stackSize = stackSize; _hasPriority = properties.getProperty(_prefix + ".ThreadPriority").Length > 0; _priority = IceInternal.Util.stringToThreadPriority(properties.getProperty(_prefix + ".ThreadPriority")); if(!_hasPriority) { _hasPriority = properties.getProperty("Ice.ThreadPriority").Length > 0; _priority = IceInternal.Util.stringToThreadPriority(properties.getProperty("Ice.ThreadPriority")); } if(_instance.traceLevels().threadPool >= 1) { string s = "creating " + _prefix + ": Size = " + _size + ", SizeMax = " + _sizeMax + ", SizeWarn = " + _sizeWarn; _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s); } _workItems = new Queue<ThreadPoolWorkItem>(); try { _threads = new List<WorkerThread>(); for(int i = 0; i < _size; ++i) { WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++); if(_hasPriority) { thread.start(_priority); } else { thread.start(ThreadPriority.Normal); } _threads.Add(thread); } } catch(System.Exception ex) { string s = "cannot create thread for `" + _prefix + "':\n" + ex; _instance.initializationData().logger.error(s); destroy(); joinWithAllThreads(); throw; } }
// // Only for use by ObjectAdapterFactory // public ObjectAdapterI(Instance instance, Communicator communicator, ObjectAdapterFactory objectAdapterFactory, string name, RouterPrx router, bool noConfig) { instance_ = instance; _communicator = communicator; _objectAdapterFactory = objectAdapterFactory; _servantManager = new ServantManager(instance, name); _name = name; _incomingConnectionFactories = new List<IncomingConnectionFactory>(); _publishedEndpoints = new List<EndpointI>(); _routerEndpoints = new List<EndpointI>(); _routerInfo = null; _directCount = 0; _noConfig = noConfig; _processId = null; if(_noConfig) { _id = ""; _replicaGroupId = ""; _reference = instance_.referenceFactory().create("dummy -t", ""); _acm = instance_.serverACM(); return; } Properties properties = instance_.initializationData().properties; List<string> unknownProps = new List<string>(); bool noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if(unknownProps.Count != 0 && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { StringBuilder message = new StringBuilder("found unknown properties for object adapter `"); message.Append(_name); message.Append("':"); foreach(string s in unknownProps) { message.Append("\n "); message.Append(s); } instance_.initializationData().logger.warning(message.ToString()); } // // Make sure named adapter has configuration. // if(router == null && noProps) { // // These need to be set to prevent warnings/asserts in the destructor. // state_ = StateDestroyed; instance_ = null; _incomingConnectionFactories = null; InitializationException ex = new InitializationException(); ex.reason = "object adapter `" + _name + "' requires configuration"; throw ex; } _id = properties.getProperty(_name + ".AdapterId"); _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId"); // // Setup a reference to be used to get the default proxy options // when creating new proxies. By default, create twoway proxies. // string proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t"); try { _reference = instance_.referenceFactory().create("dummy " + proxyOptions, ""); } catch(ProxyParseException) { InitializationException ex = new InitializationException(); ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; throw ex; } _acm = new ACMConfig(properties, communicator.getLogger(), _name + ".ACM", instance_.serverACM()); { int defaultMessageSizeMax = instance.messageSizeMax() / 1024; int num = properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax); if(num < 1 || num > 0x7fffffff / 1024) { _messageSizeMax = 0x7fffffff; } else { _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes } } try { int threadPoolSize = properties.getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax"); if(threadPoolSize > 0 || threadPoolSizeMax > 0) { _threadPool = new ThreadPool(instance_, _name + ".ThreadPool", 0); } if(router == null) { router = RouterPrxHelper.uncheckedCast( instance_.proxyFactory().propertyToProxy(_name + ".Router")); } if(router != null) { _routerInfo = instance_.routerManager().get(router); if(_routerInfo != null) { // // Make sure this router is not already registered with another adapter. // if(_routerInfo.getAdapter() != null) { Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException(); ex.kindOfObject = "object adapter with router"; ex.id = instance_.identityToString(router.ice_getIdentity()); throw ex; } // // Add the router's server proxy endpoints to this object // adapter. // EndpointI[] endpoints = _routerInfo.getServerEndpoints(); for(int i = 0; i < endpoints.Length; ++i) { _routerEndpoints.Add(endpoints[i]); } _routerEndpoints.Sort(); // Must be sorted. // // Remove duplicate endpoints, so we have a list of unique endpoints. // for(int i = 0; i < _routerEndpoints.Count-1;) { EndpointI e1 = _routerEndpoints[i]; EndpointI e2 = _routerEndpoints[i + 1]; if(e1.Equals(e2)) { _routerEndpoints.RemoveAt(i); } else { ++i; } } // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo.setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // instance_.outgoingConnectionFactory().setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. The connection // factory might change it, for example, to fill in the real port number. // List<EndpointI> endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints"), true); foreach(EndpointI endp in endpoints) { IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this); _incomingConnectionFactories.Add(factory); } if(endpoints.Count == 0) { TraceLevels tl = instance_.traceLevels(); if(tl.network >= 2) { instance_.initializationData().logger.trace(tl.networkCat, "created adapter `" + _name + "' without endpoints"); } } // // Parse published endpoints. // _publishedEndpoints = parsePublishedEndpoints(); } if(properties.getProperty(_name + ".Locator").Length > 0) { setLocator(LocatorPrxHelper.uncheckedCast( instance_.proxyFactory().propertyToProxy(_name + ".Locator"))); } else { setLocator(instance_.referenceFactory().getDefaultLocator()); } } catch(LocalException) { destroy(); throw; } }