Exemplo n.º 1
0
        private void Abort(TraceEventType traceEventType, string timeoutErrorString)
        {
            Microsoft.ServiceBus.Channels.IConnection[] array;
            Microsoft.ServiceBus.Channels.IConnection[] connectionArray;
            lock (this.ThisLock)
            {
                if (this.closeState != HybridConnection.CloseState.Closed)
                {
                    this.timeoutErrorString = timeoutErrorString;
                    this.aborted            = true;
                    this.closeState         = HybridConnection.CloseState.Closed;
                    array = this.readConnectionQueue.ToArray();
                    this.readConnectionQueue.Clear();
                    connectionArray = this.writeConnectionQueue.ToArray();
                    this.writeConnectionQueue.Clear();
                }
                else
                {
                    return;
                }
            }
            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTrace(traceEventType))
            {
                TraceUtility.TraceEvent(traceEventType, TraceCode.SocketConnectionAbort, this);
            }
            if (this.readConnection != this.writeConnection)
            {
                this.writeConnection.Abort();
            }
            this.readConnection.Abort();
            HybridConnection.AbortConnections(array);
            HybridConnection.AbortConnections(connectionArray);
            if (this.directConnect != null)
            {
                this.directConnect.Dispose();
            }
            EventHandler eventHandler = this.Closed;

            if (eventHandler != null)
            {
                eventHandler(this, EventArgs.Empty);
            }
        }
Exemplo n.º 2
0
 public HybridConnection(HybridConnectionRole role, Microsoft.ServiceBus.Channels.IConnection connection, IDisposable directConnect, int asyncReadBufferSize)
 {
     if (connection == null)
     {
         throw Fx.Exception.ArgumentNull("connection");
     }
     this.connectionState    = HybridConnectionState.Relayed;
     this.closeState         = HybridConnection.CloseState.Open;
     this.exceptionEventType = TraceEventType.Error;
     Microsoft.ServiceBus.Channels.IConnection connection1 = connection;
     Microsoft.ServiceBus.Channels.IConnection connection2 = connection1;
     this.writeConnection     = connection1;
     this.readConnection      = connection2;
     this.asyncReadBufferSize = asyncReadBufferSize;
     this.Activity            = connection.Activity;
     this.role = role;
     this.readConnectionQueue  = new Queue <Microsoft.ServiceBus.Channels.IConnection>();
     this.writeConnectionQueue = new Queue <Microsoft.ServiceBus.Channels.IConnection>();
     this.directConnect        = directConnect;
     if (connection.AsyncReadBufferSize != asyncReadBufferSize)
     {
         throw new InvalidOperationException(SRClient.InvalidBufferSize);
     }
 }
Exemplo n.º 3
0
        public void Close(TimeSpan timeout)
        {
            Microsoft.ServiceBus.Channels.IConnection[] array;
            Microsoft.ServiceBus.Channels.IConnection[] connectionArray;
            lock (this.ThisLock)
            {
                if (this.closeState == HybridConnection.CloseState.Closing || this.closeState == HybridConnection.CloseState.Closed)
                {
                    return;
                }
                else
                {
                    this.closeState = HybridConnection.CloseState.Closing;
                    array           = this.readConnectionQueue.ToArray();
                    this.readConnectionQueue.Clear();
                    connectionArray = this.writeConnectionQueue.ToArray();
                    this.writeConnectionQueue.Clear();
                }
            }
            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            this.Shutdown(timeoutHelper.RemainingTime());
            byte[]   numArray = new byte[1];
            TimeSpan timeSpan = timeoutHelper.RemainingTime();

            try
            {
                if (this.ReadCore(numArray, 0, 1, timeSpan, true) > 0)
                {
                    ExceptionUtility exceptionUtility            = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                    string           socketCloseReadReceivedData = Resources.SocketCloseReadReceivedData;
                    object[]         remoteIPEndPoint            = new object[] { this.readConnection.RemoteIPEndPoint };
                    throw exceptionUtility.ThrowHelper(new CommunicationException(Microsoft.ServiceBus.SR.GetString(socketCloseReadReceivedData, remoteIPEndPoint)), this.ExceptionEventType);
                }
            }
            catch (TimeoutException timeoutException1)
            {
                TimeoutException timeoutException       = timeoutException1;
                ExceptionUtility exceptionUtility1      = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           socketCloseReadTimeout = Resources.SocketCloseReadTimeout;
                object[]         objArray = new object[] { this.readConnection.RemoteIPEndPoint, timeSpan };
                throw exceptionUtility1.ThrowHelper(new TimeoutException(Microsoft.ServiceBus.SR.GetString(socketCloseReadTimeout, objArray), timeoutException), this.ExceptionEventType);
            }
            if (timeoutHelper.RemainingTime() <= TimeSpan.Zero && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceWarning)
            {
                TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.SocketConnectionAbortClose, this);
            }
            this.readConnection.Close(timeoutHelper.RemainingTime());
            HybridConnection.CloseConnections(array, ref timeoutHelper);
            HybridConnection.CloseConnections(connectionArray, ref timeoutHelper);
            if (this.directConnect != null)
            {
                this.directConnect.Dispose();
            }
            lock (this.ThisLock)
            {
                this.closeState = HybridConnection.CloseState.Closed;
            }
            EventHandler eventHandler = this.Closed;

            if (eventHandler != null)
            {
                eventHandler(this, EventArgs.Empty);
            }
        }