33// LICENSE file in the root directory of this source tree. An additional grant
44// of patent rights can be found in the PATENTS file in the same directory.
55
6+ #include < sys/socket.h>
7+ #include < netinet/tcp.h>
8+ #include < netinet/in.h>
9+
610#include " net/include/pb_conn.h"
711
812#include < arpa/inet.h>
@@ -36,9 +40,13 @@ ReadStatus PbConn::GetRequest() {
3640 while (true ) {
3741 switch (connStatus_) {
3842 case kHeader : {
43+ int quickack = 1 ;
3944 ssize_t nread = read (fd (), rbuf_ + cur_pos_, COMMAND_HEADER_LENGTH - cur_pos_);
45+ setsockopt (fd (), IPPROTO_TCP, TCP_QUICKACK, &quickack, sizeof (quickack));
46+ // LOG(INFO) << "kHeader nread size: " << nread;
4047 if (nread == -1 ) {
4148 if (errno == EAGAIN) {
49+ // LOG(INFO) << "kHeader errno == EAGAIN readhalf";
4250 return kReadHalf ;
4351 } else {
4452 return kReadError ;
@@ -56,6 +64,7 @@ ReadStatus PbConn::GetRequest() {
5664 connStatus_ = kPacket ;
5765 continue ;
5866 }
67+ // LOG(INFO) << "kHeader readhalf";
5968 return kReadHalf ;
6069 }
6170 }
@@ -75,8 +84,12 @@ ReadStatus PbConn::GetRequest() {
7584 }
7685 // read msg body
7786 ssize_t nread = read (fd (), rbuf_ + cur_pos_, remain_packet_len_);
87+ int quickack = 1 ;
88+ setsockopt (fd (), IPPROTO_TCP, TCP_QUICKACK, &quickack, sizeof (quickack));
89+ // LOG(INFO) << "kPacket nread size: " << nread;
7890 if (nread == -1 ) {
7991 if (errno == EAGAIN) {
92+ // LOG(INFO) << "kPacket errno == EAGAIN readhalf";
8093 return kReadHalf ;
8194 } else {
8295 return kReadError ;
@@ -88,12 +101,15 @@ ReadStatus PbConn::GetRequest() {
88101 cur_pos_ += static_cast <uint32_t >(nread);
89102 remain_packet_len_ -= static_cast <int32_t >(nread);
90103 if (remain_packet_len_ == 0 ) {
104+ // LOG(INFO) << "connStatus_ turns to kComplete";
91105 connStatus_ = kComplete ;
92106 continue ;
93107 }
108+ // LOG(INFO) << "kPacket readhalf";
94109 return kReadHalf ;
95110 }
96111 case kComplete : {
112+ // LOG(INFO) << "kComplete";
97113 if (DealMessage () != 0 ) {
98114 return kDealError ;
99115 }
@@ -117,12 +133,15 @@ WriteStatus PbConn::SendReply() {
117133 ssize_t nwritten = 0 ;
118134 size_t item_len;
119135 std::lock_guard l (resp_mu_);
136+ // LOG(INFO) << "queue size to write to fd " << write_buf_.queue_.size();
120137 while (!write_buf_.queue_ .empty ()) {
121138 std::string item = write_buf_.queue_ .front ();
122139 item_len = item.size ();
140+ // LOG(INFO) << "queue item size: " << item_len;
123141 while (item_len - write_buf_.item_pos_ > 0 ) {
124142 nwritten = write (fd (), item.data () + write_buf_.item_pos_ , item_len - write_buf_.item_pos_ );
125143 if (nwritten <= 0 ) {
144+ LOG (ERROR) << " nwritten less than 0" ;
126145 break ;
127146 }
128147 g_network_statistic->IncrReplOutputBytes (nwritten);
@@ -144,6 +163,7 @@ WriteStatus PbConn::SendReply() {
144163 if (item_len - write_buf_.item_pos_ != 0 ) {
145164 return kWriteHalf ;
146165 }
166+ LOG (ERROR) << " write item success" ;
147167 }
148168 return kWriteAll ;
149169}
0 commit comments