private void ReceiveComplete(IAsyncResult result, bool completedSynchronously)
                {
                    Message   message;
                    Exception exception = null;

                    try
                    {
                        bool flag = this.innerChannel.EndTryReceive(result, out message);
                        if (!flag || message == null || !(message.Headers.Action == "Ping"))
                        {
                            this.success = flag;
                            this.Message = message;
                        }
                        else
                        {
                            if (SocketConnectionChannelListener <TChannel, TChannelAcceptor> .DuplexSessionChannel.TryReceiveAsyncResult.receiveStatic == null)
                            {
                                SocketConnectionChannelListener <TChannel, TChannelAcceptor> .DuplexSessionChannel.TryReceiveAsyncResult.receiveStatic = new Action <object>(SocketConnectionChannelListener <TChannel, TChannelAcceptor> .DuplexSessionChannel.TryReceiveAsyncResult.ReceiveStatic);
                            }
                            IOThreadScheduler.ScheduleCallbackNoFlow(SocketConnectionChannelListener <TChannel, TChannelAcceptor> .DuplexSessionChannel.TryReceiveAsyncResult.receiveStatic, this);
                            return;
                        }
                    }
                    catch (Exception exception2)
                    {
                        Exception exception1 = exception2;
                        if (Fx.IsFatal(exception1))
                        {
                            throw;
                        }
                        exception = exception1;
                    }
                    base.Complete(completedSynchronously, exception);
                }
            private void StartBackgroundReceive()
            {
                if (receiveAsyncCallback == null)
                {
                    receiveAsyncCallback = Fx.ThunkCallback(new AsyncCallback(DuplexChannelBinder.AutoCloseDuplexSessionChannel.ReceiveAsyncCallback));
                }
                IAsyncResult state     = null;
                Exception    exception = null;

                try
                {
                    state = this.innerChannel.BeginReceive(TimeSpan.MaxValue, receiveAsyncCallback, this);
                }
                catch (Exception exception2)
                {
                    if (Fx.IsFatal(exception2))
                    {
                        throw;
                    }
                    exception = exception2;
                }
                if (exception != null)
                {
                    this.pendingMessages.EnqueueAndDispatch(exception, this.messageDequeuedCallback, false);
                }
                else if (state.CompletedSynchronously)
                {
                    if (receiveThreadSchedulerCallback == null)
                    {
                        receiveThreadSchedulerCallback = new Action <object>(DuplexChannelBinder.AutoCloseDuplexSessionChannel.ReceiveThreadSchedulerCallback);
                    }
                    IOThreadScheduler.ScheduleCallbackLowPriNoFlow(receiveThreadSchedulerCallback, state);
                }
            }
Exemplo n.º 3
0
 public void Connect(AddressCandidates addresses)
 {
     lock (base.ThisLock)
     {
         if (this.connecting)
         {
             throw new FaultException(SRClient.InvalidCallFaultException);
         }
         this.connecting = true;
     }
     try
     {
         this.localEndpoints = addresses.GetEndpoints(AddressType.Local);
         IPEndPoint endpoint = addresses.GetEndpoint(AddressType.External);
         this.ServerStartConnectingLocal(this.localEndpoints);
         this.ServerStartConnectingExternal(this.localDerivedEndpoint, endpoint);
         IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.SendResponse), null);
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.Failure(exception);
         throw new FaultException(exception.ToString());
     }
 }
Exemplo n.º 4
0
        private void AcceptComplete(IAsyncResult result, bool completedSynchronously)
        {
            IConnection connection;

            try
            {
                try
                {
                    connection = this.innerListener.EndAccept(result);
                    if (connection == null)
                    {
                        return;
                    }
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(DemuxSocketManager.StartAcceptingStatic), this);
                    return;
                }
                IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(DemuxSocketManager.StartAcceptingStatic), this);
                this.ProcessConnection(connection);
            }
            catch (Exception exception1)
            {
                if (Fx.IsFatal(exception1))
                {
                    throw;
                }
            }
        }
 private void ReScheduleIfNeeded(Exception exception)
 {
     if (this.ShouldGetEntityInfo(exception))
     {
         IOThreadScheduler.ScheduleCallbackNoFlow((object s) => (new GetRuntimeEntityDescriptionAsyncResult(this.trackingContext, this.clientEntity, this.entityAddress, this.factory, this.messageCreator, false, base.RemainingTime(), null, null)).Start(), null);
     }
 }
