예제 #1
0
        protected void CloseConnection(Exception e)           // not synced!
        // e == SocketException || SslException
        {
            if (!m_IsDisposed)
            {
                if (this.OnConnectionClose != null)
                {
                    this.OnConnectionClose(this, new SocketCloseEventArgs()
                    {
                        Exception = e
                    });
                }

                m_IsDisposed = true;
                try {
                    m_Socket.Shutdown(SocketShutdown.Both);
                } catch {}
                m_Socket.Close();
                if (m_ActiveSend != null)
                {
                    if (m_ActiveSend.AsyncResult != null)
                    {
                        m_SentList.Add(m_ActiveSend);
                        m_ActiveSend.AsyncResult.Notify(e);
                    }
                }
                Exception f = e;
                if (f == null)
                {
                    f = new SslException(AlertDescription.UnexpectedMessage, "The bytes could not be sent because the connection has been closed.");
                }
                for (int i = 0; i < m_ToSendList.Count; i++)
                {
                    m_ActiveSend = (TransferItem)m_ToSendList[i];
                    m_SentList.Add(m_ActiveSend);
                    if (m_ActiveSend.AsyncResult != null)
                    {
                        m_ActiveSend.AsyncResult.Notify(f);
                    }
                }
                m_ToSendList.Clear();
                if (m_ActiveReceive != null && m_ActiveReceive.AsyncResult != null)
                {
                    m_ActiveReceive.AsyncResult.Notify(e);
                }
                if (m_ShutdownCallback != null)
                {
                    m_ShutdownCallback.Notify(e);
                }
                // destroy sensitive data
                if (m_RecordLayer != null)
                {
                    m_RecordLayer.Dispose();
                }
            }
        }
예제 #2
0
		protected void CloseConnection(Exception e) { // not synced!
			// e == SocketException || SslException
			if (!m_IsDisposed) {
				m_IsDisposed = true;
				try {
					m_Socket.Shutdown(SocketShutdown.Both);
				} catch {}
				m_Socket.Close();
				if (m_ActiveSend != null) {
					if (m_ActiveSend.AsyncResult != null) {
						m_SentList.Add(m_ActiveSend);
						m_ActiveSend.AsyncResult.Notify(e);
					}
				}
				Exception f = e;
				if (f == null)
					f = new SslException(AlertDescription.UnexpectedMessage, "The bytes could not be sent because the connection has been closed.");
				for(int i = 0; i < m_ToSendList.Count; i++) {
					m_ActiveSend = (TransferItem)m_ToSendList[i];
					m_SentList.Add(m_ActiveSend);
					m_ActiveSend.AsyncResult.Notify(f);
				}
				m_ToSendList.Clear();
				if (m_ActiveReceive != null && m_ActiveReceive.AsyncResult != null) {
					m_ActiveReceive.AsyncResult.Notify(e);
				}
				if (m_ShutdownCallback != null) {
					m_ShutdownCallback.Notify(e);
				}
				// destroy sensitive data
				if (m_RecordLayer != null)
					m_RecordLayer.Dispose();
			}
		}