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

Class for UNIX datagram sockets. More...

#include <unixclientdgram.hpp>

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

Public Member Functions

 unix_dgram_client (int flags=0)
 Constructor with only socket() flags. More...
 
 unix_dgram_client (const char *path, int flags=0)
 Constructor setting the socket up. More...
 
 unix_dgram_client (const string &path, int flags=0)
 Constructor setting the socket up. More...
 
void setup (const char *path, int flags=0)
 Set a UNIX domain datagram socket up. More...
 
void connect (const char *path)
 Connect a UNIX datagram socket. More...
 
void connect (const string &path)
 Connect a UNIX datagram socket. More...
 
void deconnect (void)
 Disconnect a UNIX datagram socket. More...
 
ssize_t sndto (const void *buf, size_t length, const char *path, int sendto_flags=0)
 Send data to datagram socket. More...
 
ssize_t sndto (const void *buf, size_t length, const string &path, int sendto_flags=0)
 Send data to datagram socket. More...
 
ssize_t sndto (const string &buf, const string &path, int sendto_flags=0)
 Send data to datagram socket. More...
 
ssize_t rcvfrom (void *buf, size_t length, char *source, size_t source_len, int recvfrom_flags=0)
 Receive data and store the sender's address. More...
 
ssize_t rcvfrom (void *buf, size_t length, string &source, int recvfrom_flags=0)
 Receive data and store the sender's address. More...
 
ssize_t rcvfrom (string &buf, string &source, int recvfrom_flags=0)
 Receive data and store the sender's address. More...
 
string get_path (void)
 Returns the path we're bound or connected to. 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)
 
ssize_t snd (const void *buf, size_t len, int flags=0)
 Send data to connected socket. More...
 
ssize_t rcv (void *buf, size_t len, int flags=0)
 Receive data from a connected DGRAM socket. More...
 
bool getconn (void) const
 
bool is_connected (void) const
 

Protected Attributes

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

Detailed Description

Class for UNIX datagram sockets.

Definition at line 49 of file unixclientdgram.hpp.

Constructor & Destructor Documentation

◆ unix_dgram_client() [1/3]

libsocket::unix_dgram_client::unix_dgram_client ( int  flags = 0)

Constructor with only socket() flags.

Parameters
flagsFlags for socket(2)

Definition at line 82 of file unixclientdgram.cpp.

Here is the call graph for this function:

◆ unix_dgram_client() [2/3]

libsocket::unix_dgram_client::unix_dgram_client ( const char *  path,
int  flags = 0 
)

Constructor setting the socket up.

This constructor binds the socket to the given path.

Parameters
pathBind path.
flagsFlags for socket(2)

Definition at line 94 of file unixclientdgram.cpp.

Here is the call graph for this function:

◆ unix_dgram_client() [3/3]

libsocket::unix_dgram_client::unix_dgram_client ( const string &  path,
int  flags = 0 
)

Constructor setting the socket up.

This constructor binds the socket to the given path.

Parameters
pathBind path.
flagsFlags for socket(2)

Definition at line 106 of file unixclientdgram.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ setup()

void libsocket::unix_dgram_client::setup ( const char *  path,
int  flags = 0 
)

Set a UNIX domain datagram socket up.

Parameters
pathThe path to bind this socket to
flagsFlags for socket(2)

Definition at line 58 of file unixclientdgram.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect() [1/2]

void libsocket::unix_dgram_client::connect ( const char *  path)

Connect a UNIX datagram socket.

This function connects a datagram socket; connect(2) says the following about this:

If the socket sockfd is of type SOCK_DGRAM then addr is the address to

which datagrams are sent by default, and the only address from which datagrams are received.

Parameters
pathThe path of the socket to connect this socket to.

Definition at line 122 of file unixclientdgram.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect() [2/2]

void libsocket::unix_dgram_client::connect ( const string &  path)

Connect a UNIX datagram socket.

This function connects a datagram socket; connect(2) says the following about this:

If the socket sockfd is of type SOCK_DGRAM then addr is the address to

which datagrams are sent by default, and the only address from which datagrams are received.

Parameters
pathThe path of the socket to connect this socket to.

Definition at line 150 of file unixclientdgram.cpp.

Here is the call graph for this function:

◆ deconnect()

void libsocket::unix_dgram_client::deconnect ( void  )

Disconnect a UNIX datagram socket.

Disconnects a previously connected socket.

Definition at line 158 of file unixclientdgram.cpp.

Here is the call graph for this function:

◆ sndto() [1/3]

ssize_t libsocket::unix_dgram::sndto ( const void *  buf,
size_t  length,
const char *  path,
int  sendto_flags = 0 
)
inherited

Send data to datagram socket.

Parameters
bufPointer to data.
lengthLength of buf
pathPath of destination
sendto_flagsFlags for sendto(2)
Returns
How many bytes were sent. Returns -1 if the socket was created with SOCK_NONBLOCK and errno is EWOULDBLOCK.

Definition at line 59 of file unixdgram.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sndto() [2/3]

ssize_t libsocket::unix_dgram::sndto ( const void *  buf,
size_t  length,
const string &  path,
int  sendto_flags = 0 
)
inherited

