0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-25 12:45:18 +00:00

Read better

This commit is contained in:
Sanae 2022-03-11 20:06:47 -06:00
parent 89dcb7f6c9
commit 4c5682e59b

View file

@ -120,7 +120,8 @@ public class Server {
while (true) { while (true) {
memory = memoryPool.Rent(Constants.HeaderSize); memory = memoryPool.Rent(Constants.HeaderSize);
async Task<bool> Read(Memory<byte> readMem, int readOffset = 0, int readSize = -1) { async Task<bool> Read(Memory<byte> readMem, int readSize = -1) {
int readOffset = 0;
if (readSize == -1) readSize = Constants.HeaderSize; if (readSize == -1) readSize = Constants.HeaderSize;
while (readOffset < readSize) { while (readOffset < readSize) {
int size = await socket.ReceiveAsync(readMem[readOffset..readSize], SocketFlags.None); int size = await socket.ReceiveAsync(readMem[readOffset..readSize], SocketFlags.None);
@ -146,7 +147,7 @@ public class Server {
memTemp.Dispose(); memTemp.Dispose();
} }
if (header.PacketSize > 0 if (header.PacketSize > 0
&& !await Read(memory.Memory[Constants.HeaderSize..(Constants.HeaderSize + header.PacketSize)])) && !await Read(memory.Memory[Constants.HeaderSize..(Constants.HeaderSize + header.PacketSize)], header.PacketSize))
break; break;
// connection initialization // connection initialization