public ServerSingletonConnectionReader(Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader preambleReader, Microsoft.ServiceBus.Channels.IConnection upgradedConnection, Microsoft.ServiceBus.Channels.ConnectionDemuxer connectionDemuxer) : base(upgradedConnection, preambleReader.BufferOffset, preambleReader.BufferSize, preambleReader.Security, preambleReader.TransportSettings, preambleReader.Via) { this.decoder = preambleReader.Decoder; this.contentType = this.decoder.ContentType; this.connectionDemuxer = connectionDemuxer; this.rawConnection = preambleReader.RawConnection; }
public void SendRequest(Message message, TimeSpan timeout) { Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { this.connection = this.connectionPoolHelper.EstablishConnection(timeoutHelper.RemainingTime()); MessagingClientEtwProvider.Provider.RelayChannelConnectionTransfer(this.Activity, this.connection.Activity); bool flag = false; try { Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessage(message, this.connection, true, this.channel.settings, ref timeoutHelper); flag = true; } finally { if (!flag) { this.connectionPoolHelper.Abort(); } } } catch (TimeoutException timeoutException1) { TimeoutException timeoutException = timeoutException1; ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string timeoutOnRequest = Resources.TimeoutOnRequest; object[] objArray = new object[] { timeout }; throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(timeoutOnRequest, objArray), timeoutException)); } }
private Microsoft.ServiceBus.Channels.ConnectionModeReader SetupModeReader(Microsoft.ServiceBus.Channels.IConnection connection, bool isCached) { Microsoft.ServiceBus.Channels.ConnectionModeReader connectionModeReader; Microsoft.ServiceBus.Channels.ConnectionModeReader connectionModeReader1; if (!isCached) { if (this.onConnectionModeKnown == null) { this.onConnectionModeKnown = new Microsoft.ServiceBus.Channels.ConnectionModeCallback(this.OnConnectionModeKnown); } connectionModeReader = new Microsoft.ServiceBus.Channels.ConnectionModeReader(connection, this.onConnectionModeKnown, this.onConnectionClosed); } else { if (this.onCachedConnectionModeKnown == null) { this.onCachedConnectionModeKnown = new Microsoft.ServiceBus.Channels.ConnectionModeCallback(this.OnCachedConnectionModeKnown); } connectionModeReader = new Microsoft.ServiceBus.Channels.ConnectionModeReader(connection, this.onCachedConnectionModeKnown, this.onConnectionClosed); } lock (this.ThisLock) { if (!this.isClosed) { this.connectionReaders.Add(connectionModeReader); connectionModeReader1 = connectionModeReader; } else { connectionModeReader.Dispose(); connectionModeReader1 = null; } } return(connectionModeReader1); }
public IAsyncResult BeginWrite(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult asyncResult; Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size); Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { lock (this.ThisLock) { if (this.writeConnectionQueue.Count > 0) { this.writeConnection.Shutdown(timeoutHelper.RemainingTime()); this.writeConnection = this.writeConnectionQueue.Dequeue(); } } IAsyncResult asyncResult1 = this.writeConnection.BeginWrite(buffer, offset, size, immediate, timeoutHelper.RemainingTime(), callback, state); asyncResult = asyncResult1; } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType); } throw; } return(asyncResult); }
private bool HandleWriteUpgradeResponseComplete(IAsyncResult result) { bool flag; this.channel.Connection.EndWrite(result); Microsoft.ServiceBus.Channels.IConnection connection = this.channel.Connection; if (this.channel.size > 0) { connection = new Microsoft.ServiceBus.Channels.PreReadConnection(connection, this.channel.connectionBuffer, this.channel.offset, this.channel.size); } if (Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.onUpgradeConnection == null) { Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.onUpgradeConnection = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.OnUpgradeConnection)); } try { IAsyncResult asyncResult = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.BeginUpgradeConnection(connection, this.channel.upgradeAcceptor, this.channel, Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.OpenAsyncResult.onUpgradeConnection, this); flag = (asyncResult.CompletedSynchronously ? this.HandleUpgradeConnectionComplete(asyncResult) : false); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.channel.WriteAuditFailure(this.channel.upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception); throw; } return(flag); }
public void Write(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout) { Microsoft.ServiceBus.Channels.ConnectionUtilities.ValidateBufferBounds(buffer, offset, size); Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { lock (this.ThisLock) { if (this.writeConnectionQueue.Count > 0) { this.writeConnection.Shutdown(timeoutHelper.RemainingTime()); this.writeConnection = this.writeConnectionQueue.Dequeue(); } } int num = size; while (num > 0) { size = Math.Min(num, 65536); this.writeConnection.Write(buffer, offset, size, immediate, timeoutHelper.RemainingTime()); num = num - size; offset = offset + size; timeout = timeoutHelper.RemainingTime(); } } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType); } throw; } }
private Microsoft.ServiceBus.Channels.IConnection SendPreamble(Microsoft.ServiceBus.Channels.IConnection connection, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, out SecurityMessageProperty remoteSecurity) { connection.Write(this.Preamble, 0, (int)this.Preamble.Length, true, timeoutHelper.RemainingTime()); if (this.upgrade == null) { remoteSecurity = null; } else { StreamUpgradeInitiator streamUpgradeInitiator = this.upgrade.CreateUpgradeInitiator(base.RemoteAddress, base.Via); if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgrade(streamUpgradeInitiator, ref connection, decoder, this, ref timeoutHelper)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, base.Via, this.messageEncoder.ContentType, ref timeoutHelper); } if (!(streamUpgradeInitiator is StreamSecurityUpgradeInitiator)) { remoteSecurity = null; } else { remoteSecurity = ((StreamSecurityUpgradeInitiator)streamUpgradeInitiator).GetRemoteSecurity(); } connection.Write(Microsoft.ServiceBus.Channels.ClientSingletonEncoder.PreambleEndBytes, 0, (int)Microsoft.ServiceBus.Channels.ClientSingletonEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime()); } byte[] numArray = new byte[1]; if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), decoder, base.Via)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(decoder, connection, base.Via, this.messageEncoder.ContentType, ref timeoutHelper); } return(connection); }
private Microsoft.ServiceBus.Channels.IConnection SendPreamble(Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> preamble, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper) { this.decoder = new Microsoft.ServiceBus.Channels.ClientDuplexDecoder((long)0); byte[] numArray = new byte[1]; connection.Write(preamble.Array, preamble.Offset, preamble.Count, true, timeoutHelper.RemainingTime()); if (this.upgrade != null) { StreamUpgradeInitiator streamUpgradeInitiator = this.upgrade.CreateUpgradeInitiator(this.RemoteAddress, this.Via); Type type = streamUpgradeInitiator.GetType(); object[] objArray = new object[] { timeoutHelper.RemainingTime() }; InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "Open", objArray); if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.InitiateUpgrade(streamUpgradeInitiator, ref connection, this.decoder, this, ref timeoutHelper)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(this.decoder, connection, this.Via, base.MessageEncoder.ContentType, ref timeoutHelper); } this.SetRemoteSecurity(streamUpgradeInitiator); Type type1 = streamUpgradeInitiator.GetType(); object[] objArray1 = new object[] { timeoutHelper.RemainingTime() }; InvokeHelper.InvokeInstanceMethod(type1, streamUpgradeInitiator, "Close", objArray1); connection.Write(Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes, 0, (int)Microsoft.ServiceBus.Channels.SessionEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime()); } if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidatePreambleResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), this.decoder, this.Via)) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFramingFault(this.decoder, connection, this.Via, base.MessageEncoder.ContentType, ref timeoutHelper); } return(connection); }
public ServerSessionConnectionReader(Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel channel) : base(channel.Connection, channel.rawConnection, channel.offset, channel.size, channel.RemoteSecurity) { this.decoder = channel.decoder; this.contentType = this.decoder.ContentType; this.maxBufferSize = channel.channelListener.MaxBufferSize; this.bufferManager = channel.channelListener.BufferManager; this.messageEncoder = channel.MessageEncoder; this.rawConnection = channel.rawConnection; }
protected SingletonConnectionReader(Microsoft.ServiceBus.Channels.IConnection connection, int offset, int size, SecurityMessageProperty security, Microsoft.ServiceBus.Channels.IConnectionOrientedTransportFactorySettings transportSettings, Uri via) { this.connection = connection; this.offset = offset; this.size = size; this.security = security; this.transportSettings = transportSettings; this.via = via; }
private void OnConnectionAvailable(Microsoft.ServiceBus.Channels.IConnection connection, Action connectionDequeuedCallback) { Microsoft.ServiceBus.Channels.ConnectionModeReader connectionModeReader = this.SetupModeReader(connection, false); if (connectionModeReader == null) { connectionDequeuedCallback(); return; } connectionModeReader.StartReading(this.channelInitializationTimeout, connectionDequeuedCallback); }
public ServerSessionPreambleConnectionReader(Microsoft.ServiceBus.Channels.IConnection connection, Action connectionDequeuedCallback, long streamPosition, int offset, int size, Microsoft.ServiceBus.Channels.TransportSettingsCallback transportSettingsCallback, Microsoft.ServiceBus.Channels.ConnectionClosedCallback closedCallback, Microsoft.ServiceBus.Channels.ServerSessionPreambleCallback callback) : base(connection, closedCallback) { this.rawConnection = connection; this.decoder = new Microsoft.ServiceBus.Channels.ServerSessionDecoder(streamPosition, base.MaxViaSize, base.MaxContentTypeSize); this.offset = offset; this.size = size; this.transportSettingsCallback = transportSettingsCallback; this.callback = callback; base.ConnectionDequeuedCallback = connectionDequeuedCallback; }
private bool HandleEstablishConnection(IAsyncResult result) { this.connection = Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EndEstablishConnection(result); IAsyncResult asyncResult = Microsoft.ServiceBus.Channels.StreamingConnectionHelper.BeginWriteMessage(this.message, this.connection, true, this.channel.settings, ref this.timeoutHelper, Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel.StreamedFramingAsyncRequest.onWriteMessage, this); if (!asyncResult.CompletedSynchronously) { return(false); } return(this.HandleWriteMessage(asyncResult)); }
public static Microsoft.ServiceBus.Channels.IConnection UpgradeConnection(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts) { Microsoft.ServiceBus.Channels.ConnectionStream connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts); Stream stream = upgradeAcceptor.AcceptUpgrade(connectionStream); if (upgradeAcceptor is StreamSecurityUpgradeAcceptor && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.StreamSecurityUpgradeAccepted, new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null); } return(new Microsoft.ServiceBus.Channels.StreamConnection(stream, connectionStream)); }
protected SessionConnectionReader(Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.IConnection rawConnection, int offset, int size, SecurityMessageProperty security) { this.offset = offset; this.size = size; if (size > 0) { this.buffer = connection.AsyncReadBuffer; } this.connection = connection; this.rawConnection = rawConnection; this.onAsyncReadComplete = new WaitCallback(this.OnAsyncReadComplete); this.security = security; }
public void ReuseConnection(Microsoft.ServiceBus.Channels.IConnection connection, TimeSpan closeTimeout) { connection.ExceptionEventType = TraceEventType.Information; Microsoft.ServiceBus.Channels.ConnectionModeReader connectionModeReader = this.SetupModeReader(connection, true); if (connectionModeReader != null) { if (this.reuseConnectionCallback == null) { this.reuseConnectionCallback = new Action <object>(this.ReuseConnectionCallback); } IOThreadScheduler.ScheduleCallbackNoFlow(this.reuseConnectionCallback, new Microsoft.ServiceBus.Channels.ConnectionDemuxer.ReuseConnectionState(connectionModeReader, closeTimeout)); } }
public DecodeFailedUpgradeAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, Microsoft.ServiceBus.Channels.IConnection connection, Uri via, string contentType, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state) { Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateReadingFaultString(decoder); this.decoder = decoder; this.connection = connection; this.via = via; this.contentType = contentType; this.timeoutHelper = timeoutHelper; if (connection.BeginRead(0, Math.Min(256, connection.AsyncReadBufferSize), timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.DecodeFailedUpgradeAsyncResult.onReadFaultData, this) == AsyncReadResult.Queued) { return; } this.CompleteReadFaultData(); }
public InitiateUpgradeAsyncResult(IDefaultCommunicationTimeouts timeouts, EndpointAddress remoteAddress, Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, StreamUpgradeInitiator upgradeInitiator, string contentType, Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state) { this.defaultTimeouts = timeouts; this.decoder = decoder; this.upgradeInitiator = upgradeInitiator; this.contentType = contentType; this.timeoutHelper = timeoutHelper; this.connection = connection; this.remoteAddress = remoteAddress; if (this.Begin()) { base.Complete(true); } }
protected InitialServerConnectionReader(Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ConnectionClosedCallback closedCallback, int maxViaSize, int maxContentTypeSize) { if (connection == null) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("connection"); } if (closedCallback == null) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("closedCallback"); } this.connection = connection; this.closedCallback = closedCallback; this.maxContentTypeSize = maxContentTypeSize; this.maxViaSize = maxViaSize; }
public static bool InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, ref Microsoft.ServiceBus.Channels.IConnection connection, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper) { for (string i = upgradeInitiator.GetNextUpgrade(); i != null; i = upgradeInitiator.GetNextUpgrade()) { Microsoft.ServiceBus.Channels.EncodedUpgrade encodedUpgrade = new Microsoft.ServiceBus.Channels.EncodedUpgrade(i); connection.Write(encodedUpgrade.EncodedBytes, 0, (int)encodedUpgrade.EncodedBytes.Length, true, timeoutHelper.RemainingTime()); byte[] numArray = new byte[1]; if (!Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.ValidateUpgradeResponse(numArray, connection.Read(numArray, 0, (int)numArray.Length, timeoutHelper.RemainingTime()), decoder)) { return(false); } Microsoft.ServiceBus.Channels.ConnectionStream connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts); connection = new Microsoft.ServiceBus.Channels.StreamConnection(upgradeInitiator.InitiateUpgrade(connectionStream), connectionStream); } return(true); }
private void AcceptConnection(Microsoft.ServiceBus.Channels.IConnection connection) { MessagingClientEtwProvider.Provider.RelayChannelConnectionTransfer(base.Activity, connection.Activity); base.SetMessageSource(new Microsoft.ServiceBus.Channels.ClientDuplexConnectionReader(this, connection, this.decoder, this.settings, base.MessageEncoder)); lock (base.ThisLock) { if (base.State != CommunicationState.Opening) { ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility; string duplexChannelAbortedDuringOpen = Resources.DuplexChannelAbortedDuringOpen; object[] via = new object[] { this.Via }; throw exceptionUtility.ThrowHelperError(new CommunicationObjectAbortedException(Microsoft.ServiceBus.SR.GetString(duplexChannelAbortedDuringOpen, via))); } base.Connection = connection; } }
private int ReadCore(byte[] buffer, int offset, int size, TimeSpan timeout, bool closing) { int num = 0; Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); try { while (true) { try { num = this.readConnection.Read(buffer, offset, size, timeoutHelper.RemainingTime()); } catch (CommunicationException communicationException) { if (this.readConnectionQueue.Count == 0) { throw; } } if (num != 0 || this.readConnectionQueue.Count <= 0) { break; } if (this.role == HybridConnectionRole.Initiator) { this.readConnection.Close(timeoutHelper.RemainingTime()); } this.readConnection = this.readConnectionQueue.Dequeue(); if (this.role == HybridConnectionRole.Listener) { this.writeConnectionQueue.Enqueue(this.readConnection); } } } catch (ObjectDisposedException objectDisposedException1) { ObjectDisposedException objectDisposedException = objectDisposedException1; Exception exception = this.ConvertObjectDisposedException(objectDisposedException); if (!object.ReferenceEquals(exception, objectDisposedException)) { throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelper(exception, this.ExceptionEventType); } throw; } return(num); }
public SendPreambleAsyncResult(Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel channel, Microsoft.ServiceBus.Channels.IConnection connection, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, Microsoft.ServiceBus.Channels.ClientFramingDecoder decoder, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.connection = connection; this.timeoutHelper = timeoutHelper; this.decoder = decoder; IAsyncResult asyncResult = connection.BeginWrite(channel.Preamble, 0, (int)channel.Preamble.Length, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.StreamedFramingRequestChannel.StreamedConnectionPoolHelper.SendPreambleAsyncResult.onWritePreamble, this); if (!asyncResult.CompletedSynchronously) { return; } if (this.HandleWritePreamble(asyncResult)) { base.Complete(true); } }
public SendPreambleAsyncResult(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel channel, Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> preamble, ref Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeoutHelper = timeoutHelper; this.connection = connection; channel.decoder = new Microsoft.ServiceBus.Channels.ClientDuplexDecoder((long)0); IAsyncResult asyncResult = connection.BeginWrite(preamble.Array, preamble.Offset, preamble.Count, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onWritePreamble, this); if (!asyncResult.CompletedSynchronously) { return; } if (this.HandleWritePreamble(asyncResult)) { base.Complete(true); } }
public UpgradeConnectionAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state) : base(callback, state) { this.upgradeAcceptor = upgradeAcceptor; this.connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts); bool flag = false; IAsyncResult asyncResult = upgradeAcceptor.BeginAcceptUpgrade(this.connectionStream, Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnectionAsyncResult.onAcceptUpgrade, this); if (asyncResult.CompletedSynchronously) { this.CompleteAcceptUpgrade(asyncResult); flag = true; } if (flag) { base.Complete(true); } }
public static void WriteMessage(Message message, Microsoft.ServiceBus.Channels.IConnection connection, bool isRequest, Microsoft.ServiceBus.Channels.IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper) { bool flag; byte[] envelopeEndBytes = null; if (message != null) { MessageEncoder encoder = settings.MessageEncoderFactory.Encoder; byte[] envelopeStartBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeStartBytes; if (!isRequest) { envelopeEndBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeEndBytes; flag = Microsoft.ServiceBus.Channels.TransferModeHelper.IsResponseStreamed(settings.TransferMode); } else { envelopeEndBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeEndFramingEndBytes; flag = Microsoft.ServiceBus.Channels.TransferModeHelper.IsRequestStreamed(settings.TransferMode); } if (!flag) { ArraySegment <byte> nums = encoder.WriteMessage(message, 2147483647, settings.BufferManager, (int)envelopeStartBytes.Length + 5); nums = Microsoft.ServiceBus.Channels.SingletonEncoder.EncodeMessageFrame(nums); Buffer.BlockCopy(envelopeStartBytes, 0, nums.Array, nums.Offset - (int)envelopeStartBytes.Length, (int)envelopeStartBytes.Length); connection.Write(nums.Array, nums.Offset - (int)envelopeStartBytes.Length, nums.Count + (int)envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), settings.BufferManager); } else { connection.Write(envelopeStartBytes, 0, (int)envelopeStartBytes.Length, false, timeoutHelper.RemainingTime()); Microsoft.ServiceBus.Channels.StreamingConnectionHelper.StreamingOutputConnectionStream streamingOutputConnectionStream = new Microsoft.ServiceBus.Channels.StreamingConnectionHelper.StreamingOutputConnectionStream(connection, settings) { Immediate = !message.Properties.AllowOutputBatching }; encoder.WriteMessage(message, new Microsoft.ServiceBus.Channels.TimeoutStream(streamingOutputConnectionStream, ref timeoutHelper)); } } else if (isRequest) { envelopeEndBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EndBytes; } if (envelopeEndBytes != null) { connection.Write(envelopeEndBytes, 0, (int)envelopeEndBytes.Length, true, timeoutHelper.RemainingTime()); } }
public ServerFramingDuplexSessionChannel(Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelListener channelListener, Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader preambleReader, EndpointAddress localAddress, bool exposeConnectionProperty, Microsoft.ServiceBus.Channels.ConnectionDemuxer connectionDemuxer) : base(channelListener, localAddress, preambleReader.Via, exposeConnectionProperty) { this.channelListener = channelListener; this.connectionDemuxer = connectionDemuxer; base.Connection = preambleReader.Connection; this.decoder = preambleReader.Decoder; this.connectionBuffer = preambleReader.connectionBuffer; this.offset = preambleReader.BufferOffset; this.size = preambleReader.BufferSize; this.rawConnection = preambleReader.RawConnection; StreamUpgradeProvider upgrade = channelListener.Upgrade; if (upgrade != null) { this.upgradeAcceptor = upgrade.CreateUpgradeAcceptor(); } MessagingClientEtwProvider.Provider.RelayChannelConnectionTransfer(base.Activity, base.Connection.Activity); }
private void CompleteAcceptUpgrade(IAsyncResult result) { Stream stream; bool flag = false; try { stream = this.upgradeAcceptor.EndAcceptUpgrade(result); flag = true; } finally { if (this.upgradeAcceptor is StreamSecurityUpgradeAcceptor && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation && flag) { TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.StreamSecurityUpgradeAccepted, new StringTraceRecord("Type", this.upgradeAcceptor.GetType().ToString()), this, null); } } this.connection = new Microsoft.ServiceBus.Channels.StreamConnection(stream, this.connectionStream); }
private bool HandleUpgrade(IAsyncResult result) { this.connection = Microsoft.ServiceBus.Channels.ConnectionUpgradeHelper.EndInitiateUpgrade(result); this.channel.SetRemoteSecurity(this.upgradeInitiator); if (Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorClose == null) { Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorClose = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.OnUpgradeInitiatorClose)); } Type type = this.upgradeInitiator.GetType(); StreamUpgradeInitiator streamUpgradeInitiator = this.upgradeInitiator; object[] objArray = new object[] { this.timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.SendPreambleAsyncResult.onUpgradeInitiatorClose, this }; IAsyncResult asyncResult = InvokeHelper.InvokeInstanceMethod(type, streamUpgradeInitiator, "BeginClose", objArray) as IAsyncResult; if (!asyncResult.CompletedSynchronously) { return(false); } return(this.HandleInitiatorClose(asyncResult)); }
private void OnSingletonConnection(Microsoft.ServiceBus.Channels.IConnection connection, Action connectionDequeuedCallback, long streamPosition, int offset, int size, TimeSpan timeout) { if (this.onSingletonPreambleKnown == null) { this.onSingletonPreambleKnown = new Microsoft.ServiceBus.Channels.ServerSingletonPreambleCallback(this.OnSingletonPreambleKnown); } Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader = new Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader(connection, connectionDequeuedCallback, streamPosition, offset, size, this.transportSettingsCallback, this.onConnectionClosed, this.onSingletonPreambleKnown); lock (this.ThisLock) { if (!this.isClosed) { this.connectionReaders.Add(serverSingletonPreambleConnectionReader); } else { serverSingletonPreambleConnectionReader.Dispose(); return; } } serverSingletonPreambleConnectionReader.StartReading(this.viaDelegate, timeout); }