danzh | 5887951 | 2020-06-08 12:25:12 -0700 | [diff] [blame] | 1 | // Copyright (c) 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_syscall_wrapper.h" |
| 6 | |
| 7 | #include <atomic> |
| 8 | #include <cerrno> |
| 9 | |
| 10 | namespace quic { |
| 11 | namespace { |
| 12 | std::atomic<QuicSyscallWrapper*> global_syscall_wrapper(new QuicSyscallWrapper); |
| 13 | } // namespace |
| 14 | |
| 15 | ssize_t QuicSyscallWrapper::Sendmsg(int sockfd, const msghdr* msg, int flags) { |
| 16 | return ::sendmsg(sockfd, msg, flags); |
| 17 | } |
| 18 | |
| 19 | int QuicSyscallWrapper::Sendmmsg(int sockfd, |
| 20 | mmsghdr* msgvec, |
| 21 | unsigned int vlen, |
| 22 | int flags) { |
| 23 | #if defined(__linux__) && !defined(__ANDROID__) |
| 24 | return ::sendmmsg(sockfd, msgvec, vlen, flags); |
| 25 | #else |
| 26 | errno = ENOSYS; |
| 27 | return -1; |
| 28 | #endif |
| 29 | } |
| 30 | |
| 31 | QuicSyscallWrapper* GetGlobalSyscallWrapper() { |
| 32 | return global_syscall_wrapper.load(); |
| 33 | } |
| 34 | |
| 35 | void SetGlobalSyscallWrapper(QuicSyscallWrapper* wrapper) { |
| 36 | global_syscall_wrapper.store(wrapper); |
| 37 | } |
| 38 | |
| 39 | ScopedGlobalSyscallWrapperOverride::ScopedGlobalSyscallWrapperOverride( |
| 40 | QuicSyscallWrapper* wrapper_in_scope) |
| 41 | : original_wrapper_(GetGlobalSyscallWrapper()) { |
| 42 | SetGlobalSyscallWrapper(wrapper_in_scope); |
| 43 | } |
| 44 | |
| 45 | ScopedGlobalSyscallWrapperOverride::~ScopedGlobalSyscallWrapperOverride() { |
| 46 | SetGlobalSyscallWrapper(original_wrapper_); |
| 47 | } |
| 48 | |
| 49 | } // namespace quic |