libsocket
|
Represents a generic "client" datagram socket, i.e. a datagram socket which can be connected. More...
#include <dgramclient.hpp>
Public Member Functions | |
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 |
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 | |
bool | connected |
int | sfd |
sfd is the sockets API file descriptor More... | |
bool | is_nonblocking |
bool | close_on_destructor |
Friends | |
dgram_client_socket & | operator<< (dgram_client_socket &sock, const char *str) |
Send data to connected peer. More... | |
dgram_client_socket & | operator<< (dgram_client_socket &sock, const string &str) |
Send data to connected peer. More... | |
dgram_client_socket & | operator>> (dgram_client_socket &sock, string &dest) |
Receive data from connected datagram socket. More... | |
Represents a generic "client" datagram socket, i.e. a datagram socket which can be connected.
Definition at line 53 of file dgramclient.hpp.
ssize_t libsocket::dgram_client_socket::snd | ( | const void * | buf, |
size_t | len, | ||
int | flags = 0 |
||
) |
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.
ssize_t libsocket::dgram_client_socket::rcv | ( | void * | buf, |
size_t | len, | ||
int | flags = 0 |
||
) |
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.
bool libsocket::dgram_client_socket::getconn | ( | void | ) | const |
Look up if socket is connected.
Definition at line 198 of file dgramclient.cpp.
bool libsocket::dgram_client_socket::is_connected | ( | void | ) | const |
Returns true if the socket is in a connected state.
Definition at line 203 of file dgramclient.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.
|
friend |
Send data to connected peer.
Usage: socket << "Abcde";
Definition at line 155 of file dgramclient.cpp.
|
friend |
Send data to connected peer.
Usage: socket << "Abcde";
Definition at line 180 of file dgramclient.cpp.
|
friend |
Receive data from connected datagram socket.
If a datagram socket is connected, you may receive data from it using stream-like functions.
sock | The socket to receive data from |
dest | The string to write data to. This string has to be resized to the number of bytes you wish to receive. |
Definition at line 95 of file dgramclient.cpp.
|
protected |
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.
|
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.