Exemplo n.º 6
0
        public HostedHttpRequestAsyncResult(HttpApplication context, string aspNetRouteServiceVirtualPath, bool flowContext, bool ensureWFService, AsyncCallback callback, object state) : base(callback, state)
        {
            if (context == null)
            {
                throw System.ServiceModel.Activation.FxTrace.Exception.ArgumentNull("context");
            }
            this.context     = context;
            this.flowContext = flowContext;
            if (ensureWFService)
            {
                if (ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.ensureWFService = false;
                }
                else
                {
                    this.ensureWFService = true;
                }
            }
            if (!string.IsNullOrEmpty(aspNetRouteServiceVirtualPath))
            {
                if (!RouteTable.Routes.RouteExistingFiles && ServiceHostingEnvironment.IsConfigurationBasedService(context, out this.configurationBasedServiceVirtualPath))
                {
                    this.AspNetRouteServiceVirtualPath = null;
                }
                else
                {
                    this.AspNetRouteServiceVirtualPath = aspNetRouteServiceVirtualPath;
                }
            }
            string strA = context.Request.HttpMethod ?? "";
            char   ch   = (strA.Length == 5) ? strA[0] : '\0';

            if (((ch == 'd') || (ch == 'D')) && (string.Compare(strA, "DEBUG", StringComparison.OrdinalIgnoreCase) == 0))
            {
                if (DiagnosticUtility.ShouldTraceVerbose)
                {
                    System.ServiceModel.Activation.Diagnostics.TraceUtility.TraceEvent(TraceEventType.Verbose, 0x90005, System.ServiceModel.Activation.SR.TraceCodeWebHostDebugRequest, this);
                }
                this.state = 1;
                base.Complete(true, null);
            }
            else
            {
                this.impersonationContext = new HostedImpersonationContext();
                if (flowContext && ServiceHostingEnvironment.AspNetCompatibilityEnabled)
                {
                    this.hostedThreadData = new System.ServiceModel.Activation.HostedThreadData();
                }
                Action <object> action = (AspNetPartialTrustHelpers.NeedPartialTrustInvoke || flowContext) ? WaitOnBeginRequestWithFlow : WaitOnBeginRequest;
                if (!ServiceHostingEnvironment.AspNetCompatibilityEnabled && !this.ensureWFService)
                {
                    context.CompleteRequest();
                }
                context.Server.ScriptTimeout = 0x7fffffff;
                ServiceHostingEnvironment.IncrementRequestCount();
                IOThreadScheduler.ScheduleCallbackLowPriNoFlow(action, this);
            }
        }
Exemplo n.º 7
0
 private void AcceptIfNecessary(bool startAccepting)
 {
     if (this.IsAcceptNecessary)
     {
         lock (this.ThisLock)
         {
             while (this.IsAcceptNecessary)
             {
                 IAsyncResult asyncResult = null;
                 Exception    exception   = null;
                 try
                 {
                     asyncResult = this.listener.BeginAccept(this.acceptCompletedCallback, null);
                 }
                 catch (CommunicationException communicationException1)
                 {
                     CommunicationException communicationException = communicationException1;
                     if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
                     {
                         Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.TraceHandledException(communicationException, TraceEventType.Information);
                     }
                 }
                 catch (Exception exception2)
                 {
                     Exception exception1 = exception2;
                     if (Fx.IsFatal(exception1))
                     {
                         throw;
                     }
                     if (startAccepting)
                     {
                         throw;
                     }
                     if (this.errorCallback == null && !ExceptionHandler.HandleTransportExceptionHelper(exception1))
                     {
                         throw;
                     }
                     exception = exception1;
                 }
                 if (exception != null && this.errorCallback != null)
                 {
                     this.errorCallback(exception);
                 }
                 if (asyncResult == null)
                 {
                     continue;
                 }
                 if (asyncResult.CompletedSynchronously)
                 {
                     IOThreadScheduler.ScheduleCallbackNoFlow(this.scheduleAcceptCallback, asyncResult);
                 }
                 ConnectionAcceptor connectionAcceptor = this;
                 connectionAcceptor.pendingAccepts = connectionAcceptor.pendingAccepts + 1;
             }
         }
     }
 }
