private void ReconnectCallback(object state) { BackoffTimeoutHelper helper = new BackoffTimeoutHelper(TimeSpan.MaxValue, TimeSpan.FromMinutes(5.0), TimeSpan.FromSeconds(30.0)); while (this.state == CommunicationState.Opening) { try { this.StartListen(true); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error); } } if (this.state == CommunicationState.Opening) { helper.WaitAndBackoff(); } } }
private IConnection TryConnect(Uri remoteUri, string resolvedAddress, BackoffTimeoutHelper backoffHelper) { bool flag = backoffHelper.IsExpired(); int dwFlagsAndAttributes = 0x40000000; if (this.includeSecurityIdentity) { dwFlagsAndAttributes |= 0x110000; } PipeHandle handle = UnsafeNativeMethods.CreateFile(resolvedAddress, -1073741824, 0, IntPtr.Zero, 3, dwFlagsAndAttributes, IntPtr.Zero); int errorCode = Marshal.GetLastWin32Error(); if (handle.IsInvalid) { handle.SetHandleAsInvalid(); } else { int mode = 2; if (UnsafeNativeMethods.SetNamedPipeHandleState(handle, ref mode, IntPtr.Zero, IntPtr.Zero) == 0) { errorCode = Marshal.GetLastWin32Error(); handle.Close(); PipeException exception = new PipeException(System.ServiceModel.SR.GetString("PipeModeChangeFailed", new object[] { PipeError.GetErrorString(errorCode) }), errorCode); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.CreateConnectFailedException(remoteUri, exception)); } return(new PipeConnection(handle, this.bufferSize, false, true)); } if ((errorCode == 2) || (errorCode == 0xe7)) { TimeoutException exception3; if (!flag) { return(null); } Exception exception2 = new PipeException(System.ServiceModel.SR.GetString("PipeConnectAddressFailed", new object[] { resolvedAddress, PipeError.GetErrorString(errorCode) }), errorCode); string absoluteUri = remoteUri.AbsoluteUri; if (errorCode == 0xe7) { exception3 = new TimeoutException(System.ServiceModel.SR.GetString("PipeConnectTimedOutServerTooBusy", new object[] { absoluteUri, backoffHelper.OriginalTimeout }), exception2); } else { exception3 = new TimeoutException(System.ServiceModel.SR.GetString("PipeConnectTimedOut", new object[] { absoluteUri, backoffHelper.OriginalTimeout }), exception2); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception3); } PipeException innerException = new PipeException(System.ServiceModel.SR.GetString("PipeConnectAddressFailed", new object[] { resolvedAddress, PipeError.GetErrorString(errorCode) }), errorCode); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.CreateConnectFailedException(remoteUri, innerException)); }
private ServiceControllerStatus ExitServiceStatus(ServiceController service, int pollMin, int pollMax, ServiceControllerStatus status) { ServiceControllerStatus status2; BackoffTimeoutHelper helper = new BackoffTimeoutHelper(TimeSpan.MaxValue, TimeSpan.FromMilliseconds((double)pollMax), TimeSpan.FromMilliseconds((double)pollMin)); do { if (this.closed) { return(service.Status); } helper.WaitAndBackoff(); service.Refresh(); status2 = service.Status; }while (status2 == status); return(status2); }
public void Listen() { BackoffTimeoutHelper helper = new BackoffTimeoutHelper(TimeSpan.FromSeconds(1.0)); lock (this.ThisLock) { if (this.listenSocket != null) { this.listenSocket.Listen(this.settings.ListenBacklog); this.isListening = true; } while (!this.isListening) { try { this.listenSocket = new Socket(this.localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if ((this.localEndpoint.AddressFamily == AddressFamily.InterNetworkV6) && this.settings.TeredoEnabled) { this.listenSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPProtectionLevel, 10); } this.listenSocket.Bind(this.localEndpoint); this.listenSocket.Listen(this.settings.ListenBacklog); this.isListening = true; continue; } catch (SocketException exception) { bool flag = false; if ((exception.ErrorCode == 0x2740) && !helper.IsExpired()) { helper.WaitAndBackoff(); flag = true; } if (!flag) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ConvertListenException(exception, this.localEndpoint)); } continue; } } this.socketAsyncEventArgsPool = new SocketAsyncEventArgsPool(GetAcceptBufferSize(this.listenSocket)); } }
private void PrepareConnect(Uri remoteUri, TimeSpan timeout, out string resolvedAddress, out BackoffTimeoutHelper backoffHelper) { TimeSpan span; PipeUri.Validate(remoteUri); if (DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, 0x4002a, System.ServiceModel.SR.GetString("TraceCodeInitiatingNamedPipeConnection"), new StringTraceRecord("Uri", remoteUri.ToString()), this, null); } resolvedAddress = GetPipeName(remoteUri); if (timeout >= TimeSpan.FromMilliseconds(300.0)) { span = TimeoutHelper.Add(timeout, TimeSpan.Zero - TimeSpan.FromMilliseconds(150.0)); } else { span = Ticks.ToTimeSpan((Ticks.FromMilliseconds(150) / 2L) + 1L); } backoffHelper = new BackoffTimeoutHelper(span, TimeSpan.FromMinutes(5.0)); }