Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
sockpp::datagram_socket Class Reference

#include <datagram_socket.h>

Inheritance diagram for sockpp::datagram_socket:
sockpp::socket sockpp::datagram_socket_tmpl< ADDR >

Public Member Functions

 datagram_socket ()
 
 datagram_socket (socket_t handle)
 
 datagram_socket (const sock_address &addr)
 
 datagram_socket (datagram_socket &&other)
 
datagram_socketoperator= (datagram_socket &&rhs)
 
bool connect (const sock_address &addr)
 
ssize_t send_to (const void *buf, size_t n, int flags, const sock_address &addr)
 
ssize_t send_to (const std::string &s, int flags, const sock_address &addr)
 
ssize_t send_to (const void *buf, size_t n, const sock_address &addr)
 
ssize_t send_to (const std::string &s, const sock_address &addr)
 
ssize_t send (const void *buf, size_t n, int flags=0)
 
ssize_t send (const std::string &s, int flags=0)
 
ssize_t recv_from (void *buf, size_t n, int flags, sock_address *srcAddr=nullptr)
 
ssize_t recv_from (void *buf, size_t n, sock_address *srcAddr=nullptr)
 
ssize_t recv (void *buf, size_t n, int flags=0)
 
- Public Member Functions inherited from sockpp::socket
 socket ()
 
 socket (socket_t h)
 
 socket (socket &&sock) noexcept
 
virtual ~socket ()
 
bool is_open () const
 
bool operator! () const
 
 operator bool () const
 
socket_t handle () const
 
virtual sa_family_t family () const
 
socket clone () const
 
void clear (int val=0)
 
socket_t release ()
 
void reset (socket_t h=INVALID_SOCKET)
 
socketoperator= (socket &&sock) noexcept
 
bool bind (const sock_address &addr)
 
sock_address_any address () const
 
sock_address_any peer_address () const
 
bool get_option (int level, int optname, void *optval, socklen_t *optlen) const
 
template<typename T >
bool get_option (int level, int optname, T *val) const
 
bool set_option (int level, int optname, const void *optval, socklen_t optlen)
 
template<typename T >
bool set_option (int level, int optname, const T &val)
 
bool set_non_blocking (bool on=true)
 
int last_error () const
 
std::string last_error_str () const
 
bool shutdown (int how=SHUT_RDWR)
 
bool close ()
 

Static Public Attributes

static constexpr int COMM_TYPE = SOCK_DGRAM
 

Static Protected Member Functions

static socket_t create_handle (int domain)
 
- Static Protected Member Functions inherited from sockpp::socket
static int get_last_error ()
 

Additional Inherited Members

- Static Public Member Functions inherited from sockpp::socket
static void initialize ()
 
static void destroy ()
 
static socket create (int domain, int type, int protocol=0)
 
static std::tuple< socket, socketpair (int domain, int type, int protocol=0)
 
static std::string error_str (int errNum)
 
- Protected Member Functions inherited from sockpp::socket
bool close_on_err ()
 
void set_last_error ()
 
template<typename T >
check_ret (T ret) const
 
template<typename T >
bool check_ret_bool (T ret) const
 
socket_t check_socket (socket_t ret) const
 
bool check_socket_bool (socket_t ret) const
 

Detailed Description

Base class for datagram sockets.

Datagram sockets are normally connectionless, where each packet is individually routed and delivered.

Constructor & Destructor Documentation

◆ datagram_socket() [1/4]

sockpp::datagram_socket::datagram_socket ( )
inline

Creates an uninitialized datagram socket.

◆ datagram_socket() [2/4]

sockpp::datagram_socket::datagram_socket ( socket_t handle)
inlineexplicit

Creates a datagram socket from an existing OS socket handle and claims ownership of the handle.

Parameters
handleA socket handle from the operating system.

◆ datagram_socket() [3/4]

sockpp::datagram_socket::datagram_socket ( const sock_address & addr)
explicit

Creates a UDP socket and binds it to the address.

Parameters
addrThe address to bind.

◆ datagram_socket() [4/4]

sockpp::datagram_socket::datagram_socket ( datagram_socket && other)
inline

