| 1031 | } |
| 1032 | |
| 1033 | void SAMSocket::Receive () |
| 1034 | { |
| 1035 | if (m_SocketType == SAMSocketType::eSAMSocketTypeStream) |
| 1036 | { |
| 1037 | if (m_IsReceiving) return; |
| 1038 | size_t bufSize = SAM_SOCKET_BUFFER_SIZE; |
| 1039 | size_t unsentSize = m_Stream ? m_Stream->GetSendBufferSize () : 0; |
| 1040 | if (unsentSize) |
| 1041 | { |
| 1042 | if (unsentSize >= SAM_STREAM_MAX_SEND_BUFFER_SIZE) return; // buffer is full |
| 1043 | if (unsentSize > SAM_STREAM_MAX_SEND_BUFFER_SIZE - SAM_SOCKET_BUFFER_SIZE) |
| 1044 | bufSize = SAM_STREAM_MAX_SEND_BUFFER_SIZE - unsentSize; |
| 1045 | } |
| 1046 | m_IsReceiving = true; |
| 1047 | m_Socket.async_read_some (boost::asio::buffer(m_Buffer, bufSize), |
| 1048 | std::bind(&SAMSocket::HandleReceived, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); |
| 1049 | } |
| 1050 | else |
| 1051 | m_Socket.async_read_some (boost::asio::buffer(m_Buffer + m_BufferOffset, SAM_SOCKET_BUFFER_SIZE - m_BufferOffset), |
| 1052 | std::bind(&SAMSocket::HandleMessage, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); |
| 1053 | } |
| 1054 | |
| 1055 | void SAMSocket::HandleReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred) |
| 1056 | { |
no test coverage detected