Skip to content

Commit

Permalink
Merge branch 'master' of https://git01.codeplex.com/clientengine
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed Dec 15, 2014
2 parents 12acdbc + d2f1993 commit 70a02fb
Show file tree
Hide file tree
Showing 2 changed files with 381 additions and 339 deletions.
39 changes: 37 additions & 2 deletions Core/SslStreamTcpSession.cs
Expand Up @@ -63,6 +63,13 @@ private void OnAuthenticated(IAsyncResult result)
{
var sslStream = result.AsyncState as SslStream;

if(sslStream == null)
{
EnsureSocketClosed();
OnError(new NullReferenceException("Ssl Stream is null OnAuthenticated"));
return;
}

try
{
sslStream.EndAuthenticateAsClient(result);
Expand All @@ -87,6 +94,13 @@ private void OnAuthenticated(IAsyncResult result)
private void OnDataRead(IAsyncResult result)
{
var state = result.AsyncState as SslAsyncState;

if (state == null || state.SslStream == null)
{
OnError(new NullReferenceException("Null state or stream."));
return;
}

var sslStream = state.SslStream;

int length = 0;
Expand All @@ -95,7 +109,7 @@ private void OnDataRead(IAsyncResult result)
{
length = sslStream.EndRead(result);
}
catch (Exception e)
catch (Exception e)
{
if (!IsIgnorableException(e))
OnError(e);
Expand All @@ -122,7 +136,7 @@ void BeginRead()
{
var client = Client;

if (client == null)
if (client == null || m_SslStream == null)
return;

try
Expand Down Expand Up @@ -253,6 +267,13 @@ protected override void SendInternal(PosList<ArraySegment<byte>> items)
private void OnWriteComplete(IAsyncResult result)
{
var state = result.AsyncState as SslAsyncState;

if (state == null || state.SslStream == null)
{
OnError(new NullReferenceException("State of Ssl stream is null."));
return;
}

var sslStream = state.SslStream;

try
Expand Down Expand Up @@ -298,5 +319,19 @@ private void OnWriteComplete(IAsyncResult result)

OnSendingCompleted();
}

public override void Close()
{
var sslStream = m_SslStream;

if (sslStream != null)
{
sslStream.Close();
sslStream.Dispose();
m_SslStream = null;
}

base.Close();
}
}
}

0 comments on commit 70a02fb

Please sign in to comment.