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 #ifndef QUICHE_QUIC_CORE_QUIC_SYSCALL_WRAPPER_H_ 6 #define QUICHE_QUIC_CORE_QUIC_SYSCALL_WRAPPER_H_ 7 8 #include <sys/socket.h> 9 #include <sys/types.h> 10 11 #include "quiche/quic/platform/api/quic_export.h" 12 13 struct mmsghdr; 14 namespace quic { 15 16 // QuicSyscallWrapper is a pass-through proxy to the real syscalls. 17 class QUICHE_EXPORT QuicSyscallWrapper { 18 public: 19 virtual ~QuicSyscallWrapper() = default; 20 21 virtual ssize_t Sendmsg(int sockfd, const msghdr* msg, int flags); 22 23 virtual int Sendmmsg(int sockfd, mmsghdr* msgvec, unsigned int vlen, 24 int flags); 25 }; 26 27 // A global instance of QuicSyscallWrapper, used by some socket util functions. 28 QuicSyscallWrapper* GetGlobalSyscallWrapper(); 29 30 // Change the global QuicSyscallWrapper to |wrapper|, for testing. 31 void SetGlobalSyscallWrapper(QuicSyscallWrapper* wrapper); 32 33 // ScopedGlobalSyscallWrapperOverride changes the global QuicSyscallWrapper 34 // during its lifetime, for testing. 35 class QUICHE_EXPORT ScopedGlobalSyscallWrapperOverride { 36 public: 37 explicit ScopedGlobalSyscallWrapperOverride( 38 QuicSyscallWrapper* wrapper_in_scope); 39 ~ScopedGlobalSyscallWrapperOverride(); 40 41 private: 42 QuicSyscallWrapper* original_wrapper_; 43 }; 44 45 } // namespace quic 46 47 #endif // QUICHE_QUIC_CORE_QUIC_SYSCALL_WRAPPER_H_ 48