libsocket
Public Member Functions | Protected Attributes | List of all members
libsocket::socket Class Reference

socket is the base class of every other libsocket++ object. More...

#include <socket.hpp>

Inheritance diagram for libsocket::socket:
Inheritance graph
[legend]

Public Member Functions

 socket (void)
 Constructor. Sets sfd to -1. More...
 
 socket (const socket &)=delete
 
 socket (socket &&)
 Move constructor. More...
 
virtual ~socket ()
 Destructor: closes socket. More...
 
virtual int destroy (void)
 Destroys a socket. More...
 
int getfd (void) const
 Returns the socket file descriptor. More...
 
int set_sock_opt (int level, int optname, const char *optval, socklen_t optlen) const
 Set socket options on the underlying socket. More...
 
void set_close_on_destructor (bool cod)
 

Protected Attributes

int sfd
 sfd is the sockets API file descriptor More...
 
bool is_nonblocking
 
bool close_on_destructor
 

Detailed Description

socket is the base class of every other libsocket++ object.

It provides the most important field: The sfd field holds the file descriptor for every socket.

Definition at line 71 of file socket.hpp.

Constructor & Destructor Documentation

◆ socket() [1/2]

libsocket::socket::socket ( void  )

Constructor. Sets sfd to -1.

Definition at line 45 of file socket.cpp.

◆ socket() [2/2]

libsocket::socket::socket ( socket &&  other)

Move constructor.

Definition at line 51 of file socket.cpp.

◆ ~socket()

libsocket::socket::~socket ( void  )
virtual

Destructor: closes socket.

Definition at line 59 of file socket.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ destroy()

int libsocket::socket::destroy ( void  )
virtual

Destroys a socket.

Return values
0Fine!
<0Most likely the socket was already closed before.

Definition at line 72 of file socket.cpp.

Here is the caller graph for this function:

◆ getfd()

int libsocket::socket::getfd ( void  ) const

Returns the socket file descriptor.

Returns
The socket file descriptor of the class.

getfd() is a getter you may use to obtain the file descriptor for raw operations on it. It's relatively uncritical as libsocket just wraps other syscalls and doesn't manipulate it using unusual ways.

Definition at line 91 of file socket.cpp.

◆ set_sock_opt()

int libsocket::socket::set_sock_opt ( int  level,
int  optname,
const char *  optval,
socklen_t  optlen 
) const

Set socket options on the underlying socket.

Returns
The return value of setsockopt(2).

Sets socket options using setsockopt(2). See setsockopt(2), tcp(7), udp(7), unix(7) for documentation on how to use this function.

Definition at line 101 of file socket.cpp.

◆ set_close_on_destructor()

void libsocket::socket::set_close_on_destructor ( bool  cod)
inline

close_on_destructor is true by default. If set to false, do not call close(2) on the underlying socket in the destructor.

Definition at line 95 of file socket.hpp.

Member Data Documentation

◆ sfd

int libsocket::socket::sfd
protected

sfd is the sockets API file descriptor

Definition at line 74 of file socket.hpp.

◆ close_on_destructor

bool libsocket::socket::close_on_destructor
protected

Default is true; if set to false, the file descriptor is not closed when the destructor is called.

Definition at line 78 of file socket.hpp.


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