Exemplo n.º 8
0
 private void HandleCancellation(bool scheduleComplete)
 {
     if (this.timer.Cancel())
     {
         if (scheduleComplete)
         {
             IOThreadScheduler.ScheduleCallbackNoFlow((object s) => ((IteratorAsyncResult <TIteratorAsyncResult> .SleepAsyncResult)s).Complete(false), this);
             return;
         }
         base.Complete(true);
     }
 }
 private void CompleteSingleOperation(BatchManager <TItem> .BatchedObjectsAsyncResult singleOperation, Exception delayedException)
 {
     if (delayedException != null)
     {
         this.completionException = delayedException;
         MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteBatchManagerException(this.TrackingContext.Activity, this.TrackingContext.TrackingId, this.TrackingContext.SystemTracker, "BatchManager.PerformFlushAsyncResult.CompleteSingleOperation", delayedException.ToStringSlim()));
     }
     IOThreadScheduler.ScheduleCallbackNoFlow((object s) => singleOperation.CompleteBatch(delayedException), null);
     if (Interlocked.Decrement(ref this.batchedResultsCount) == 0)
     {
         base.Complete(false, this.completionException);
     }
 }
Exemplo n.º 10
0
 private static void InvokeDequeuedCallback(Action dequeuedCallback, bool canDispatchOnThisThread)
 {
     if (canDispatchOnThisThread)
     {
         dequeuedCallback();
         return;
     }
     if (Microsoft.ServiceBus.Channels.SingletonChannelAcceptor <ChannelInterfaceType, TChannel, QueueItemType> .onInvokeDequeuedCallback == null)
     {
         Microsoft.ServiceBus.Channels.SingletonChannelAcceptor <ChannelInterfaceType, TChannel, QueueItemType> .onInvokeDequeuedCallback = new Action <object>(Microsoft.ServiceBus.Channels.SingletonChannelAcceptor <ChannelInterfaceType, TChannel, QueueItemType> .OnInvokeDequeuedCallback);
     }
     IOThreadScheduler.ScheduleCallbackNoFlow(Microsoft.ServiceBus.Channels.SingletonChannelAcceptor <ChannelInterfaceType, TChannel, QueueItemType> .onInvokeDequeuedCallback, dequeuedCallback);
 }
Exemplo n.º 11
0
 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));
     }
 }
Exemplo n.º 12
0
        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 ScheduleGetRuntimeEntityDescription(TrackingContext trackingContext, MessageClientEntity clientEntity, string entityName, SbmpMessageCreator messageCreator)
 {
     Microsoft.ServiceBus.Messaging.RuntimeEntityDescription runtimeEntityDescription;
     if (!this.Settings.GatewayMode && clientEntity.RuntimeEntityDescription == null && !this.Settings.EnableRedirect && base.IsOpened)
     {
         string str = string.Concat(this.BaseAddress.AbsoluteUri, entityName);
         if (RuntimeEntityDescriptionCache.TryGet(str, out runtimeEntityDescription))
         {
             clientEntity.RuntimeEntityDescription = runtimeEntityDescription;
             return;
         }
         IOThreadScheduler.ScheduleCallbackNoFlow((object s) => (new GetRuntimeEntityDescriptionAsyncResult(trackingContext, clientEntity, str, this, messageCreator, false, Constants.GetRuntimeEntityDescriptionTimeout, null, null)).Start(), null);
     }
 }
