Skip to content

Commit

Permalink
Merge branch 'master' into readme-add-profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
cyshi committed Dec 30, 2016
2 parents ac0c1dc + eac8e69 commit c7e0fca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/sofa/pbrpc/binary_rpc_request_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
namespace sofa {
namespace pbrpc {

#define SOFA_PBRPC_MAX_RPC_MESSAGE_SIZE (64 << 20)
const int64 BinaryRpcRequestParser::MAX_MESSAGE_SIZE =
SOFA_PBRPC_MAX_RPC_MESSAGE_SIZE + sizeof(RpcMessageHeader);

BinaryRpcRequestParser::BinaryRpcRequestParser() :
_state(PS_MAGIC_STRING),
_bytes_recved(0),
Expand Down Expand Up @@ -51,12 +55,12 @@ int BinaryRpcRequestParser::Parse(const char* buf,
return 0;
}
*bytes_consumed = 0;
int bytes_remain, consume;
int64 bytes_remain, consume;
switch (_state)
{
case PS_MSG_HEADER:
bytes_remain = sizeof(RpcMessageHeader) - _bytes_recved;
consume = std::min(data_size, bytes_remain);
consume = std::min(static_cast<int64>(data_size), bytes_remain);
memcpy(reinterpret_cast<char*>(&_req->_req_header) + _bytes_recved,
buf + offset, consume);
*bytes_consumed += consume;
Expand All @@ -82,7 +86,21 @@ int BinaryRpcRequestParser::Parse(const char* buf,
}
case PS_MSG_BODY:
bytes_remain = _req->_req_header.message_size - _bytes_recved;
consume = std::min(data_size, bytes_remain);
if (bytes_remain > MAX_MESSAGE_SIZE || bytes_remain <= 0)
{
// compute bytes_remain error
#if defined( LOG )
LOG(ERROR) << "Parse(): " << RpcEndpointToString(_req->_remote_endpoint)
<< ": compute bytes_remain[" << bytes_remain
<< "] error, message size limit[" << MAX_MESSAGE_SIZE << "]";
#else
SLOG(ERROR, "Parse(): %s: compute bytes_remain[%lld] error, message size limit[%lld]",
RpcEndpointToString(_req->_remote_endpoint).c_str(),
bytes_remain, MAX_MESSAGE_SIZE);
#endif
return -1;
}
consume = std::min(static_cast<int64>(data_size), bytes_remain);
_req->_req_body->Append(BufHandle(const_cast<char*>(buf), consume, offset));
*bytes_consumed += consume;
_bytes_recved += consume;
Expand Down
2 changes: 2 additions & 0 deletions src/sofa/pbrpc/binary_rpc_request_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BinaryRpcRequestParser : public RpcRequestParser
ParseState _state; // current parsing state
int _bytes_recved; // bytes received in current state
BinaryRpcRequestPtr _req;

static const int64 MAX_MESSAGE_SIZE;
}; // class BinaryRpcRequestParser

} // namespace pbrpc
Expand Down

0 comments on commit c7e0fca

Please sign in to comment.