void UdpReceiveThread::Main() { SocketThreadOperation *op = mSocketThreadOperation; UdpSocket *s = (UdpSocket*)op->mSocket; ErrorType error; StopWatch sw; sw.Start(); while (!ShouldEnd()) { error = s->Receive(op->mIPAddress, &op->mByteStream, Math::ClampLong(op->mTimeoutMS - sw.GetElapsedMilliseconds(), 0L, 16L)); if (0L == op->mTimeoutMS || (error && kErrorTimedOut != error) || (0L < op->mTimeoutMS && sw.GetElapsedMilliseconds() >= op->mTimeoutMS)) { if (error) Error::Throw(error, String("[%s(%p, %p)]", FastFunctionName, this, op)); s->OnReceive(op->mID, op->mIPAddress, op->mByteStream, error); op->mByteStream.Clear(); sw.Reset(); sw.Start(); continue; } } }
void TcpServerReceiveThread::Main() { SocketThreadOperation *op = mSocketThreadOperation; TcpServerSocket *s = (TcpServerSocket*)op->mSocket; ErrorType error; StopWatch sw; sw.Start(); while (!ShouldEnd()) { error = s->Receive(op->mTcpClientConnectionID, &op->mByteStream, Math::ClampLong( op->mTimeoutMS - sw.GetElapsedMilliseconds(), 0L, 33L)); if (0L == op->mTimeoutMS || (error && kErrorTimedOut != error) || (0L < op->mTimeoutMS && sw.GetElapsedMilliseconds() >= op->mTimeoutMS)) { if (error) Error::Throw(error, String("[%s(%p, %p)]", FastFunctionName, this, op)); s->OnReceive(op->mID, op->mTcpClientConnectionID, op->mByteStream, error); sw.Reset(); sw.Start(); } } }
void TcpClientConnectThread::Main() { SocketThreadOperation *op = mSocketThreadOperation; TcpClientSocket *s = (TcpClientSocket*)op->mSocket; ErrorType error; StopWatch sw; sw.Start(); while (!ShouldEnd()) { error = s->Connect(op->mIPAddress, Math::ClampLong( op->mTimeoutMS - sw.GetElapsedMilliseconds(), 0L, 33L)); if (0L == op->mTimeoutMS || (error && kErrorTimedOut != error) || (0L < op->mTimeoutMS && sw.GetElapsedMilliseconds() >= op->mTimeoutMS)) { if (error) Error::Throw(error, String("[%s(%p, %p)]", FastFunctionName, this, op)); s->OnConnect(op->mID, op->mIPAddress, kErrorTimedOut); break; } } }