private void ProcessConnection(Microsoft.ServiceBus.Channels.IConnection connection) { TimeoutHelper timeoutHelper = new TimeoutHelper(Microsoft.ServiceBus.ServiceDefaults.ReceiveTimeout); bool flag = false; try { byte[] numArray = new byte[16]; if (connection.Read(numArray, 0, 16, timeoutHelper.RemainingTime()) != 16) { throw new CommunicationException(SRClient.InvalidLengthofReceivedContent); } Guid guid = new Guid(numArray); this.connectionListener.EnqueueConnection(guid, connection, this.socketType, new Action(this.OnSocketDequeued)); byte[] numArray1 = new byte[] { 1 }; connection.Write(numArray1, 0, 1, true, timeoutHelper.RemainingTime()); flag = true; } finally { if (!flag) { connection.Abort(); } } }
public Microsoft.ServiceBus.Channels.IConnection Connect() { Microsoft.ServiceBus.Channels.IConnection connection; try { IDirectConnectionControl directConnectionControl = this.channelFactory.CreateChannel(); ((IChannel)directConnectionControl).Open(); this.session.Channel = directConnectionControl; this.session.Initiate(); Microsoft.ServiceBus.Channels.IConnection connection1 = this.Wait(); this.session.Close(this.timeoutHelper.RemainingTime()); try { this.channelFactory.Close(this.timeoutHelper.RemainingTime()); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } Fx.Exception.TraceHandled(exception, "DirectSocketInitiator.DirectConnectWaiter.Connect", this.Activity); } connection = connection1; } finally { this.channelFactory.Abort(); } return(connection); }
public void SendMessage(Microsoft.ServiceBus.Channels.IConnection connection, Message message, TimeSpan timeout) { ArraySegment <byte> nums = this.MessageEncoder.WriteMessage(message, 65536, this.SendBufferManager); SocketMessageHelper.SendMessageAsyncResult sendMessageAsyncResult = new SocketMessageHelper.SendMessageAsyncResult(connection, nums, timeout, null, null); sendMessageAsyncResult.RunSynchronously(); }
public ReadBytesAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, int requestedCount, bool throwIfNotAllRead, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.connection = connection; this.requestedCount = requestedCount; this.throwIfNotAllRead = throwIfNotAllRead; this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout); if (this.BeginRead() == AsyncReadResult.Completed) { this.ReadComplete(true); } }
public void Success(object sender, Microsoft.ServiceBus.Channels.IConnection connection) { RelayedConnectionSession relayedConnectionSession = (RelayedConnectionSession)sender; MessagingClientEtwProvider.Provider.RelayListenerClientAccepted(relayedConnectionSession.Activity, this.uri.AbsoluteUri, relayedConnectionSession.Id.ToString()); lock (this.ThisLock) { this.connectionSessions.Remove(relayedConnectionSession.Id.ToString()); } this.socketQueue.EnqueueAndDispatch(connection); relayedConnectionSession.Close(); }
public Microsoft.ServiceBus.Channels.IConnection Connect(Uri uri, TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); Microsoft.ServiceBus.Channels.IConnection connection = this.relayedSocketInitiator.Connect(uri, timeoutHelper.RemainingTime()); this.SendInitiateMessage(connection, timeoutHelper.RemainingTime()); HybridConnectionInitiator.DirectSocketClient directSocketClient = new HybridConnectionInitiator.DirectSocketClient(this, this.directSocketInitiator, uri, timeoutHelper.RemainingTime()); HybridConnection hybridConnection = new HybridConnection(HybridConnectionRole.Initiator, connection, directSocketClient, this.bufferSize); directSocketClient.HybridConnection = hybridConnection; IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.StartDirectConnect), directSocketClient); return(hybridConnection); }
public void Success(object sender, Microsoft.ServiceBus.Channels.IConnection connection) { lock (this.ThisLock) { if (!this.complete) { this.complete = true; } else { connection.Close(TimeSpan.FromSeconds(1)); return; } } this.listener.Success(this, connection); }
protected override IEnumerator <IteratorAsyncResult <WebSocketRelayedConnectionListener.ConnectAsyncResult> .AsyncStep> GetAsyncSteps() { Uri uri = ServiceBusUriHelper.CreateServiceUri(Uri.UriSchemeHttps, this.Request.HttpsEndpoint.ToString(), "/"); ServiceBusClientWebSocket serviceBusClientWebSocket = new ServiceBusClientWebSocket("wsrelayedconnection"); yield return(base.CallAsync((WebSocketRelayedConnectionListener.ConnectAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => serviceBusClientWebSocket.BeginConnect(uri.Host, uri.Port, ConnectConstants.ConnectionInitiateTimeout, c, s), (WebSocketRelayedConnectionListener.ConnectAsyncResult thisPtr, IAsyncResult r) => serviceBusClientWebSocket.EndConnect(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.connection = new ClientWebSocketConnection(serviceBusClientWebSocket, this.relayedConnectionListener.bufferSize, this.relayedConnectionListener.uri, this.Activity); this.message = Message.CreateMessage(this.relayedConnectionListener.messageHelper.MessageVersion, "RelayedAccept", new AcceptMessage(this.Request.Id)); this.message.Headers.To = EndpointAddress.AnonymousUri; WebSocketRelayedConnectionListener.ConnectAsyncResult connectAsyncResult = this; IteratorAsyncResult <WebSocketRelayedConnectionListener.ConnectAsyncResult> .BeginCall beginCall = (WebSocketRelayedConnectionListener.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.relayedConnectionListener.messageHelper.BeginSendMessage(thisRef.connection, thisRef.message, t, c, s); yield return(connectAsyncResult.CallAsync(beginCall, (WebSocketRelayedConnectionListener.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.relayedConnectionListener.messageHelper.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.relayedConnectionListener.BeginConnectCallback), this.connection); }
public void Success(object sender, Socket socket) { lock (base.ThisLock) { if (!this.complete) { this.complete = true; this.Cleanup(); this.socket = socket; } else { socket.Close(); return; } } this.Connection = new Microsoft.ServiceBus.Channels.SocketConnection(this.socket, this.bufferSize, this.Activity); base.Complete(false); }
private void SendInitiateMessage(Microsoft.ServiceBus.Channels.IConnection connection, TimeSpan timeout) { try { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); byte[] byteArray = this.connectionId.ToByteArray(); connection.Write(byteArray, 0, (int)byteArray.Length, true, timeoutHelper.RemainingTime()); byte[] numArray = new byte[1]; if (connection.Read(numArray, 0, 1, timeoutHelper.RemainingTime()) < 1 || numArray[0] != 1) { throw new CommunicationException(SRClient.InvalidReceivedContent); } } catch { connection.Close(TimeSpan.Zero); throw; } }
protected override IEnumerator <IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .AsyncStep> GetAsyncSteps() { this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); RelayedConnectionSession.ConnectAsyncResult connectAsyncResult = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.socket.BeginConnect(thisRef.request.IpEndpoint, c, s); yield return(connectAsyncResult.CallAsync(beginCall, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.socket.EndConnect(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.connection = new Microsoft.ServiceBus.Channels.SocketConnection(this.socket, this.RelayedConnectionSession.bufferSize, this.Activity); this.typeBytes = Encoding.UTF8.GetBytes(ConnectConstants.ConnectType); this.typeLengthBytes = BitConverter.GetBytes((int)this.typeBytes.Length); RelayedConnectionSession.ConnectAsyncResult connectAsyncResult1 = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall1 = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.connection.BeginWrite(thisRef.typeLengthBytes, 0, (int)thisRef.typeLengthBytes.Length, true, t, c, s); yield return(connectAsyncResult1.CallAsync(beginCall1, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection.EndWrite(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); RelayedConnectionSession.ConnectAsyncResult connectAsyncResult2 = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall2 = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.connection.BeginWrite(thisRef.typeBytes, 0, (int)thisRef.typeBytes.Length, true, t, c, s); yield return(connectAsyncResult2.CallAsync(beginCall2, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection.EndWrite(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); string str = string.Concat("sb://", this.request.IpEndpoint, "/"); this.via = new Uri(str); this.viaBytes = Encoding.UTF8.GetBytes(this.via.ToString()); this.viaLengthBytes = BitConverter.GetBytes((int)this.viaBytes.Length); RelayedConnectionSession.ConnectAsyncResult connectAsyncResult3 = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall3 = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.connection.BeginWrite(thisRef.viaLengthBytes, 0, (int)thisRef.viaLengthBytes.Length, true, t, c, s); yield return(connectAsyncResult3.CallAsync(beginCall3, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection.EndWrite(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); RelayedConnectionSession.ConnectAsyncResult connectAsyncResult4 = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall4 = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.connection.BeginWrite(thisRef.viaBytes, 0, (int)thisRef.viaBytes.Length, true, t, c, s); yield return(connectAsyncResult4.CallAsync(beginCall4, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection.EndWrite(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); RelayedConnectionSession.ConnectAsyncResult connectAsyncResult5 = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall5 = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => SecureSocketUtil.BeginInitiateSecureClientUpgradeIfNeeded(thisRef.connection, null, thisRef.RelayedConnectionSession.socketSecurityMode, thisRef.RelayedConnectionSession.uri.Host, t, c, s); yield return(connectAsyncResult5.CallAsync(beginCall5, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection = SecureSocketUtil.EndInitiateSecureClientUpgradeIfNeeded(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.message = Message.CreateMessage(this.RelayedConnectionSession.messageHelper.MessageVersion, "RelayedAccept", new AcceptMessage(this.RelayedConnectionSession.id.ToString())); this.message.Headers.To = EndpointAddress.AnonymousUri; RelayedConnectionSession.ConnectAsyncResult connectAsyncResult6 = this; IteratorAsyncResult <RelayedConnectionSession.ConnectAsyncResult> .BeginCall beginCall6 = (RelayedConnectionSession.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.RelayedConnectionSession.messageHelper.BeginSendMessage(thisRef.connection, thisRef.message, t, c, s); yield return(connectAsyncResult6.CallAsync(beginCall6, (RelayedConnectionSession.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.RelayedConnectionSession.messageHelper.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.RelayedConnectionSession.BeginConnectCallback), this.connection); }
protected override IEnumerator <IteratorAsyncResult <WebStreamRelayedConnectionListener.ConnectAsyncResult> .AsyncStep> GetAsyncSteps() { Uri uri; uri = (!this.relayedConnectionListener.useHttpsMode ? ServiceBusUriHelper.CreateServiceUri(Uri.UriSchemeHttp, this.Request.HttpEndpoint.ToString(), "/") : ServiceBusUriHelper.CreateServiceUri(Uri.UriSchemeHttps, this.Request.HttpsEndpoint.ToString(), "/")); WebStream webStream = (new WebStream(uri, "connection", this.relayedConnectionListener.useHttpsMode, this.Activity, this.relayedConnectionListener.uri)).Open(); this.connection = new WebStreamConnection(uri, this.relayedConnectionListener.bufferSize, this.Activity, webStream, this.relayedConnectionListener.uri); WebStreamRelayedConnectionListener.ConnectAsyncResult connectAsyncResult = this; IteratorAsyncResult <WebStreamRelayedConnectionListener.ConnectAsyncResult> .BeginCall beginCall = (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => SecureSocketUtil.BeginInitiateSecureClientUpgradeIfNeeded(thisRef.connection, null, thisRef.relayedConnectionListener.socketSecurityMode, thisRef.relayedConnectionListener.uri.Host, t, c, s); yield return(connectAsyncResult.CallAsync(beginCall, (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection = SecureSocketUtil.EndInitiateSecureClientUpgradeIfNeeded(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.message = Message.CreateMessage(this.relayedConnectionListener.messageHelper.MessageVersion, "RelayedAccept", new AcceptMessage(this.Request.Id)); this.message.Headers.To = EndpointAddress.AnonymousUri; WebStreamRelayedConnectionListener.ConnectAsyncResult connectAsyncResult1 = this; IteratorAsyncResult <WebStreamRelayedConnectionListener.ConnectAsyncResult> .BeginCall beginCall1 = (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.relayedConnectionListener.messageHelper.BeginSendMessage(thisRef.connection, thisRef.message, t, c, s); yield return(connectAsyncResult1.CallAsync(beginCall1, (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.relayedConnectionListener.messageHelper.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.relayedConnectionListener.BeginConnectCallback), this.connection); }
private void DirectConnectComplete(IAsyncResult result, bool completedSynchronously) { try { Microsoft.ServiceBus.Channels.IConnection connection = this.directSocketInitiator.EndConnect(result); if (!this.disposed) { this.hybridConnectionInitiator.SendInitiateMessage(connection, this.timeout.RemainingTime()); this.HybridConnection.EnqueueConnection(connection); } else { connection.Abort(); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } } }
private void EndConnectCallback(IAsyncResult ar) { try { Microsoft.ServiceBus.Channels.IConnection asyncState = (Microsoft.ServiceBus.Channels.IConnection)ar.AsyncState; Message message = this.messageHelper.EndReceiveMessage(ar); if (message.IsFault) { MessageFault messageFault = MessageFault.CreateFault(message, 65536); throw Fx.Exception.AsError(ErrorUtility.ConvertToError(messageFault), null); } base.EnqueueConnection(asyncState, false); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } Fx.Exception.TraceHandled(exception, "WebSocketRelayedConnectionListener.EndConnectCallback", null); } }
private void EndConnectCallback(IAsyncResult ar) { Microsoft.ServiceBus.Channels.IConnection asyncState = (Microsoft.ServiceBus.Channels.IConnection)ar.AsyncState; try { Message message = this.messageHelper.EndReceiveMessage(ar); if (message.IsFault) { throw ErrorUtility.ConvertToError(MessageFault.CreateFault(message, 65536)); } this.listener.Success(this, asyncState); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } asyncState.Abort(); this.listener.Failure(this, exception); } }
private void EnqueueConnection(Guid connectionId, Microsoft.ServiceBus.Channels.IConnection connection, HybridConnectionListener.HybridConnectionSocketType socketType, Action dequeuedCallback) { HybridConnection hybridConnection; bool flag = false; try { lock (this.connectionTable) { if (this.connectionTable.TryGetValue(connectionId, out hybridConnection)) { hybridConnection.EnqueueConnection(connection); } else if (socketType != HybridConnectionListener.HybridConnectionSocketType.Direct) { hybridConnection = new HybridConnection(HybridConnectionRole.Listener, connection, null, this.bufferSize); hybridConnection.Closed += new EventHandler((object o, EventArgs e) => this.connectionTable.Remove(connectionId)); flag = true; this.connectionTable.Add(connectionId, hybridConnection); } else { connection.Abort(); return; } } if (flag) { this.connectionQueue.EnqueueAndDispatch(hybridConnection); } } finally { dequeuedCallback(); } }
public void SendMessage(Microsoft.ServiceBus.Channels.IConnection connection, Message message) { this.SendMessage(connection, message, TimeSpan.MaxValue); }
public Message ReceiveMessage(Microsoft.ServiceBus.Channels.IConnection connection, TimeSpan timeout) { SocketMessageHelper.ReceiveMessageAsyncResult receiveMessageAsyncResult = new SocketMessageHelper.ReceiveMessageAsyncResult(this, connection, timeout, null, null); receiveMessageAsyncResult.RunSynchronously(); return(receiveMessageAsyncResult.Message); }
public IAsyncResult BeginSendMessage(Microsoft.ServiceBus.Channels.IConnection connection, Message message, TimeSpan timeout, AsyncCallback callback, object state) { ArraySegment <byte> nums = this.MessageEncoder.WriteMessage(message, 65536, this.SendBufferManager); return((new SocketMessageHelper.SendMessageAsyncResult(connection, nums, timeout, callback, state)).Start()); }
public IAsyncResult BeginReceiveMessage(Microsoft.ServiceBus.Channels.IConnection connection, TimeSpan timeout, AsyncCallback callback, object state) { SocketMessageHelper.ReceiveMessageAsyncResult receiveMessageAsyncResult = new SocketMessageHelper.ReceiveMessageAsyncResult(this, connection, timeout, callback, state); receiveMessageAsyncResult.Start(); return(receiveMessageAsyncResult); }
public IAsyncResult BeginReceiveBytes(Microsoft.ServiceBus.Channels.IConnection connection, int size, TimeSpan timeout, AsyncCallback callback, object state) { return((new SocketMessageHelper.ReceiveBytesAsyncResult(connection, size, timeout, callback, state)).Start()); }
public SendMessageAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, ArraySegment <byte> messageBytes, TimeSpan timeout, AsyncCallback callback, object state) : base(timeout, callback, state) { this.connection = connection; this.messageBytes = messageBytes; }
public ReceiveMessageAsyncResult(SocketMessageHelper messageHelper, Microsoft.ServiceBus.Channels.IConnection connection, TimeSpan timeout, AsyncCallback callback, object state) : base(timeout, callback, state) { this.messageHelper = messageHelper; this.Connection = connection; }
public ReceiveBytesAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, int size, TimeSpan timeout, AsyncCallback callback, object state) : base(timeout, callback, state) { this.connection = connection; this.size = size; }
private void BeginConnectCallback(object state) { Microsoft.ServiceBus.Channels.IConnection connection = (Microsoft.ServiceBus.Channels.IConnection)state; this.messageHelper.BeginReceiveMessage(connection, ConnectConstants.ConnectionInitiateTimeout, new AsyncCallback(this.EndConnectCallback), connection); }
private void BeginConnectCallback(object state) { Microsoft.ServiceBus.Channels.IConnection connection = (Microsoft.ServiceBus.Channels.IConnection)state; this.messageHelper.BeginReceiveMessage(connection, TimeSpan.MaxValue, new AsyncCallback(this.EndConnectCallback), connection); }