private bool HandleWriteUpgradeResponseComplete(IAsyncResult result) { bool flag; this.channel.Connection.EndWrite(result); IConnection innerConnection = this.channel.Connection; if (this.channel.size > 0) { innerConnection = new PreReadConnection(innerConnection, this.channel.connectionBuffer, this.channel.offset, this.channel.size); } if (onUpgradeConnection == null) { onUpgradeConnection = Fx.ThunkCallback(new AsyncCallback(ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.OnUpgradeConnection)); } try { IAsyncResult result2 = InitialServerConnectionReader.BeginUpgradeConnection(innerConnection, this.channel.upgradeAcceptor, this.channel, onUpgradeConnection, this); if (!result2.CompletedSynchronously) { return false; } flag = this.HandleUpgradeConnectionComplete(result2); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.channel.WriteAuditFailure(this.channel.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } return flag; }
private void OnConnectionClosed(InitialServerConnectionReader connectionReader) { lock (this.ThisLock) { if (!this.isDisposed) { this.connectionReaders.Remove(connectionReader); } } }
void OnConnectionClosed(InitialServerConnectionReader connectionReader) { lock (ThisLock) { if (isDisposed) { return; } connectionReaders.Remove(connectionReader); } }
private bool ContinueReading() { while (true) { if (this.size == 0) { if (readCallback == null) { readCallback = new WaitCallback(ConnectionModeReader.ReadCallback); } if (base.Connection.BeginRead(0, base.Connection.AsyncReadBufferSize, this.GetRemainingTimeout(), readCallback, this) == AsyncReadResult.Queued) { return(false); } if (!this.GetReadResult()) { return(false); } } do { int num; try { num = this.decoder.Decode(this.buffer, this.offset, this.size); } catch (CommunicationException exception) { string str; if (FramingEncodingString.TryGetFaultString(exception, out str)) { byte[] drainBuffer = new byte[0x80]; InitialServerConnectionReader.SendFault(base.Connection, str, drainBuffer, this.GetRemainingTimeout(), base.MaxViaSize + base.MaxContentTypeSize); base.Close(this.GetRemainingTimeout()); } throw; } if (num > 0) { this.offset += num; this.size -= num; } if (this.decoder.CurrentState == ServerModeDecoder.State.Done) { return(true); } }while (this.size != 0); } }
private void SendFault(IConnection connection, string faultCode) { try { if (drainBuffer == null) { drainBuffer = new byte[0x400]; } InitialServerConnectionReader.SendFault(connection, faultCode, drainBuffer, ListenerConstants.SharedSendTimeout, 0x10000); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (DiagnosticUtility.ShouldTraceError) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Error); } } }
void OnViaDecoded(InitialServerConnectionReader connectionReader, ListenerSessionConnection session) { try { connectionHandleDuplicated(session); } finally { session.TriggerDequeuedCallback(); } lock (ThisLock) { if (isDisposed) { return; } connectionReaders.Remove(connectionReader); } }
bool ContinueReading() { for (;;) { if (size == 0) { if (readCallback == null) { readCallback = new WaitCallback(ReadCallback); } if (Connection.BeginRead(0, Connection.AsyncReadBufferSize, GetRemainingTimeout(), readCallback, this) == AsyncCompletionResult.Queued) { break; } if (!GetReadResult()) // we're at EOF, bail { return(false); } } for (;;) { int bytesDecoded; try { bytesDecoded = decoder.Decode(buffer, offset, size); } catch (CommunicationException e) { // see if we need to send back a framing fault string framingFault; if (FramingEncodingString.TryGetFaultString(e, out framingFault)) { byte[] drainBuffer = new byte[128]; InitialServerConnectionReader.SendFault( Connection, framingFault, drainBuffer, GetRemainingTimeout(), MaxViaSize + MaxContentTypeSize); base.Close(GetRemainingTimeout()); } throw; } if (bytesDecoded > 0) { offset += bytesDecoded; size -= bytesDecoded; } if (decoder.CurrentState == ServerModeDecoder.State.Done) { return(true); } if (size == 0) { break; } } } return(false); }
protected void SendFault(string faultString, TimeSpan timeout) { byte[] drainBuffer = new byte[0x80]; InitialServerConnectionReader.SendFault(this.connection, faultString, drainBuffer, timeout, 0x10000); }
public IConnection CompletePreamble(TimeSpan timeout) { int num; TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (!this.transportSettings.MessageEncoderFactory.Encoder.IsContentTypeSupported(this.decoder.ContentType)) { this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeInvalid", ref timeoutHelper); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("ContentTypeMismatch", new object[] { this.decoder.ContentType, this.transportSettings.MessageEncoderFactory.Encoder.ContentType }))); } StreamUpgradeAcceptor upgradeAcceptor = null; StreamUpgradeProvider upgrade = this.transportSettings.Upgrade; IStreamUpgradeChannelBindingProvider property = null; if (upgrade != null) { property = upgrade.GetProperty <IStreamUpgradeChannelBindingProvider>(); upgradeAcceptor = upgrade.CreateUpgradeAcceptor(); } IConnection connection = base.Connection; Label_00B1: if (this.size == 0) { this.offset = 0; this.size = connection.Read(this.connectionBuffer, 0, this.connectionBuffer.Length, timeoutHelper.RemainingTime()); if (this.size == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException()); } } Label_0101: num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size); if (num > 0) { this.offset += num; this.size -= num; } switch (this.decoder.CurrentState) { case ServerSingletonDecoder.State.UpgradeRequest: { if (upgradeAcceptor == null) { this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("UpgradeRequestToNonupgradableService", new object[] { this.decoder.Upgrade }))); } if (!upgradeAcceptor.CanUpgrade(this.decoder.Upgrade)) { this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("UpgradeProtocolNotSupported", new object[] { this.decoder.Upgrade }))); } connection.Write(ServerSingletonEncoder.UpgradeResponseBytes, 0, ServerSingletonEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime()); IConnection innerConnection = connection; if (this.size > 0) { innerConnection = new PreReadConnection(innerConnection, this.connectionBuffer, this.offset, this.size); } try { connection = InitialServerConnectionReader.UpgradeConnection(innerConnection, upgradeAcceptor, this.transportSettings); this.connectionBuffer = connection.AsyncReadBuffer; if ((property != null) && property.IsChannelBindingSupportEnabled) { this.channelBindingToken = property.GetChannelBinding(upgradeAcceptor, ChannelBindingKind.Endpoint); } goto Label_02C0; } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.WriteAuditFailure(upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } break; } case ServerSingletonDecoder.State.Start: break; default: goto Label_02C0; } this.SetupSecurityIfNecessary(upgradeAcceptor); connection.Write(ServerSessionEncoder.AckResponseBytes, 0, ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime()); return(connection); Label_02C0: if (this.size != 0) { goto Label_0101; } goto Label_00B1; }
private void SendFault(string faultString, ref TimeoutHelper timeoutHelper) { InitialServerConnectionReader.SendFault(base.Connection, faultString, this.connectionBuffer, timeoutHelper.RemainingTime(), 0x10000); }
private bool HandleUpgradeConnectionComplete(IAsyncResult result) { this.channel.AcceptUpgradedConnection(InitialServerConnectionReader.EndUpgradeConnection(result)); return true; }
protected override void OnOpen(TimeSpan timeout) { bool flag = false; try { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); this.ValidateContentType(ref timeoutHelper); Label_0017: if (this.size == 0) { this.offset = 0; this.size = base.Connection.Read(this.connectionBuffer, 0, this.connectionBuffer.Length, timeoutHelper.RemainingTime()); if (this.size == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException()); } } Label_006B: this.DecodeBytes(); switch (this.decoder.CurrentState) { case ServerSessionDecoder.State.UpgradeRequest: { this.ProcessUpgradeRequest(ref timeoutHelper); base.Connection.Write(ServerSessionEncoder.UpgradeResponseBytes, 0, ServerSessionEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime()); IConnection innerConnection = base.Connection; if (this.size > 0) { innerConnection = new PreReadConnection(innerConnection, this.connectionBuffer, this.offset, this.size); } try { base.Connection = InitialServerConnectionReader.UpgradeConnection(innerConnection, this.upgradeAcceptor, this); if ((this.channelBindingProvider != null) && this.channelBindingProvider.IsChannelBindingSupportEnabled) { base.SetChannelBinding(this.channelBindingProvider.GetChannelBinding(this.upgradeAcceptor, ChannelBindingKind.Endpoint)); } this.connectionBuffer = base.Connection.AsyncReadBuffer; goto Label_018C; } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.WriteAuditFailure(this.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } break; } case ServerSessionDecoder.State.Start: break; default: goto Label_018C; } this.SetupSecurityIfNecessary(); base.Connection.Write(ServerSessionEncoder.AckResponseBytes, 0, ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime()); this.SetupSessionReader(); flag = true; return; Label_018C: if (this.size != 0) { goto Label_006B; } goto Label_0017; } finally { if (!flag) { base.Connection.Abort(); } } }
public void SendFault(string faultString) { InitialServerConnectionReader.SendFault(base.Connection, faultString, this.connectionBuffer, this.GetRemainingTimeout(), 0x10000); base.Close(this.GetRemainingTimeout()); }