public void WaitUntilFinished() { lock (this) { // First we wait until the factory is destroyed. If we are using // an acceptor, we also wait for it to be closed. while (!_destroyed) { System.Threading.Monitor.Wait(this); } } // _connections is immutable in this state foreach (Connection connection in _connections) { connection.WaitUntilFinished(); } // Ensure all the connections are finished and reaped. if (_transceiver == null) { #if DEBUG IEnumerable <Connection> cons = _monitor.SwapReapedConnections(); Debug.Assert(cons.Count() == _connections.Count); #else _monitor.SwapReapedConnections(); #endif } _connections.Clear(); // Must be destroyed outside the synchronization since this might block waiting for // a timer task to execute. _monitor.Destroy(); }
public IncomingConnectionFactory(ObjectAdapter adapter, Endpoint endpoint, Endpoint?publish, ACMConfig acmConfig) { _communicator = adapter.Communicator; _endpoint = endpoint; _publishedEndpoint = publish; _adapter = adapter; _warn = _communicator.GetPropertyAsBool("Ice.Warn.Connections") ?? false; _monitor = new FactoryACMMonitor(_communicator, acmConfig); if (_communicator.OverrideTimeout != null) { _endpoint = _endpoint.NewTimeout(_communicator.OverrideTimeout.Value); } if (_communicator.OverrideCompress != null) { _endpoint = _endpoint.NewCompressionFlag(_communicator.OverrideCompress.Value); } try { _transceiver = _endpoint.GetTransceiver(); if (_transceiver != null) { if (_communicator.TraceLevels.Network >= 2) { _communicator.Logger.Trace(_communicator.TraceLevels.NetworkCat, $"attempting to bind to {_endpoint.Name} socket\n{_transceiver}"); } _endpoint = _transceiver.Bind(); var connection = new Connection(_communicator, null, _transceiver, null, _endpoint, _adapter); _ = connection.StartAsync(); _connections.Add(connection); } else { _acceptor = _endpoint.GetAcceptor(_adapter !.Name); if (_communicator.TraceLevels.Network >= 2) { _communicator.Logger.Trace(_communicator.TraceLevels.NetworkCat, $"attempting to bind to {_endpoint.Name} socket {_acceptor}"); } _endpoint = _acceptor !.Listen(); if (_communicator.TraceLevels.Network >= 1) { _communicator.Logger.Trace(_communicator.TraceLevels.NetworkCat, $"listening for {_endpoint.Name} connections\n{_acceptor!.ToDetailedString()}"); } } } catch (System.Exception) { // // Clean up. // try { _transceiver?.Close(); _acceptor?.Close(); } catch (System.Exception) { // Ignore } _monitor.Destroy(); _connections.Clear(); throw; } }