} // StopListening // // end of IChannelReceiver implementation // // Thread for listening void Listen() { InternalRemotingServices.RemotingTrace("Waiting to Accept a Connection on Port: " + _portName); // // Wait for an incoming client connection // IntPtr handle = IntPtr.Zero; bool connected = false; CommonSecurityDescriptor descriptor = _securityDescriptor; // Connect with exlusive flag the first time try{ // If the descriptor is not explicitly set through code use the _authorizedGroup config if (descriptor == null && _authorizedGroup != null) { NTAccount ntAccount = new NTAccount(_authorizedGroup); descriptor = IpcPort.CreateSecurityDescriptor((SecurityIdentifier)ntAccount.Translate(typeof(SecurityIdentifier))); } _port = IpcPort.Create(_portName, descriptor, _bExclusiveAddressUse); } catch (Exception e) { _startListeningException = e; } finally { _bListening = (_startListeningException == null); _waitForStartListening.Set(); // allow main thread to continue now that we have tried to start the socket } if (_port != null) { connected = _port.WaitForConnect(); } while (_bListening) { InternalRemotingServices.RemotingTrace("IpcChannel::Listen"); // For DevDiv#220882, we need to create new IpcPort before handling the current message // to avoid race condition in case the message is handled and finished before // the new IpcPort is created. The client will intermittently fail with Port not found. IpcPort port = IpcPort.Create(_portName, descriptor, false); if (connected) { // Initialize the server handler and perform an async read IpcServerHandler serverHandler = new IpcServerHandler(_port, CoreChannel.RequestQueue, new PipeStream(_port)); serverHandler.DataArrivedCallback = new WaitCallback(_transportSink.ServiceRequest); serverHandler.BeginReadMessage(); } _port = port; connected = _port.WaitForConnect(); } }
private void Listen() { bool flag = true; bool flag2 = false; CommonSecurityDescriptor securityDescriptor = this._securityDescriptor; if (flag) { try { if ((securityDescriptor == null) && (this._authorizedGroup != null)) { NTAccount account = new NTAccount(this._authorizedGroup); securityDescriptor = IpcPort.CreateSecurityDescriptor((SecurityIdentifier)account.Translate(typeof(SecurityIdentifier))); } this._port = IpcPort.Create(this._portName, securityDescriptor, this._bExclusiveAddressUse); } catch (Exception exception) { this._startListeningException = exception; } finally { this._waitForStartListening.Set(); } if (this._port != null) { flag2 = this._port.WaitForConnect(); flag = this._bListening; } } while (flag && (this._startListeningException == null)) { IpcPort port = IpcPort.Create(this._portName, securityDescriptor, false); if (flag2) { new IpcServerHandler(this._port, CoreChannel.RequestQueue, new PipeStream(this._port)) { DataArrivedCallback = new WaitCallback(this._transportSink.ServiceRequest) }.BeginReadMessage(); } this._port = port; flag2 = this._port.WaitForConnect(); flag = this._bListening; } }