Exemplo n.º 14
0
 private bool ScheduleCompleteClose(bool isStillSynchronous)
 {
     if (!isStillSynchronous)
     {
         this.OnCompleteCloseScheduled();
         return(true);
     }
     if (Microsoft.ServiceBus.Channels.FramingDuplexSessionChannel.CloseAsyncResult.onCompleteCloseScheduled == null)
     {
         Microsoft.ServiceBus.Channels.FramingDuplexSessionChannel.CloseAsyncResult.onCompleteCloseScheduled = new Action <object>(Microsoft.ServiceBus.Channels.FramingDuplexSessionChannel.CloseAsyncResult.OnCompleteCloseScheduled);
     }
     IOThreadScheduler.ScheduleCallbackNoFlow(Microsoft.ServiceBus.Channels.FramingDuplexSessionChannel.CloseAsyncResult.onCompleteCloseScheduled, this);
     return(false);
 }
Exemplo n.º 15
0
            private bool ContinueOperation(Exception delayedException, IList <BatchManager <TItem> .BatchedObjectsAsyncResult> batchedObjectsAsyncResults)
            {
                if (delayedException != null)
                {
                    MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteBatchManagerException(this.TrackingContext.Activity, this.TrackingContext.TrackingId, this.TrackingContext.SystemTracker, "BatchManager.PerformFlushAsyncResult.ContinueOperation", delayedException.ToStringSlim()));
                }
                if (this.isInTransaction || delayedException == null || delayedException is CommunicationObjectFaultedException)
                {
                    ExceptionInfo exceptionInfo = new ExceptionInfo(delayedException);
                    foreach (BatchManager <TItem> .BatchedObjectsAsyncResult batchedObjectsAsyncResult in batchedObjectsAsyncResults)
                    {
                        IOThreadScheduler.ScheduleCallbackNoFlow((object s) => ((BatchManager <TItem> .BatchedObjectsAsyncResult)s).CompleteBatch(exceptionInfo.CreateException()), batchedObjectsAsyncResult);
                    }
                    return(false);
                }
                int  count = batchedObjectsAsyncResults.Count;
                bool flag  = count > 1;

                Interlocked.Add(ref this.batchedResultsCount, count);
                foreach (BatchManager <TItem> .BatchedObjectsAsyncResult batchedObjectsAsyncResult1 in batchedObjectsAsyncResults)
                {
                    if (!this.ShouldRetry(delayedException, batchedObjectsAsyncResult1, flag))
                    {
                        this.CompleteSingleOperation(batchedObjectsAsyncResult1, delayedException);
                    }
                    else
                    {
                        try
                        {
                            IAsyncResult batchedBegin = this.BatchManager.BatchedBegin(this.TrackingContext, batchedObjectsAsyncResult1.BatchedObjects, this.transactionId, this.timeout, BatchManager <TItem> .PerformFlushAsyncResult.singleOperationCompleteCallback, new Tuple <BatchManager <TItem> .PerformFlushAsyncResult, BatchManager <TItem> .BatchedObjectsAsyncResult>(this, batchedObjectsAsyncResult1));
                            if (batchedBegin.CompletedSynchronously)
                            {
                                this.OnSingleOperationCompleted(batchedBegin);
                            }
                        }
                        catch (Exception exception1)
                        {
                            Exception exception = exception1;
                            if (Fx.IsFatal(exception))
                            {
                                throw;
                            }
                            this.CompleteSingleOperation(batchedObjectsAsyncResult1, exception);
                        }
                    }
                }
                return(true);
            }
Exemplo n.º 16
0
            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);
            }
Exemplo n.º 17
0
            public override void ConnectResponse(ConnectResponseMessage request)
            {
                Exception  exception;
                IPEndPoint endpoint = request.Addresses.GetEndpoint(AddressType.External);

                if (!this.ClientStartConnecting(ref this.localDerivedEndpoint.LocalEndpoint, endpoint, out exception))
                {
                    SocketException socketException = exception as SocketException;
                    if (socketException != null && socketException.ErrorCode == 10048)
                    {
                        this.localListener.Dispose();
                        this.ClientStartConnecting(ref this.localDerivedEndpoint.LocalEndpoint, endpoint, out exception);
                    }
                }
                IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.WaitForTimeout), null);
            }
