Final change for new release.

This commit is contained in:
EdwardNutting_cp 2013-12-24 18:05:49 +00:00
parent a952b8ff4b
commit 33fd366580

View file

@ -140,56 +140,56 @@ namespace Cosmos.Debug.Common
#endif #endif
} }
protected void DoRead(IAsyncResult aResult) // protected void DoRead(IAsyncResult aResult)
{ // {
try // try
{ // {
var xIncoming = (Incoming)aResult.AsyncState; // var xIncoming = (Incoming)aResult.AsyncState;
int xCount = xIncoming.Stream.EndRead(aResult); // int xCount = xIncoming.Stream.EndRead(aResult);
System.Diagnostics.Debug.WriteLine(String.Format("DC - Received: {0}", BytesToString(xIncoming.Packet, xIncoming.CurrentPos, xCount))); // System.Diagnostics.Debug.WriteLine(String.Format("DC - Received: {0}", BytesToString(xIncoming.Packet, xIncoming.CurrentPos, xCount)));
xIncoming.CurrentPos += xCount; // xIncoming.CurrentPos += xCount;
if (xCount == 0) // if (xCount == 0)
{ // {
// If 0, end of stream then just exit without calling BeginRead again // // If 0, end of stream then just exit without calling BeginRead again
return; // return;
} // }
else if (xIncoming.CurrentPos < xIncoming.Packet.Length) // else if (xIncoming.CurrentPos < xIncoming.Packet.Length)
{ // {
// Packet is not full yet, read more data // // Packet is not full yet, read more data
#if TRACK_PENDING //#if TRACK_PENDING
try { // try {
Interlocked.Increment(ref _pendingReadsCount); // Interlocked.Increment(ref _pendingReadsCount);
#endif //#endif
xIncoming.Stream.BeginRead(xIncoming.Packet, xIncoming.CurrentPos // xIncoming.Stream.BeginRead(xIncoming.Packet, xIncoming.CurrentPos
, xIncoming.Packet.Length - xIncoming.CurrentPos // , xIncoming.Packet.Length - xIncoming.CurrentPos
, new AsyncCallback(DoRead), xIncoming); // , new AsyncCallback(DoRead), xIncoming);
#if TRACK_PENDING //#if TRACK_PENDING
} // }
catch (Exception e) { // catch (Exception e) {
Interlocked.Decrement(ref _pendingReadsCount); // Interlocked.Decrement(ref _pendingReadsCount);
throw; // throw;
} // }
#endif //#endif
} // }
else // else
{ // {
System.Diagnostics.Debug.WriteLine(String.Format("DC - Full packet received - Received: {0}", BytesToString(xIncoming.Packet, 0, xIncoming.Packet.Length))); // System.Diagnostics.Debug.WriteLine(String.Format("DC - Full packet received - Received: {0}", BytesToString(xIncoming.Packet, 0, xIncoming.Packet.Length)));
// Full packet received, process it // // Full packet received, process it
xIncoming.Completed(xIncoming.Packet); // xIncoming.Completed(xIncoming.Packet);
} // }
} // }
catch (System.IO.IOException ex) // catch (System.IO.IOException ex)
{ // {
ConnectionLost(ex); // ConnectionLost(ex);
} // }
#if TRACK_PENDING //#if TRACK_PENDING
finally { // finally {
Interlocked.Decrement(ref _pendingReadsCount); // Interlocked.Decrement(ref _pendingReadsCount);
} // }
#endif //#endif
} // }
private List<Incoming> ReadQueue = new List<Incoming>(); private List<Incoming> ReadQueue = new List<Incoming>();
private bool reading = false; private bool reading = false;
@ -215,11 +215,11 @@ namespace Cosmos.Debug.Common
} }
else else
{ {
mStream.BeginRead(next.Packet, next.CurrentPos, next.Packet.Length - next.CurrentPos, new AsyncCallback(DoRead2), next); mStream.BeginRead(next.Packet, next.CurrentPos, next.Packet.Length - next.CurrentPos, new AsyncCallback(DoRead), next);
} }
} }
} }
private void DoRead2(IAsyncResult result) private void DoRead(IAsyncResult result)
{ {
try try
{ {