MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / Receive

Method Receive

examples/ThirdPartyLibs/clsocket/src/SimpleSocket.cpp:698–807  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Receive() - Attempts to receive a block of data on an established connection. Data is received in an internal buffer managed by the class. This buffer is only valid until the next call to Receive(), a call to Close(), or until the object goes out of scope. ----------------------------------------------------------

Source from the content-addressed store, hash-verified

696//
697//------------------------------------------------------------------------------
698int32 CSimpleSocket::Receive(int32 nMaxBytes, uint8 *pBuffer)
699{
700 m_nBytesReceived = 0;
701
702 //--------------------------------------------------------------------------
703 // If the socket is invalid then return false.
704 //--------------------------------------------------------------------------
705 if (IsSocketValid() == false)
706 {
707 return m_nBytesReceived;
708 }
709
710 uint8 *pWorkBuffer = pBuffer;
711 if (pBuffer == NULL)
712 {
713 //--------------------------------------------------------------------------
714 // Free existing buffer and allocate a new buffer the size of
715 // nMaxBytes.
716 //--------------------------------------------------------------------------
717 if ((m_pBuffer != NULL) && (nMaxBytes != m_nBufferSize))
718 {
719 delete[] m_pBuffer;
720 m_pBuffer = NULL;
721 }
722
723 //--------------------------------------------------------------------------
724 // Allocate a new internal buffer to receive data.
725 //--------------------------------------------------------------------------
726 if (m_pBuffer == NULL)
727 {
728 m_nBufferSize = nMaxBytes;
729 m_pBuffer = new uint8[nMaxBytes];
730 }
731
732 pWorkBuffer = m_pBuffer;
733 }
734
735 SetSocketError(SocketSuccess);
736
737 m_timer.Initialize();
738 m_timer.SetStartTime();
739
740 switch (m_nSocketType)
741 {
742 //----------------------------------------------------------------------
743 // If zero bytes are received, then return. If SocketERROR is
744 // received, free buffer and return CSocket::SocketError (-1) to caller.
745 //----------------------------------------------------------------------
746 case CSimpleSocket::SocketTypeTcp:
747 {
748 do
749 {
750 m_nBytesReceived = RECV(m_socket, (pWorkBuffer + m_nBytesReceived),
751 nMaxBytes, m_nFlags);
752 TranslateSocketError();
753 } while ((GetSocketError() == CSimpleSocket::SocketInterrupted));
754
755 break;

Callers 8

CreateTCPEchoServerFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
checkDataMethod · 0.80
processServerStatusMethod · 0.80
TCPThreadFuncFunction · 0.80
mainFunction · 0.80

Calls 3

SetStartTimeMethod · 0.80
SetEndTimeMethod · 0.80
InitializeMethod · 0.45

Tested by

no test coverage detected