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); }
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); }