Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / deps / grpc / src / core / lib / iomgr / internal_errqueue.cc
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #include <grpc/support/port_platform.h>
20
21 #include "src/core/lib/iomgr/port.h"
22
23 #include <grpc/impl/codegen/log.h>
24 #include "src/core/lib/iomgr/internal_errqueue.h"
25
26 #ifdef GRPC_POSIX_SOCKET_TCP
27
28 #include <errno.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <sys/utsname.h>
32
33 namespace grpc_core {
34 static bool errqueue_supported = false;
35
36 bool kernel_supports_errqueue() { return errqueue_supported; }
37
38 void grpc_errqueue_init() {
39 /* Both-compile time and run-time linux kernel versions should be at least 4.0.0
40  */
41 #ifdef GRPC_LINUX_ERRQUEUE
42   struct utsname buffer;
43   if (uname(&buffer) != 0) {
44     gpr_log(GPR_ERROR, "uname: %s", strerror(errno));
45     return;
46   }
47   char* release = buffer.release;
48   if (release == nullptr) {
49     return;
50   }
51
52   if (strtol(release, nullptr, 10) >= 4) {
53     errqueue_supported = true;
54   } else {
55     gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled");
56   }
57 #endif /* GRPC_LINUX_ERRQUEUE */
58 }
59 } /* namespace grpc_core */
60
61 #else
62
63 namespace grpc_core {
64 void grpc_errqueue_init() {}
65 } /* namespace grpc_core */
66
67 #endif /* GRPC_POSIX_SOCKET_TCP */