libsocket
|
Class for UNIX datagram sockets. More...
#include <unixclientdgram.hpp>
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 |
Class for UNIX datagram sockets.
Definition at line 49 of file unixclientdgram.hpp.
libsocket::unix_dgram_client::unix_dgram_client | ( | int | flags = 0 | ) |
Constructor with only socket()
flags.
flags | Flags for socket(2) |
Definition at line 82 of file unixclientdgram.cpp.
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.
path | Bind path. |
flags | Flags for socket(2) |
Definition at line 94 of file unixclientdgram.cpp.
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.
path | Bind path. |
flags | Flags for socket(2) |
Definition at line 106 of file unixclientdgram.cpp.
void libsocket::unix_dgram_client::setup | ( | const char * | path, |
int | flags = 0 |
||
) |
Set a UNIX domain datagram socket up.
path | The path to bind this socket to |
flags | Flags for socket(2) |
Definition at line 58 of file unixclientdgram.cpp.
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.
path | The path of the socket to connect this socket to. |
Definition at line 122 of file unixclientdgram.cpp.
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.
path | The path of the socket to connect this socket to. |
Definition at line 150 of file unixclientdgram.cpp.
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.
|
inherited |
Send data to datagram socket.
buf | Pointer to data. |
length | Length of buf |
path | Path of destination |
sendto_flags | Flags for sendto(2) |
Definition at line 59 of file unixdgram.cpp.
|
inherited |
Send data to datagram socket.
buf | Pointer to data. |
length | Length of buf |
path | Path of destination |
sendto_flags | Flags for sendto(2) |
Definition at line 91 of file unixdgram.cpp.
|
inherited |
Send data to datagram socket.
buf | Pointer to data. |
path | Path of destination |
sendto_flags | Flags for sendto(2) |
Definition at line 106 of file unixdgram.cpp.
|
inherited |
Receive data and store the sender's address.
buf | Receive buffer |
length | Length of buf |
source | Buffer for sender's path |
source_len | source 's length |
recvfrom_flags | Flags for recvfrom(2) |
Definition at line 124 of file unixdgram.cpp.
|
inherited |
Receive data and store the sender's address.
buf | Receive buffer |
length | Length of buf |
source | Buffer for sender's path. The path is truncated to source.size() characters. |
recvfrom_flags | Flags for recvfrom(2) |
Definition at line 159 of file unixdgram.cpp.
|
inherited |
Receive data and store the sender's address.
buf | Receive buffer. The data is truncated to buf.size() characters. |
source | Buffer for sender's path. The path is truncated to source.size() characters. |
recvfrom_flags | Flags for recvfrom(2) |
Definition at line 208 of file unixdgram.cpp.
|
inherited |
Returns the path we're bound or connected to.
Definition at line 50 of file unixbase.cpp.
|
virtualinherited |
Destroys a socket.
0 | Fine! |
<0 | Most likely the socket was already closed before. |
Definition at line 72 of file socket.cpp.
|
inherited |
Returns the socket file descriptor.
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.
|
inherited |
Set socket options on the underlying socket.
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.
|
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.
|
inherited |
Send data to connected socket.
buf | Pointer to the data |
len | The length of the buffer |
flags | Flags for send(2) |
n | n bytes were sent |
<0 | An error occurred. |
Definition at line 135 of file dgramclient.cpp.
|
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.
buf | Area to write the data to |
len | How many data we want to receive |
flags | Flags to be passed to recv(2) |
>0 | n bytes were received. |
0 | 0 bytes were received. (EOF?) |
-1 | Something went wrong. |
Definition at line 73 of file dgramclient.cpp.
|
inherited |
Look up if socket is connected.
Definition at line 198 of file dgramclient.cpp.
|
inherited |
Returns true if the socket is in a connected state.
Definition at line 203 of file dgramclient.cpp.
|
protectedinherited |
The path we're connected (client stream) or bound (server stream, server datagram)
Definition at line 55 of file unixbase.hpp.
|
protectedinherited |
sfd is the sockets API file descriptor
Definition at line 74 of file socket.hpp.
|
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.
|
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.