Index: src/shared/NetworkNew/Socket.cpp =================================================================== --- src/shared/NetworkNew/Socket.cpp (revision 29) +++ src/shared/NetworkNew/Socket.cpp (working copy) @@ -326,38 +326,62 @@ void Socket::OnReadEvent() { - if(!m_bConnected) - return; -//LockReading UnlockReading are still questions + if(!m_bConnected) + return; + + //TODO peak MSG_PEEK LockReading(); uint32 iosize = recv(GetSocket(), (char*)(ReadBuffer()->get_buffer() + ReadBuffer()->get_data_size()), ReadBuffer()->get_free_size(), 0); - if(iosize > 0) - { - ReadBuffer()->get_offset() += iosize; - OnRead(); + if (iosize == 0 || iosize == -1) + {//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; } - 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; - } - } + + ReadBuffer()->get_offset() += iosize; UnlockReading(); - return; + OnRead(); } +// void Socket::OnReadEvent() +// { +// if(!m_bConnected) +// return; +// //LockReading UnlockReading are still questions +// LockReading(); +// uint32 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; +// } + #endif//USE_LEVENT //////////////////////////////////////////////////////////////////////////