• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2022 Google, Inc.
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 "hal/syscall_wrapper_impl.h"
20 
21 #include <errno.h>
22 #include <unistd.h>
23 
24 namespace bluetooth {
25 namespace hal {
26 
Socket(int domain,int type,int protocol)27 int SyscallWrapperImpl::Socket(int domain, int type, int protocol) {
28   int ret = socket(domain, type, protocol);
29   errno_ = errno;
30   return ret;
31 }
32 
Bind(int fd,const struct sockaddr * addr,socklen_t len)33 int SyscallWrapperImpl::Bind(int fd, const struct sockaddr* addr, socklen_t len) {
34   int ret = bind(fd, addr, len);
35   errno_ = errno;
36   return ret;
37 }
38 
Connect(int fd,const struct sockaddr * addr,socklen_t len)39 int SyscallWrapperImpl::Connect(int fd, const struct sockaddr* addr, socklen_t len) {
40   int ret = connect(fd, addr, len);
41   errno_ = errno;
42   return ret;
43 }
44 
Send(int fd,const void * buf,size_t n,int flags)45 ssize_t SyscallWrapperImpl::Send(int fd, const void* buf, size_t n, int flags) {
46   int ret = send(fd, buf, n, flags);
47   errno_ = errno;
48   return ret;
49 }
50 
Recv(int fd,void * buf,size_t n,int flags)51 ssize_t SyscallWrapperImpl::Recv(int fd, void* buf, size_t n, int flags) {
52   int ret = recv(fd, buf, n, flags);
53   errno_ = errno;
54   return ret;
55 }
56 
Setsockopt(int fd,int level,int optname,const void * optval,socklen_t optlen)57 int SyscallWrapperImpl::Setsockopt(int fd, int level, int optname, const void* optval, socklen_t optlen) {
58   int ret = setsockopt(fd, level, optname, optval, optlen);
59   errno_ = errno;
60   return ret;
61 }
62 
Listen(int fd,int n)63 int SyscallWrapperImpl::Listen(int fd, int n) {
64   int ret = listen(fd, n);
65   errno_ = errno;
66   return ret;
67 }
68 
Accept(int fd,struct sockaddr * addr,socklen_t * addr_len,int flags)69 int SyscallWrapperImpl::Accept(int fd, struct sockaddr* addr, socklen_t* addr_len, int flags) {
70   int ret = accept4(fd, addr, addr_len, flags);
71   errno_ = errno;
72   return ret;
73 }
74 
Write(int fd,const void * buf,size_t count)75 ssize_t SyscallWrapperImpl::Write(int fd, const void* buf, size_t count) {
76   ssize_t ret = write(fd, buf, count);
77   errno_ = errno;
78   return ret;
79 }
80 
Close(int fd)81 int SyscallWrapperImpl::Close(int fd) {
82   int ret = close(fd);
83   errno_ = errno;
84   return ret;
85 }
86 
Pipe2(int * pipefd,int flags)87 int SyscallWrapperImpl::Pipe2(int* pipefd, int flags) {
88   int ret = pipe2(pipefd, flags);
89   errno_ = errno;
90   return ret;
91 }
92 
GetErrno() const93 int SyscallWrapperImpl::GetErrno() const {
94   return errno_;
95 }
96 
FDSet(int fd,fd_set * set)97 void SyscallWrapperImpl::FDSet(int fd, fd_set* set) {
98   FD_SET(fd, set);
99 }
100 
FDClr(int fd,fd_set * set)101 void SyscallWrapperImpl::FDClr(int fd, fd_set* set) {
102   FD_CLR(fd, set);
103 }
104 
FDIsSet(int fd,fd_set * set)105 bool SyscallWrapperImpl::FDIsSet(int fd, fd_set* set) {
106   return FD_ISSET(fd, set);
107 }
108 
FDZero(fd_set * set)109 void SyscallWrapperImpl::FDZero(fd_set* set) {
110   FD_ZERO(set);
111 }
112 
Select(int __nfds,fd_set * __readfds,fd_set * __writefds,fd_set * __exceptfds,struct timeval * __timeout)113 int SyscallWrapperImpl::Select(
114     int __nfds, fd_set* __readfds, fd_set* __writefds, fd_set* __exceptfds, struct timeval* __timeout) {
115   int ret = select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
116   errno_ = errno;
117   return ret;
118 }
119 
120 }  // namespace hal
121 }  // namespace bluetooth
122