Skip to content

Commit

Permalink
fix: network statistic input bytes is not right in some case(OpenAtom…
Browse files Browse the repository at this point in the history
…Foundation#2223) (OpenAtomFoundation#2224) (OpenAtomFoundation#2234)

Co-authored-by: liuchengyu <liuchengyu@360.cn>
  • Loading branch information
chengyu-l and liuchengyu committed Dec 24, 2023
1 parent fc68552 commit c12fa12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/net/src/pb_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ReadStatus PbConn::GetRequest() {
switch (connStatus_) {
case kHeader: {
ssize_t nread = read(fd(), rbuf_ + cur_pos_, COMMAND_HEADER_LENGTH - cur_pos_);
g_network_statistic->IncrReplInputBytes(nread);
if (nread == -1) {
if (errno == EAGAIN) {
return kReadHalf;
Expand All @@ -47,6 +46,7 @@ ReadStatus PbConn::GetRequest() {
} else if (nread == 0) {
return kReadClose;
} else {
g_network_statistic->IncrReplInputBytes(nread);
cur_pos_ += nread;
if (cur_pos_ == COMMAND_HEADER_LENGTH) {
uint32_t integer = 0;
Expand Down Expand Up @@ -75,7 +75,6 @@ ReadStatus PbConn::GetRequest() {
}
// read msg body
ssize_t nread = read(fd(), rbuf_ + cur_pos_, remain_packet_len_);
g_network_statistic->IncrReplInputBytes(nread);
if (nread == -1) {
if (errno == EAGAIN) {
return kReadHalf;
Expand All @@ -85,6 +84,7 @@ ReadStatus PbConn::GetRequest() {
} else if (nread == 0) {
return kReadClose;
}
g_network_statistic->IncrReplInputBytes(nread);
cur_pos_ += static_cast<uint32_t>(nread);
remain_packet_len_ -= static_cast<int32_t>(nread);
if (remain_packet_len_ == 0) {
Expand Down Expand Up @@ -122,10 +122,10 @@ WriteStatus PbConn::SendReply() {
item_len = item.size();
while (item_len - write_buf_.item_pos_ > 0) {
nwritten = write(fd(), item.data() + write_buf_.item_pos_, item_len - write_buf_.item_pos_);
g_network_statistic->IncrReplOutputBytes(nwritten);
if (nwritten <= 0) {
break;
}
g_network_statistic->IncrReplOutputBytes(nwritten);
write_buf_.item_pos_ += nwritten;
if (write_buf_.item_pos_ == item_len) {
write_buf_.queue_.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/net/src/redis_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ WriteStatus RedisConn::SendReply() {
size_t wbuf_len = response_.size();
while (wbuf_len > 0) {
nwritten = write(fd(), response_.data() + wbuf_pos_, wbuf_len - wbuf_pos_);
g_network_statistic->IncrRedisOutputBytes(nwritten);
if (nwritten <= 0) {
break;
}
g_network_statistic->IncrRedisOutputBytes(nwritten);
wbuf_pos_ += nwritten;
if (wbuf_pos_ == wbuf_len) {
// Have sended all response data
Expand Down

0 comments on commit c12fa12

Please sign in to comment.