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