Exemplo n.º 18
0
 protected override void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         this.disposed = true;
         try
         {
             if (disposing)
             {
                 if (this.pump != null)
                 {
                     this.pump.Dispose();
                     this.pump = null;
                 }
                 if (this.outputStream != null)
                 {
                     this.outputStream.Close();
                     this.outputStream = null;
                 }
                 if (this.inputStream != null)
                 {
                     Stream stream = this.inputStream;
                     IOThreadScheduler.ScheduleCallbackNoFlow((object o) => {
                         try
                         {
                             ((Stream)o).Close();
                         }
                         catch (Exception exception1)
                         {
                             Exception exception = exception1;
                             if (Fx.IsFatal(exception))
                             {
                                 throw;
                             }
                             Fx.Exception.TraceHandled(exception, "PumpStream.Dispose", null);
                         }
                     }, stream);
                     this.inputStream = null;
                 }
             }
         }
         finally
         {
             base.Dispose(disposing);
         }
     }
 }
Exemplo n.º 19
0
        private static void SignalPendingOperations(int key)
        {
            List <AsyncWaiter> asyncWaiters;

            lock (Microsoft.ServiceBus.Messaging.NetworkDetector.ThisLock)
            {
                if (Microsoft.ServiceBus.Messaging.NetworkDetector.pendingOperations.TryGetValue(key, out asyncWaiters))
                {
                    Microsoft.ServiceBus.Messaging.NetworkDetector.pendingOperations.Remove(key);
                }
            }
            if (asyncWaiters != null)
            {
                foreach (AsyncWaiter asyncWaiter in asyncWaiters)
                {
                    IOThreadScheduler.ScheduleCallbackNoFlow((object state) => ((AsyncWaiter)state).Signal(), asyncWaiter);
                }
            }
        }
 private void AcceptComplete(IAsyncResult result, bool completedSynchronously)
 {
     Microsoft.ServiceBus.Channels.IConnection connection;
     try
     {
         try
         {
             connection = this.socketListener.EndAccept(result);
             if (connection == null)
             {
                 return;
             }
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(HybridConnectionListener.ConnectionAcceptor.StartAcceptingStatic), this);
             return;
         }
         try
         {
             this.ProcessConnection(connection);
         }
         catch (Exception exception1)
         {
             if (Fx.IsFatal(exception1))
             {
                 throw;
             }
         }
         IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(HybridConnectionListener.ConnectionAcceptor.StartAcceptingStatic), this);
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
     }
 }
 public CloseAsyncResult(Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelFactory <TChannel> parent, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.parent        = parent;
     this.timeoutHelper = new TimeoutHelper(timeout);
     this.parent.GetUpgradeAndConnectionPool(out this.upgradeProvider, out this.connectionPool);
     if (this.connectionPool != null)
     {
         if (Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelFactory <TChannel> .CloseAsyncResult.onReleaseConnectionPoolScheduled == null)
         {
             Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelFactory <TChannel> .CloseAsyncResult.onReleaseConnectionPoolScheduled = new Action <object>(Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelFactory <TChannel> .CloseAsyncResult.OnReleaseConnectionPoolScheduled);
         }
         IOThreadScheduler.ScheduleCallbackNoFlow(Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelFactory <TChannel> .CloseAsyncResult.onReleaseConnectionPoolScheduled, this);
     }
     else if (this.HandleReleaseConnectionPoolComplete())
     {
         base.Complete(true);
         return;
     }
 }
Exemplo n.º 22
0
            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);
            }
