Return immediately if the first message is empty

pull/17332/head
Yash Tibrewal 6 years ago
parent 6697496a1d
commit af16b2c09d
  1. 26
      src/core/lib/iomgr/tcp_posix.cc

@ -686,11 +686,9 @@ struct cmsghdr* process_timestamp(grpc_tcp* tcp, msghdr* msg,
} }
/** For linux platforms, reads the socket's error queue and processes error /** For linux platforms, reads the socket's error queue and processes error
* messages from the queue. Returns true if all the errors processed were * messages from the queue.
* timestamps. Returns false if any of the errors were not timestamps. For
* non-linux platforms, error processing is not used/enabled currently.
*/ */
static bool process_errors(grpc_tcp* tcp) { static void process_errors(grpc_tcp* tcp) {
while (true) { while (true) {
struct iovec iov; struct iovec iov;
iov.iov_base = nullptr; iov.iov_base = nullptr;
@ -719,10 +717,10 @@ static bool process_errors(grpc_tcp* tcp) {
} while (r < 0 && saved_errno == EINTR); } while (r < 0 && saved_errno == EINTR);
if (r == -1 && saved_errno == EAGAIN) { if (r == -1 && saved_errno == EAGAIN) {
return true; /* No more errors to process */ return; /* No more errors to process */
} }
if (r == -1) { if (r == -1) {
return false; return;
} }
if (grpc_tcp_trace.enabled()) { if (grpc_tcp_trace.enabled()) {
if ((msg.msg_flags & MSG_CTRUNC) == 1) { if ((msg.msg_flags & MSG_CTRUNC) == 1) {
@ -732,10 +730,14 @@ static bool process_errors(grpc_tcp* tcp) {
if (msg.msg_controllen == 0) { if (msg.msg_controllen == 0) {
/* There was no control message found. It was probably spurious. */ /* There was no control message found. It was probably spurious. */
return true; return;
}
auto cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg == nullptr || cmsg->cmsg_len == 0) {
/* No control message found. */
return;
} }
for (auto cmsg = CMSG_FIRSTHDR(&msg); cmsg && cmsg->cmsg_len; do {
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level != SOL_SOCKET || if (cmsg->cmsg_level != SOL_SOCKET ||
cmsg->cmsg_type != SCM_TIMESTAMPING) { cmsg->cmsg_type != SCM_TIMESTAMPING) {
/* Got a control message that is not a timestamp. Don't know how to /* Got a control message that is not a timestamp. Don't know how to
@ -745,10 +747,10 @@ static bool process_errors(grpc_tcp* tcp) {
"unknown control message cmsg_level:%d cmsg_type:%d", "unknown control message cmsg_level:%d cmsg_type:%d",
cmsg->cmsg_level, cmsg->cmsg_type); cmsg->cmsg_level, cmsg->cmsg_type);
} }
return false; return;
} }
cmsg = process_timestamp(tcp, &msg, cmsg); cmsg = CMSG_NXTHDR(&msg, process_timestamp(tcp, &msg, cmsg));
} } while (cmsg && cmsg->cmsg_len);
} }
} }

Loading…
Cancel
Save