mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | List of all members
UnixSyscalls Class Reference

#include <UnixSyscalls.hpp>

Collaboration diagram for UnixSyscalls:
Collaboration graph

Public Member Functions

TEST_VIRTUAL ~UnixSyscalls ()=default
 
TEST_VIRTUAL int bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 
TEST_VIRTUAL int close (int fd)
 
TEST_VIRTUAL int ioctl (int fd, unsigned long request, void *argp)
 
TEST_VIRTUAL int open (const char *pathname, int flags)
 
TEST_VIRTUAL int poll (struct pollfd *fds, nfds_t nfds, int timeout)
 
TEST_VIRTUAL ssize_t read (int fd, void *buf, size_t count)
 
TEST_VIRTUAL ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
 
TEST_VIRTUAL ssize_t sendto (int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 
TEST_VIRTUAL int socket (int domain, int type, int protocol)
 
TEST_VIRTUAL int tcgetattr (int fd, struct termios *termios_p)
 
TEST_VIRTUAL int tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
 
TEST_VIRTUAL ssize_t write (int fd, const void *buf, size_t count)
 

Detailed Description

A thin wrapper around Unix system calls.

The purpose of this is to allow system calls to be mocked during testing.

See the following man pages for documentation:

Definition at line 54 of file UnixSyscalls.hpp.

Constructor & Destructor Documentation

◆ ~UnixSyscalls()

TEST_VIRTUAL UnixSyscalls::~UnixSyscalls ( )
default

Member Function Documentation

◆ bind()

int UnixSyscalls::bind ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Bind a name to a socket.

See man 2 bind for documentation.

Parameters
sockfdSocket file descriptor.
addrAddress to assign to socket.
addrlenSize of address structure in bytes.

Definition at line 40 of file UnixSyscalls.cpp.

◆ close()

int UnixSyscalls::close ( int  fd)

Close a file descriptor.

See man 2 close for documentation.

Parameters
fdThe file descriptor to close.

Definition at line 54 of file UnixSyscalls.cpp.

◆ ioctl()

int UnixSyscalls::ioctl ( int  fd,
unsigned long  request,
void *  argp 
)

Control device.

See man 2 ioctl for documentation.

Parameters
fdThe file descriptor to control.
requestRequest code, defined in <sys/ioctl.h>
argpPointer to input/output, dependent on request code.

Definition at line 69 of file UnixSyscalls.cpp.

◆ open()

int UnixSyscalls::open ( const char *  pathname,
int  flags 
)

Open and possibly create a file.

See man 2 open for documentation.

Definition at line 80 of file UnixSyscalls.cpp.

◆ poll()

int UnixSyscalls::poll ( struct pollfd *  fds,
nfds_t  nfds,
int  timeout 
)

Wait for some event on a file descriptor.

See man 2 poll for documentation.

Parameters
fdsFile descriptor event structures.
nfdsNumber of file descriptor event structures.
timeoutThe timeout in milliseconds.

Definition at line 95 of file UnixSyscalls.cpp.

◆ read()

ssize_t UnixSyscalls::read ( int  fd,
void *  buf,
size_t  count 
)

Read from a file descriptor.

See man 2 read for documentation.

Definition at line 106 of file UnixSyscalls.cpp.

◆ recvfrom()

ssize_t UnixSyscalls::recvfrom ( int  sockfd,
void *  buf,
size_t  len,
int  flags,
struct sockaddr *  src_addr,
socklen_t *  addrlen 
)

Receive a message from a socket.

See man 2 recvfrom for documentation.

Parameters
sockfdSocket file descriptor to receive data on.
bufThe buffer to write the data into.
lenThe length of the buffer.
flagsOption flags.
src_addrSource address buffer.
addrlenBefore call, length of source address buffer. After call, actual length of address data.
Returns
The number of bytes written to or -1 if an error occurred.

Definition at line 126 of file UnixSyscalls.cpp.

◆ sendto()

ssize_t UnixSyscalls::sendto ( int  sockfd,
const void *  buf,
size_t  len,
int  flags,
const struct sockaddr *  dest_addr,
socklen_t  addrlen 
)

Send a message on a socket.

See man 2 sendto for documentation.

Definition at line 139 of file UnixSyscalls.cpp.

◆ socket()

int UnixSyscalls::socket ( int  domain,
int  type,
int  protocol 
)

Create an endpoint for communication.

See man 2 socket for documentation.

Parameters
domainProtocol family to use for communication.
typeSocket type.
protocolProtocol to use for socket.

Definition at line 156 of file UnixSyscalls.cpp.

◆ tcgetattr()

int UnixSyscalls::tcgetattr ( int  fd,
struct termios *  termios_p 
)

Get serial port parameters associated with the given file descriptor.

See man 2 termios for documentation.

Definition at line 167 of file UnixSyscalls.cpp.

◆ tcsetattr()

int UnixSyscalls::tcsetattr ( int  fd,
int  optional_actions,
const struct termios *  termios_p 
)

Set serial port parameters for given file descriptor.

See man 2 termios for documentation.

Definition at line 178 of file UnixSyscalls.cpp.

◆ write()

ssize_t UnixSyscalls::write ( int  fd,
const void *  buf,
size_t  count 
)

Write to a file descriptor.

See man 2 write for documentation.

Definition at line 190 of file UnixSyscalls.cpp.


The documentation for this class was generated from the following files: