diff options
author | Yash Tibrewal <yashkt@google.com> | 2018-11-28 20:16:27 -0800 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2018-11-28 20:31:14 -0800 |
commit | af16b2c09d75f56acc9fa2c7d76ebb038e06ea3e (patch) | |
tree | 82ca0febcaacf50b5e6ad05ce43531a1852c694e /src/core/lib | |
parent | 6697496a1dca9012375c8a00ac6acedaa42449d9 (diff) |
Return immediately if the first message is empty
Diffstat (limited to 'src/core/lib')
-rw-r--r-- | src/core/lib/iomgr/tcp_posix.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index 606bfce6e7..84d593426e 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/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 - * messages from the queue. Returns true if all the errors processed were - * timestamps. Returns false if any of the errors were not timestamps. For - * non-linux platforms, error processing is not used/enabled currently. + * messages from the queue. */ -static bool process_errors(grpc_tcp* tcp) { +static void process_errors(grpc_tcp* tcp) { while (true) { struct iovec iov; iov.iov_base = nullptr; @@ -719,10 +717,10 @@ static bool process_errors(grpc_tcp* tcp) { } while (r < 0 && saved_errno == EINTR); if (r == -1 && saved_errno == EAGAIN) { - return true; /* No more errors to process */ + return; /* No more errors to process */ } if (r == -1) { - return false; + return; } if (grpc_tcp_trace.enabled()) { if ((msg.msg_flags & MSG_CTRUNC) == 1) { @@ -732,10 +730,14 @@ static bool process_errors(grpc_tcp* tcp) { if (msg.msg_controllen == 0) { /* 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; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { + do { if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_TIMESTAMPING) { /* 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", 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); } } |