Move constructor.

Parameters
otherThe other socket to move to this one

Member Function Documentation

◆ connect()

bool sockpp::datagram_socket::connect ( const sock_address & addr)
inline

Connects the socket to the remote address. In the case of datagram sockets, this does not create an actual connection, but rather specifies the address to which datagrams are sent by default and the only address from which packets are received.

Parameters
addrThe address on which to "connect".
Returns
true on success, false on failure

◆ operator=()

datagram_socket & sockpp::datagram_socket::operator= ( datagram_socket && rhs)
inline

Move assignment.

Parameters
rhsThe other socket to move into this one.
Returns
A reference to this object.

◆ recv()

ssize_t sockpp::datagram_socket::recv ( void * buf,
size_t n,
int flags = 0 )
inline

Receives a message on the socket.

Parameters
bufBuffer to get the incoming data.
nThe number of bytes to read.
flagsThe option bit flags. See send(2).
Returns
The number of bytes read or -1 on error.

◆ recv_from() [1/2]

ssize_t sockpp::datagram_socket::recv_from ( void * buf,
size_t n,
int flags,
sock_address * srcAddr = nullptr )

Receives a message on the socket.

Parameters
bufBuffer to get the incoming data.
nThe number of bytes to read.
flagsThe option bit flags. See send(2).
srcAddrReceives the address of the peer that sent the message
Returns
The number of bytes read or -1 on error.

◆ recv_from() [2/2]

ssize_t sockpp::datagram_socket::recv_from ( void * buf,
size_t n,
sock_address * srcAddr = nullptr )
inline

Receives a message on the socket.

Parameters
bufBuffer to get the incoming data.
nThe number of bytes to read.
srcAddrReceives the address of the peer that sent the message
Returns
The number of bytes read or -1 on error.

◆ send() [1/2]

ssize_t sockpp::datagram_socket::send ( const std::string & s,
int flags = 0 )
inline

Sends a string to the socket at the default address. The socket should be connected before calling this

Parameters
sThe string to send.
flagsThe option bit flags. See send(2).
Returns
zero on success, -1 on failure.

◆ send() [2/2]

ssize_t sockpp::datagram_socket::send ( const void * buf,
size_t n,
int flags = 0 )
inline

Sends a message to the socket at the default address. The socket should be connected before calling this.

Parameters
bufThe date to send.
nThe number of bytes in the data buffer.
flagsThe option bit flags. See send(2).
Returns
zero on success, -1 on failure.

◆ send_to() [1/4]

ssize_t sockpp::datagram_socket::send_to ( const std::string & s,
const sock_address & addr )
inline

Sends a string to another socket.

Parameters
sThe string to send.
addrThe remote destination of the data.
Returns
the number of bytes sent on success or, -1 on failure.

◆ send_to() [2/4]

ssize_t sockpp::datagram_socket::send_to ( const std::string & s,
int flags,
const sock_address & addr )
inline

Sends a string to the socket at the specified address.

Parameters
sThe string to send.
flagsThe flags. See send(2).
addrThe remote destination of the data.
Returns
the number of bytes sent on success or, -1 on failure.

◆ send_to() [3/4]

ssize_t sockpp::datagram_socket::send_to ( const void * buf,
size_t n,
const sock_address & addr )
inline

Sends a message to another socket.

Parameters
bufThe data to send.
nThe number of bytes in the data buffer.
addrThe remote destination of the data.
Returns
the number of bytes sent on success or, -1 on failure.

◆ send_to() [4/4]

ssize_t sockpp::datagram_socket::send_to ( const void * buf,
size_t n,
int flags,
const sock_address & addr )
inline

Sends a message to the socket at the specified address.

Parameters
bufThe data to send.
nThe number of bytes in the data buffer.
flagsThe flags. See send(2).
addrThe remote destination of the data.
Returns
the number of bytes sent on success or, -1 on failure.

Member Data Documentation

◆ COMM_TYPE

int sockpp::datagram_socket::COMM_TYPE = SOCK_DGRAM
staticconstexpr

The socket 'type' for communications semantics.


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