Send data to datagram socket.

Parameters
bufPointer to data.
lengthLength of buf
pathPath of destination
sendto_flagsFlags for sendto(2)
Returns
How many bytes were sent. Returns -1 if the socket was created with SOCK_NONBLOCK and errno is EWOULDBLOCK.

Definition at line 91 of file unixdgram.cpp.

Here is the call graph for this function:

◆ sndto() [3/3]

ssize_t libsocket::unix_dgram::sndto ( const string &  buf,
const string &  path,
int  sendto_flags = 0 
)
inherited

Send data to datagram socket.

Parameters
bufPointer to data.
pathPath of destination
sendto_flagsFlags for sendto(2)
Returns
How many bytes were sent. Returns -1 if the socket was created with SOCK_NONBLOCK and errno is EWOULDBLOCK.

Definition at line 106 of file unixdgram.cpp.

Here is the call graph for this function:

◆ rcvfrom() [1/3]

ssize_t libsocket::unix_dgram::rcvfrom ( void *  buf,
size_t  length,
char *  source,
size_t  source_len,
int  recvfrom_flags = 0 
)
inherited

Receive data and store the sender's address.

Parameters
bufReceive buffer
lengthLength of buf
sourceBuffer for sender's path
source_lensource's length
recvfrom_flagsFlags for recvfrom(2)
Returns
How many bytes were received. Returns -1 if the socket was created with SOCK_NONBLOCK and errno is EWOULDBLOCK.

Definition at line 124 of file unixdgram.cpp.

Here is the call graph for this function:

◆ rcvfrom() [2/3]

ssize_t libsocket::unix_dgram::rcvfrom ( void *  buf,
size_t  length,
string &  source,
int  recvfrom_flags = 0 
)
inherited

Receive data and store the sender's address.

Parameters
bufReceive buffer
lengthLength of buf
sourceBuffer for sender's path. The path is truncated to source.size() characters.
recvfrom_flagsFlags for recvfrom(2)
Returns
How many bytes were received. Returns -1 if the socket was created with SOCK_NONBLOCK and errno is EWOULDBLOCK.

Definition at line 159 of file unixdgram.cpp.

Here is the call graph for this function:

◆ rcvfrom() [3/3]

ssize_t libsocket::unix_dgram::rcvfrom ( string &  buf,
string &  source,
int  recvfrom_flags = 0 
)
inherited

Receive data and store the sender's address.

Parameters
bufReceive buffer. The data is truncated to buf.size() characters.
sourceBuffer for sender's path. The path is truncated to source.size() characters.
recvfrom_flagsFlags for recvfrom(2)
Returns
How many bytes were received. Returns -1 if the socket was created with SOCK_NONBLOCK and errno is EWOULDBLOCK.

Definition at line 208 of file unixdgram.cpp.

Here is the call graph for this function:

◆ get_path()

string libsocket::unix_socket::get_path ( void  )
inherited

Returns the path we're bound or connected to.

Definition at line 50 of file unixbase.cpp.

◆ destroy()

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

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
inherited

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
inherited

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)
inlineinherited

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.

◆ snd()

ssize_t libsocket::dgram_client_socket::snd ( const void *  buf,
size_t  len,
int  flags = 0 
)
inherited

Send data to connected socket.

Parameters
bufPointer to the data
lenThe length of the buffer
flagsFlags for send(2)
Return values
nn bytes were sent
<0An error occurred.

Definition at line 135 of file dgramclient.cpp.

◆ rcv()

ssize_t libsocket::dgram_client_socket::rcv ( void *  buf,
size_t  len,
int  flags = 0 
)
inherited

Receive data from a connected DGRAM socket.

If a datagram socket is connected, this function may be called to receive data sent from the host connected to.

Parameters
bufArea to write the data to
lenHow many data we want to receive
flagsFlags to be passed to recv(2)
Return values
>0n bytes were received.
00 bytes were received. (EOF?)
-1Something went wrong.

Definition at line 73 of file dgramclient.cpp.

◆ getconn()

bool libsocket::dgram_client_socket::getconn ( void  ) const
inherited
Deprecated:
(use is_connected())

Look up if socket is connected.

Definition at line 198 of file dgramclient.cpp.

◆ is_connected()

bool libsocket::dgram_client_socket::is_connected ( void  ) const
inherited

Returns true if the socket is in a connected state.

Definition at line 203 of file dgramclient.cpp.

Member Data Documentation

◆ _path

string libsocket::unix_socket::_path
protectedinherited

The path we're connected (client stream) or bound (server stream, server datagram)

Definition at line 55 of file unixbase.hpp.

◆ sfd

int libsocket::socket::sfd
protectedinherited

sfd is the sockets API file descriptor

Definition at line 74 of file socket.hpp.

◆ close_on_destructor

bool libsocket::socket::close_on_destructor
protectedinherited

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.

◆ connected

bool libsocket::dgram_client_socket::connected
protectedinherited

Stores the connection state of the socket so other functions in this class can check if the socket is connected. The connection() method itself is implemented in derived classes, e.g. inet_dgram_client

Definition at line 55 of file dgramclient.hpp.


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