I'm currently implementing IOCP server for a game and I'm trying zero bytes recv technic.
I have 3 questions.
If you know disconnection from the client by checking if
bytestransferred
is 0, then how do you distinguish between receive completion and disconnection?I'm not performing non-block mode
recv()
when I process actual receive process because clients send the bytes of actual data first, so I know how many bytes I'm receiving. Do I need to use non-block moderecv()
still?
I'm doing it like so.
InputMemoryBitStream incomming;
std::string data;
uint32_t strLen = 0;
recv(socket, reinterpret_cast<char*>(&strLen), sizeof(uint32_t), 0);
incomming.resize(strLen);
recv(socket, reinterpret_cast<char*>(incomming.getBufferPtr()), strLen, 0);
incomming.read(data, strLen);
(InputMemoryBitStream is for reading compressed data.)
- I'm dynamically allocating
per io data
every time I doWSARecv()
andWSASend()
and I free them as soon as I finish processing completed I/Os. Is it inefficient to do that? or is it acceptable? Should I reuseper io data
maybe?
Thank you in advance.