Exemplo n.º 23
0
        private void SignalPendingOperations(TKey key)
        {
            List <AsyncWaiter> asyncWaiters;

            lock (base.ThisLock)
            {
                if (this.pendingOperations.TryGetValue(key, out asyncWaiters))
                {
                    this.pendingOperations.Remove(key);
                }
            }
            if (asyncWaiters != null)
            {
                foreach (AsyncWaiter asyncWaiter in asyncWaiters)
                {
                    IOThreadScheduler.ScheduleCallbackNoFlow((object state) => ((AsyncWaiter)state).Signal(), asyncWaiter);
                }
            }
        }
Exemplo n.º 24
0
 private void ScheduleMessageCompletion(BrokeredMessage message, TrackingContext trackingContext)
 {
     MessageReceivePump.BatchCompleteAsyncResult batchCompleteAsyncResult = null;
     lock (this.completionList)
     {
         if (message != null)
         {
             this.completionList.Add(message.LockToken);
         }
         if (!this.completionInProgress && this.completionList.Count > 0)
         {
             this.completionInProgress = true;
             batchCompleteAsyncResult  = new MessageReceivePump.BatchCompleteAsyncResult(this, trackingContext, MessageReceivePump.MessageCompletionOperationTimeout, new AsyncCallback(MessageReceivePump.OnCompleteMessageCompletion), null);
         }
     }
     if (batchCompleteAsyncResult != null)
     {
         IOThreadScheduler.ScheduleCallbackNoFlow((object o) => ((MessageReceivePump.BatchCompleteAsyncResult)o).Start(), batchCompleteAsyncResult);
     }
 }
Exemplo n.º 25
0
            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);
            }
