libtasks Documentation  1.6
tasks::net::socket Class Reference

The socket class. More...

#include <socket.h>

Inheritance diagram for tasks::net::socket:
Collaboration diagram for tasks::net::socket:

Public Member Functions

 socket (int fd)
 
 socket (socket_type=socket_type::TCP)
 
bool udp () const
 
bool tcp () const
 
socket_type type () const
 
std::shared_ptr< struct
sockaddr_in > 
addr ()
 
void set_blocking ()
 Set the socket to blocking mode. More...
 
void bind (int port, std::string ip="")
 
void listen (std::string path, int queue_size=128)
 
void listen (int port, std::string ip="", int queue_size=128)
 
socket accept ()
 Accept new client connections. More...
 
void connect (std::string path)
 
void connect (std::string host, int port)
 
void shutdown ()
 Call shutdown on the fd. More...
 
std::streamsize write (const char *data, std::size_t len, int port=-1, std::string ip="")
 
std::streamsize read (char *data, std::size_t len)
 
- Public Member Functions inherited from io_base
 io_base ()
 
 io_base (int fd)
 
virtual ~io_base ()
 
int fd () const
 
virtual void close ()
 

Private Member Functions

void bind (int port, std::string ip, bool udp)
 
void init_sockaddr (int port, std::string ip="")
 

Private Attributes

socket_type m_type = socket_type::TCP
 
bool m_blocking = false
 
std::shared_ptr< struct
sockaddr_in > 
m_addr
 

Additional Inherited Members

- Protected Attributes inherited from io_base
int m_fd = -1
 

Detailed Description

The socket class.

Definition at line 35 of file socket.h.

Constructor & Destructor Documentation

tasks::net::socket::socket ( int  fd)
inline

Constructor

Parameters
fdUse fd for the socket object.

Definition at line 40 of file socket.h.

Here is the caller graph for this function:

tasks::net::socket::socket ( socket_type  type = socket_type::TCP)

Constructor

Parameters
socket_typeThe socket type. The default is socket_type::TCP for stream sockets (used for unix domain sockets too). For UDP sockets use socket_type::UDP.

Definition at line 23 of file socket.cpp.

Here is the call graph for this function:

Member Function Documentation

socket tasks::net::socket::accept ( )

Accept new client connections.

Definition at line 136 of file socket.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::shared_ptr<struct sockaddr_in> tasks::net::socket::addr ( )
inline
Returns
A pointer to the sockaddr_in struct.

Definition at line 58 of file socket.h.

Here is the caller graph for this function:

void tasks::net::socket::bind ( int  port,
std::string  ip = "" 
)

Bind for udp sockets. This method can be used to bind udp sockets. For tcp servers socket::listen(std::string path, int queue_size) or port, std::string ip, int queue_size) has to be called.

Parameters
portThe port.
ipThe ip address in dot notation (optional).

Definition at line 86 of file socket.cpp.

Here is the caller graph for this function:

void tasks::net::socket::bind ( int  port,
std::string  ip,
bool  udp 
)
private

Definition at line 90 of file socket.cpp.

Here is the call graph for this function:

void tasks::net::socket::connect ( std::string  path)

Connect to a domain socket.

Parameters
pathThe path to the socket file.

Definition at line 147 of file socket.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void tasks::net::socket::connect ( std::string  host,
int  port 
)

Connect via tcp.

Parameters
hostThe hostname or ip address in dot notation.
portThe port.

Definition at line 185 of file socket.cpp.

Here is the call graph for this function:

void tasks::net::socket::init_sockaddr ( int  port,
std::string  ip = "" 
)
private

Definition at line 119 of file socket.cpp.

Here is the caller graph for this function:

void tasks::net::socket::listen ( std::string  path,
int  queue_size = 128 
)

Listen for unix domain sockets.

Parameters
pathThe path to the socket file.
queue_sizeThe liste queue size. The default value is 128.

Definition at line 36 of file socket.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void tasks::net::socket::listen ( int  port,
std::string  ip = "",
int  queue_size = 128 
)
Parameters
portThe port.
ipThe ip address in dot notation (optional).
queue_sizeThe liste queue size. The default value is 128.

Definition at line 76 of file socket.cpp.

Here is the call graph for this function:

std::streamsize tasks::net::socket::read ( char *  data,
std::size_t  len 
)

Read data from a socket.

Parameters
dataA pointer to the destination data.
lenThe number of bytes to write.

Definition at line 251 of file socket.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void tasks::net::socket::set_blocking ( )
inline

Set the socket to blocking mode.

Definition at line 61 of file socket.h.

Here is the caller graph for this function:

void tasks::net::socket::shutdown ( )

Call shutdown on the fd.

Definition at line 218 of file socket.cpp.

Here is the caller graph for this function:

bool tasks::net::socket::tcp ( ) const
inline
Returns
True if the socket type is socket_type::TCP.

Definition at line 52 of file socket.h.

socket_type tasks::net::socket::type ( ) const
inline
Returns
The the socket type.

Definition at line 55 of file socket.h.

bool tasks::net::socket::udp ( ) const
inline
Returns
True if the socket type is socket_type::UDP.

Definition at line 49 of file socket.h.

Here is the caller graph for this function:

std::streamsize tasks::net::socket::write ( const char *  data,
std::size_t  len,
int  port = -1,
std::string  ip = "" 
)

Write data to the socket.

Parameters
dataA pointer to the source data.
lenThe number of bytes to write.
portAs UDP sockets are not connection based, the remote port has to be passed.
ipOptional ip in dot notation for UDP writes.

Definition at line 225 of file socket.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::shared_ptr<struct sockaddr_in> tasks::net::socket::m_addr
private

Definition at line 118 of file socket.h.

bool tasks::net::socket::m_blocking = false
private

Definition at line 117 of file socket.h.

socket_type tasks::net::socket::m_type = socket_type::TCP
private

Definition at line 116 of file socket.h.


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