private void OnConnectionDequeued() { lock (this.ThisLock) { ConnectionAcceptor connectionAcceptor = this; connectionAcceptor.connections = connectionAcceptor.connections - 1; } this.AcceptIfNecessary(false); }
private void AcceptIfNecessary(bool startAccepting) { if (this.IsAcceptNecessary) { lock (this.ThisLock) { while (this.IsAcceptNecessary) { IAsyncResult asyncResult = null; Exception exception = null; try { asyncResult = this.listener.BeginAccept(this.acceptCompletedCallback, null); } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation) { Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(communicationException, TraceEventType.Information); } } catch (Exception exception2) { Exception exception1 = exception2; if (Fx.IsFatal(exception1)) { throw; } if (startAccepting) { throw; } if (this.errorCallback == null && !ExceptionHandler.HandleTransportExceptionHelper(exception1)) { throw; } exception = exception1; } if (exception != null && this.errorCallback != null) { this.errorCallback(exception); } if (asyncResult == null) { continue; } if (asyncResult.CompletedSynchronously) { IOThreadScheduler.ScheduleCallbackNoFlow(this.scheduleAcceptCallback, asyncResult); } ConnectionAcceptor connectionAcceptor = this; connectionAcceptor.pendingAccepts = connectionAcceptor.pendingAccepts + 1; } } } }
private void HandleCompletedAccept(IAsyncResult result) { IConnection connection = null; lock (this.ThisLock) { bool flag = false; Exception exception = null; try { try { if (!this.isDisposed) { connection = this.listener.EndAccept(result); if (connection != null) { if (this.connections + 1 >= this.maxPendingConnections && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceWarning) { TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.MaxPendingConnectionsReached, new StringTraceRecord("MaxPendingConnections", this.maxPendingConnections.ToString(CultureInfo.InvariantCulture)), this, null); } ConnectionAcceptor connectionAcceptor = this; connectionAcceptor.connections = connectionAcceptor.connections + 1; } } flag = true; } catch (CommunicationException communicationException1) { CommunicationException communicationException = communicationException1; if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation) { Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(communicationException, TraceEventType.Information); } } catch (Exception exception2) { Exception exception1 = exception2; if (Fx.IsFatal(exception1)) { throw; } if (this.errorCallback == null && !ExceptionHandler.HandleTransportExceptionHelper(exception1)) { throw; } exception = exception1; } } finally { if (!flag) { connection = null; } ConnectionAcceptor connectionAcceptor1 = this; connectionAcceptor1.pendingAccepts = connectionAcceptor1.pendingAccepts - 1; } if (exception != null && this.errorCallback != null) { this.errorCallback(exception); } } this.AcceptIfNecessary(false); if (connection != null) { this.callback(connection, this.onConnectionDequeued); } }