Exemplo n.º 26
0
            protected override IEnumerator <IteratorAsyncResult <WebStreamOnewayConnectionInitiator.ConnectAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                if (base.RemainingTime() > TimeSpan.Zero)
                {
                    IOThreadScheduler.ScheduleCallbackNoFlow((object s) => {
                        WebStreamOnewayConnectionInitiator.ConnectAsyncResult webStreamConnection = (WebStreamOnewayConnectionInitiator.ConnectAsyncResult)s;
                        try
                        {
                            try
                            {
                                webStreamConnection.webStream.Open();
                                webStreamConnection.Connection = new WebStreamConnection(webStreamConnection.address, webStreamConnection.initiator.bufferSize, webStreamConnection.activity, webStreamConnection.webStream, webStreamConnection.address);
                            }
                            catch (Exception exception)
                            {
                                webStreamConnection.CompleteException = exception;
                            }
                        }
                        finally
                        {
                            webStreamConnection.asyncWaitHandle.Set();
                        }
                    }, this);
                    WebStreamOnewayConnectionInitiator.ConnectAsyncResult connectAsyncResult = this;
                    IteratorAsyncResult <WebStreamOnewayConnectionInitiator.ConnectAsyncResult> .BeginCall beginCall = (WebStreamOnewayConnectionInitiator.ConnectAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.asyncWaitHandle.BeginWait(thisPtr.activity, t, c, s);
                    yield return(connectAsyncResult.CallAsync(beginCall, (WebStreamOnewayConnectionInitiator.ConnectAsyncResult thisPtr, IAsyncResult r) => thisPtr.asyncWaitHandle.EndWait(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Continue));

                    if (base.LastAsyncStepException != null && this.Connection == null)
                    {
                        this.CompleteException = new TimeoutException(SRClient.OperationRequestTimedOut(base.OriginalTimeout), base.LastAsyncStepException);
                    }
                    this.Finally();
                }
                else
                {
                    base.Complete(new TimeoutException(SRClient.OperationRequestTimedOut(base.OriginalTimeout)));
                }
            }
 public ReceiveAsyncResult(Microsoft.ServiceBus.Channels.SingletonConnectionReader parent, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.parent  = parent;
     this.timeout = timeout;
     IOThreadScheduler.ScheduleCallbackNoFlow(Microsoft.ServiceBus.Channels.SingletonConnectionReader.ReceiveAsyncResult.onReceiveScheduled, this);
 }
 protected void Begin()
 {
     IOThreadScheduler.ScheduleCallbackNoFlow(TransportManagerContainer.OpenOrCloseAsyncResult.scheduledCallback, this);
 }
Exemplo n.º 29
0
 public SyncCallbackAsyncResult(MessageReceivePump owner, BrokeredMessage message, AsyncCallback callback, object state) : base(callback, state)
 {
     this.owner   = owner;
     this.message = message;
     IOThreadScheduler.ScheduleCallbackNoFlow(MessageReceivePump.SyncCallbackAsyncResult.executeSyncCallback, this);
 }
            public WriteMessageAsyncResult(Message message, Microsoft.ServiceBus.Channels.IConnection connection, bool isRequest, Microsoft.ServiceBus.Channels.IConnectionOrientedTransportFactorySettings settings, ref TimeoutHelper timeoutHelper, AsyncCallback callback, object state) : base(callback, state)
            {
                bool flag;

                this.connection    = connection;
                this.encoder       = settings.MessageEncoderFactory.Encoder;
                this.bufferManager = settings.BufferManager;
                this.timeoutHelper = timeoutHelper;
                this.message       = message;
                this.settings      = settings;
                bool flag1 = true;
                bool flag2 = false;

                if (message != null)
                {
                    try
                    {
                        byte[] envelopeStartBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeStartBytes;
                        if (!isRequest)
                        {
                            this.endBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeEndBytes;
                            flag          = Microsoft.ServiceBus.Channels.TransferModeHelper.IsResponseStreamed(settings.TransferMode);
                        }
                        else
                        {
                            this.endBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EnvelopeEndFramingEndBytes;
                            flag          = Microsoft.ServiceBus.Channels.TransferModeHelper.IsRequestStreamed(settings.TransferMode);
                        }
                        if (!flag)
                        {
                            ArraySegment <byte> nums = settings.MessageEncoderFactory.Encoder.WriteMessage(message, 2147483647, this.bufferManager, (int)envelopeStartBytes.Length + 5);
                            nums = Microsoft.ServiceBus.Channels.SingletonEncoder.EncodeMessageFrame(nums);
                            this.bufferToFree = nums.Array;
                            Buffer.BlockCopy(envelopeStartBytes, 0, nums.Array, nums.Offset - (int)envelopeStartBytes.Length, (int)envelopeStartBytes.Length);
                            if (Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteBufferedMessage == null)
                            {
                                Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteBufferedMessage = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.OnWriteBufferedMessage));
                            }
                            IAsyncResult asyncResult = connection.BeginWrite(nums.Array, nums.Offset - (int)envelopeStartBytes.Length, nums.Count + (int)envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteBufferedMessage, this);
                            if (asyncResult.CompletedSynchronously)
                            {
                                flag2 = this.HandleWriteBufferedMessage(asyncResult);
                            }
                        }
                        else
                        {
                            if (Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteStartBytes == null)
                            {
                                Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteStartBytes = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ThunkAsyncCallback(new AsyncCallback(Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.OnWriteStartBytes));
                            }
                            IAsyncResult asyncResult1 = connection.BeginWrite(envelopeStartBytes, 0, (int)envelopeStartBytes.Length, true, timeoutHelper.RemainingTime(), Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteStartBytes, this);
                            if (asyncResult1.CompletedSynchronously)
                            {
                                if (Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteStartBytesScheduled == null)
                                {
                                    Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteStartBytesScheduled = new Action <object>(Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.OnWriteStartBytesScheduled);
                                }
                                IOThreadScheduler.ScheduleCallbackNoFlow(Microsoft.ServiceBus.Channels.StreamingConnectionHelper.WriteMessageAsyncResult.onWriteStartBytesScheduled, asyncResult1);
                            }
                        }
                        flag1 = false;
                    }
                    finally
                    {
                        if (flag1)
                        {
                            this.Cleanup();
                        }
                    }
                }
                else
                {
                    if (isRequest)
                    {
                        this.endBytes = Microsoft.ServiceBus.Channels.SingletonEncoder.EndBytes;
                    }
                    flag2 = this.WriteEndBytes();
                }
                if (flag2)
                {
                    base.Complete(true);
                }
            }