| 80 | } |
| 81 | |
| 82 | Status ReceiveFramedMessageBlocking(Socket* sock, faststring* recv_buf, |
| 83 | MessageLite* header, Slice* param_buf, const MonoTime& deadline) { |
| 84 | DCHECK(sock != nullptr); |
| 85 | DCHECK(recv_buf != nullptr); |
| 86 | DCHECK(header != nullptr); |
| 87 | DCHECK(param_buf != nullptr); |
| 88 | |
| 89 | RETURN_NOT_OK(CheckInBlockingMode(sock)); |
| 90 | |
| 91 | // Read the message prefix, which specifies the length of the payload. |
| 92 | recv_buf->clear(); |
| 93 | recv_buf->resize(kMsgLengthPrefixLength); |
| 94 | size_t recvd = 0; |
| 95 | RETURN_NOT_OK(sock->BlockingRecv(recv_buf->data(), kMsgLengthPrefixLength, &recvd, deadline)); |
| 96 | uint32_t payload_len = NetworkByteOrder::Load32(recv_buf->data()); |
| 97 | |
| 98 | // Verify that the payload size isn't out of bounds. |
| 99 | // This can happen because of network corruption, or a naughty client. |
| 100 | if (PREDICT_FALSE(payload_len > FLAGS_rpc_max_message_size)) { |
| 101 | // A common user mistake is to try to speak the Kudu RPC protocol to an |
| 102 | // HTTP endpoint, or vice versa. |
| 103 | if (memcmp(recv_buf->data(), kHTTPHeader, strlen(kHTTPHeader)) == 0) { |
| 104 | return Status::IOError( |
| 105 | "received invalid RPC message which appears to be an HTTP response. " |
| 106 | "Verify that you have specified a valid RPC port and not an HTTP port."); |
| 107 | } |
| 108 | |
| 109 | return Status::IOError( |
| 110 | strings::Substitute( |
| 111 | "received invalid message of size $0 which exceeds" |
| 112 | " the rpc_max_message_size of $1 bytes", |
| 113 | payload_len, FLAGS_rpc_max_message_size)); |
| 114 | } |
| 115 | |
| 116 | // Read the message payload. |
| 117 | recvd = 0; |
| 118 | recv_buf->resize(payload_len + kMsgLengthPrefixLength); |
| 119 | RETURN_NOT_OK(sock->BlockingRecv(recv_buf->data() + kMsgLengthPrefixLength, |
| 120 | payload_len, &recvd, deadline)); |
| 121 | RETURN_NOT_OK(serialization::ParseMessage(Slice(*recv_buf), header, param_buf)); |
| 122 | return Status::OK(); |
| 123 | } |
| 124 | |
| 125 | } // namespace rpc |
| 126 | } // namespace kudu |
no test coverage detected