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 <grpc/support/port_platform.h> 16 17 #include "src/core/lib/iomgr/internal_errqueue.h" 18 19 #include <grpc/support/log.h> 20 21 #include "src/core/lib/iomgr/port.h" 22 23 #ifdef GRPC_POSIX_SOCKET_TCP 24 25 #include <errno.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <sys/utsname.h> 29 30 #include "src/core/lib/gprpp/strerror.h" 31 32 namespace grpc_core { 33 KernelSupportsErrqueue()34bool KernelSupportsErrqueue() { 35 static const bool errqueue_supported = []() { 36 #ifdef GRPC_LINUX_ERRQUEUE 37 // Both-compile time and run-time linux kernel versions should be at 38 // least 4.0.0 39 struct utsname buffer; 40 if (uname(&buffer) != 0) { 41 gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str()); 42 return false; 43 } 44 char* release = buffer.release; 45 if (release == nullptr) { 46 return false; 47 } 48 49 if (strtol(release, nullptr, 10) >= 4) { 50 return true; 51 } else { 52 gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled"); 53 } 54 #endif // GRPC_LINUX_ERRQUEUE 55 return false; 56 }(); 57 return errqueue_supported; 58 } 59 } // namespace grpc_core 60 61 #endif // GRPC_POSIX_SOCKET_TCP 62