void ReadPacket(AsyncData ad) { while (true) { if (_socket == null) { break; } int needRecvSize = Math.Min(_recvBuffer.Length, ad.Size); int recvLen; try { recvLen = _socket.Receive(_recvBuffer, needRecvSize, SocketFlags.None); } catch (Exception) { Error(NetworkReason.RecvError, true); break; } if (recvLen <= 0) { Close( ); break; } ad.Size -= recvLen; ad.Stream.Write(_recvBuffer, 0, recvLen); if (ad.Size == 0) { ad.Stream.Seek(0, SeekOrigin.Begin); ad.Callback(ad.Stream, ad.Tag); break; } } }
void ReadPacket(AsyncData ad) { while (true) { if (_socket == null) { break; } int recvLen; try { recvLen = _socket.Receive(ad.Data); } catch (Exception) { Error(NetworkReason.RecvError, true); break; } if (recvLen <= 0) { Close( ); break; } ad.Size -= recvLen; ad.Stream.Write(ad.Data, 0, recvLen); if (ad.Size == 0) { ad.Stream.Seek(0, SeekOrigin.Begin); ad.Callback(ad.Stream, ad.Tag); break; } } }