rendered paste bodyvoid Socket::OnReadEvent()
{
if(event_add(&m_ev_read, NULL) == -1)
{
sLog.outError("<Socket %u> Couldn't add EV_READ | EV_PERSIST event", GetSocket());
return;
}
LockReading();
int32 iosize = recv(GetSocket(),
(char*)(ReadBuffer()->get_buffer() + ReadBuffer()->get_data_size()),
ReadBuffer()->get_free_size(), 0);
if(iosize > 0)
{
ReadBuffer()->get_offset() += iosize;
OnRead();
}
else
{
#ifdef WIN32
DWORD err = WSAGetLastError();
if (iosize == 0 || (iosize == -1 && err != WSAEWOULDBLOCK))
#else
if (iosize == 0 || (iosize == -1 && (errno != EAGAIN && errno != EWOULDBLOCK)))
#endif
{ //If the connection has been gracefully closed, the return value is zero.
//If the connection has been abortively closed, the return value is SOCKET_ERROR.
UnlockReading();
Disconnect(iosize == -1);
return;
}
}
UnlockReading();
return;
}