示例#1
0
 public void Shutdown(TimeSpan timeout)
 {
     Microsoft.ServiceBus.Channels.IConnection[] array;
     Microsoft.ServiceBus.Channels.IConnection[] connectionArray;
     Microsoft.ServiceBus.Common.TimeoutHelper   timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
     lock (this.ThisLock)
     {
         if (!this.isShutdown)
         {
             this.isShutdown = true;
             array           = this.readConnectionQueue.ToArray();
             this.readConnectionQueue.Clear();
             connectionArray = this.writeConnectionQueue.ToArray();
             this.writeConnectionQueue.Clear();
         }
         else
         {
             return;
         }
     }
     try
     {
         this.writeConnection.Shutdown(timeoutHelper.RemainingTime());
         HybridConnection.CloseConnections(array, ref timeoutHelper);
         HybridConnection.CloseConnections(connectionArray, ref timeoutHelper);
         if (this.directConnect != null)
         {
             this.directConnect.Dispose();
         }
     }
     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;
     }
 }
示例#2
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);
            }
        }