private void IntReadCallback(IAsyncResult ar) { AsyncRequest lRequest = (AsyncRequest)ar.AsyncState; Int32 lCount; try { BufferAsyncResult lBufferResult = ar as BufferAsyncResult; if (lBufferResult != null) { if (fBufferEnd - fBufferStart > lBufferResult.Count) { for (Int32 i = 0; i < lBufferResult.Count; i++) { lBufferResult.Buffer[lBufferResult.Offset + i] = fBuffer[i + fBufferStart]; } fBufferStart += lBufferResult.Count; lCount = lBufferResult.Count; } else { Int32 lSize = fBufferEnd - fBufferStart; for (Int32 i = 0; i < lSize; i++) { lBufferResult.Buffer[lBufferResult.Offset + i] = fBuffer[i + fBufferStart]; } fBufferStart = 0; fBufferEnd = 0; lCount = lSize; } } else { lCount = IntEndRead(ar); } } catch (ObjectDisposedException) // disconnect from this side { TriggerAsyncDisconnect(); return; } catch (SocketException) // disconnect { TriggerAsyncDisconnect(); return; } catch (ArgumentException) // disconnect { return; } if (lCount == 0) { TriggerAsyncDisconnect(); return; } lRequest.AsyncRest = lRequest.AsyncRest - lCount; if (lRequest.AsyncRest > 0) { lRequest.AsyncOffset = lRequest.AsyncOffset + lCount; try { TriggerAsyncHaveIncompleteData(); IntBeginRead(lRequest.AsyncBuffer, lRequest.AsyncOffset, lRequest.AsyncRest, IntReadCallback, lRequest); } catch (ObjectDisposedException) // disconnect from this side { TriggerAsyncDisconnect(); } catch (SocketException) // disconnect { TriggerAsyncDisconnect(); } } else { lRequest.AsyncCallback(lRequest); } }