* @brief Receive data from socket * * ...and puts it in `buf`. * * @param buf A writable memory buffer of length `len` * @param len Length of `buf` * @param flags Flags for `recv(2)`. WARNING: Throws an exception if `recv()` * returns -1; this may be the case if the flag `MSG_DONTWAIT` is used. * * @returns The length of received data */
| 66 | * @returns The length of received data |
| 67 | */ |
| 68 | ssize_t stream_client_socket::rcv(void* buf, size_t len, int flags) { |
| 69 | ssize_t recvd; |
| 70 | |
| 71 | if (shut_rd == true) |
| 72 | throw socket_exception( |
| 73 | __FILE__, __LINE__, |
| 74 | "stream_client_socket::rcv() - Socket has already been shut down!", |
| 75 | false); |
| 76 | |
| 77 | if (sfd == -1) |
| 78 | throw socket_exception( |
| 79 | __FILE__, __LINE__, |
| 80 | "stream_client_socket::rcv() - Socket is not connected!", false); |
| 81 | |
| 82 | if (buf == NULL || len == 0) |
| 83 | throw socket_exception( |
| 84 | __FILE__, __LINE__, |
| 85 | "stream_client_socket::rcv() - Buffer or length is null!", false); |
| 86 | |
| 87 | memset(buf, 0, len); |
| 88 | |
| 89 | if (-1 == (recvd = BERKELEY::recv(sfd, buf, len, flags))) { |
| 90 | if (is_nonblocking && errno == EWOULDBLOCK) |
| 91 | return -1; |
| 92 | else |
| 93 | throw socket_exception( |
| 94 | __FILE__, __LINE__, |
| 95 | "stream_client_socket::rcv() - Error while reading!"); |
| 96 | } |
| 97 | |
| 98 | return recvd; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @brief Receive data from socket to a string |
nothing calls this directly
no test coverage detected