| 51 | } |
| 52 | |
| 53 | std::string receive() noexcept { |
| 54 | // If uninitialized then bail |
| 55 | if (!detail::isValidSocket(m_socket)) { |
| 56 | return ""; |
| 57 | } |
| 58 | |
| 59 | // Try to receive (this is blocking) |
| 60 | std::string buffer(256, '\0'); |
| 61 | int string_len; |
| 62 | if ((string_len = recv(m_socket, &buffer[0], static_cast<int>(buffer.size()), 0)) < 1) { |
| 63 | m_errorMessage = "Could not recv on the socket file descriptor"; |
| 64 | return ""; |
| 65 | } |
| 66 | |
| 67 | // No error return the trimmed result |
| 68 | m_errorMessage.clear(); |
| 69 | buffer.resize(std::min(static_cast<size_t>(string_len), buffer.size())); |
| 70 | return buffer; |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | SOCKET_TYPE m_socket; |
no test coverage detected