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

Provides an interface to UNIX-domain datagram sockets. More...

#include <unixserverdgram.hpp>

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

Public Member Functions

 unix_dgram_server (void)
 Void constructor. More...
 
 unix_dgram_server (const char *bindpath, int socket_flags=0)
 Constructs and binds a socket. More...
 
 unix_dgram_server (const string &bindpath, int socket_flags=0)
 Constructs and binds a socket. More...
 
void setup (const char *bindpath, int socket_flags=0)
 Binds a socket. More...
 
void setup (const string &bindpath, int socket_flags=0)
 Binds a 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)
 

Protected Attributes

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

Private Attributes

bool bound
 Shows if the socket is already bound (for setup routines) More...
 

Detailed Description

Provides an interface to UNIX-domain datagram sockets.

The difference to unix_dgram_client is that this class cannot be connected to another socket.

Definition at line 51 of file unixserverdgram.hpp.

Constructor & Destructor Documentation

◆ unix_dgram_server() [1/3]

libsocket::unix_dgram_server::unix_dgram_server ( void  )

Void constructor.

Definition at line 55 of file unixserverdgram.cpp.

◆ unix_dgram_server() [2/3]

libsocket::unix_dgram_server::unix_dgram_server ( const char *  bindpath,
int  socket_flags = 0 
)

Constructs and binds a socket.

Constructs a socket and binds it to bindpath. Then calls listen().

Parameters
bindpathBind path.
socket_flagsFlags for socket(2)

Definition at line 65 of file unixserverdgram.cpp.

Here is the call graph for this function:

◆ unix_dgram_server() [3/3]

libsocket::unix_dgram_server::unix_dgram_server ( const string &  bindpath,
int  socket_flags = 0 
)

Constructs and binds a socket.

Constructs a socket and binds it to bindpath. Then calls listen().

Parameters
bindpathBind path.
socket_flagsFlags for socket(2)

Definition at line 77 of file unixserverdgram.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ setup() [1/2]

void libsocket::unix_dgram_server::setup ( const char *  bindpath,
int  socket_flags = 0 
)

Binds a socket.

Binds a socket. (Also calls listen())

Parameters
bindpathBind path.
socket_flagsFlags for socket(2)

Definition at line 89 of file unixserverdgram.cpp.

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

◆ setup() [2/2]

void libsocket::unix_dgram_server::setup ( const string &  bindpath,
int  socket_flags = 0 
)

Binds a socket.

Binds a socket. (Also calls listen())

Parameters
bindpathBind path.
socket_flagsFlags for socket(2)

Definition at line 115 of file unixserverdgram.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.

Member Data Documentation

◆ bound

bool libsocket::unix_dgram_server::bound
private

Shows if the socket is already bound (for setup routines)

Definition at line 53 of file unixserverdgram.hpp.

◆ _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.


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