Skip to content

Commit

Permalink
[src] Fix the bug of blocking reading of RpcCodec for single socket fd
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigma711 committed Aug 25, 2023
1 parent 51b5c01 commit 308fdac
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/rpc_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer,
int saved_errno = 0; // FIXME: error check
const ssize_t min_header_len =
static_cast<ssize_t>(kMinMessageLength + kHeaderLength);
while (min_header_len >= io_buffer->GetReadableBytes()) {
io_buffer->ReadFromFd(sock_fd, min_header_len, &saved_errno);
while (min_header_len > io_buffer->GetReadableBytes()) {
io_buffer->ReadFromFd(
sock_fd, min_header_len - io_buffer->GetReadableBytes(), &saved_errno);
if (saved_errno != 0) {
LOG_ERROR("RpcCodec::OnMessage() - Fd(%d) with errno(%d)", sock_fd,
saved_errno);
Expand All @@ -135,9 +136,11 @@ void RpcCodec::OnMessage(int sock_fd, IoBuffer* io_buffer,
ErrorCode::kInvalidLength);
return;
}
while (static_cast<size_t>(kHeaderLength + len) >=
while (static_cast<size_t>(kHeaderLength + len) >
io_buffer->GetReadableBytes()) {
io_buffer->ReadFromFd(sock_fd, static_cast<size_t>(kHeaderLength + len),
io_buffer->ReadFromFd(sock_fd,
static_cast<size_t>(kHeaderLength + len) -
io_buffer->GetReadableBytes(),
&saved_errno);
}
if (AsyncRawCallback_ &&
Expand Down

0 comments on commit 308fdac

Please sign in to comment.