libsocket
|
Plain UDP sockets. More...
#include <inetserverdgram.hpp>
Public Member Functions | |
inet_dgram_server (const char *host, const char *port, int proto_osi3, int flags=0) | |
Create datagram socket and bind it. More... | |
inet_dgram_server (const string &host, const string &port, int proto_osi3, int flags=0) | |
Create datagram socket and bind it. More... | |
ssize_t | sndto (const void *buf, size_t len, const char *dsthost, const char *dstport, int sndto_flags=0) |
Send data to UDP peer. More... | |
ssize_t | sndto (const void *buf, size_t len, const string &dsthost, const string &dstport, int sndto_flags=0) |
Send data to UDP peer; C++ string host and port. More... | |
ssize_t | sndto (const string &buf, const string &dsthost, const string &dstport, int sndto_flags=0) |
Send data to UDP peer; using C++ strings only. More... | |
ssize_t | rcvfrom (void *buf, size_t len, char *srchost, size_t hostlen, char *srcport, size_t portlen, int rcvfrom_flags=0, bool numeric=false) |
Receives data from peer. More... | |
ssize_t | rcvfrom (void *buf, size_t len, string &srchost, string &srcport, int rcvfrom_flags=0, bool numeric=false) |
rcvfrom for C++ strings More... | |
ssize_t | rcvfrom (string &buf, string &srchost, string &srcport, int rcvfrom_flags=0, bool numeric=false) |
rcvfrom for C++ strings, implemented consistently More... | |
const string & | gethost (void) const |
const string & | getport (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 | |
string | host |
The address we're bound or connected to. More... | |
string | port |
The port we're bound or connected to. More... | |
int | proto |
Which internet protocol version we're using. More... | |
int | sfd |
sfd is the sockets API file descriptor More... | |
bool | is_nonblocking |
bool | close_on_destructor |
Private Member Functions | |
void | setup (const char *host, const char *port, int proto_osi3, int flags=0) |
Set up socket. NOT FOR EXTERNAL USE More... | |
void | setup (const string &host, const string &port, int proto_osi3, int flags=0) |
Set up socket. NOT FOR EXTERNAL USE More... | |
Plain UDP sockets.
Although called ..._server
, this class may also be used as client (UDP is symmetric). It has some special features, e.g. it's not possible to connect it.
Definition at line 49 of file inetserverdgram.hpp.
libsocket::inet_dgram_server::inet_dgram_server | ( | const char * | host, |
const char * | port, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Create datagram socket and bind it.
host | Bind address (Wildcard: "0.0.0.0"/"::") |
port | Bind port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 60 of file inetserverdgram.cpp.
libsocket::inet_dgram_server::inet_dgram_server | ( | const string & | host, |
const string & | port, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Create datagram socket and bind it.
host | Bind address (Wildcard: "0.0.0.0"/"::") |
port | Bind port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 73 of file inetserverdgram.cpp.
|
private |
Set up socket. NOT FOR EXTERNAL USE
bhost | Bind address (Wildcard: "0.0.0.0"/"::") |
bport | Bind port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 86 of file inetserverdgram.cpp.
|
private |
Set up socket. NOT FOR EXTERNAL USE
bhost | Bind address (Wildcard: "0.0.0.0"/"::") |
bport | Bind port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 109 of file inetserverdgram.cpp.
|
inherited |
Send data to UDP peer.
This is the counterpart to system's sendto(2)
. It sends data to a UDP peer.
buf | The data to be sent |
len | Length of transmission |
dsthost | Target host |
dstport | Target port |
sndto_flags | Flags for sendto(2) |
>0 | n bytes of data were sent. |
0 | Nothing was sent |
-1 | Socket is non-blocking and didn't send any data. |
Every error makes the function throw an exception.
Definition at line 207 of file inetdgram.cpp.
|
inherited |
Send data to UDP peer; C++ string host and port.
This is the counterpart to system's sendto(2)
. It sends data to a UDP peer.
buf | The data to be sent |
len | Length of transmission |
dsthost | Target host |
dstport | Target port |
sndto_flags | Flags for sendto(2) |
Every error makes the function throw an exception, except for EWOULDBLOCK.
-1 | Socket is non-blocking and didn't send any data. |
Definition at line 243 of file inetdgram.cpp.
|
inherited |
Send data to UDP peer; using C++ strings only.
This is the counterpart to system's sendto(2)
. It sends data to a UDP peer.
buf | The data to be sent |
dsthost | Target host |
dstport | Target port |
sndto_flags | Flags for sendto(2) |
Every error makes the function throw an exception.
-1 | Socket is non-blocking and didn't send any data. |
Definition at line 266 of file inetdgram.cpp.
|
inherited |
Receives data from peer.
rcvfrom is the equivalent to recvfrom(2)
.
buf | Target memory |
len | The size of the target memory |
hostbuf | Buffer to write the peer's hostname to |
hostbuflen | Its length |
portbuf | Like hostbuf , but for the remote port |
portbuflen | portbuf 's length |
rcvfrom_flags | Flags to be passed to recvfrom(2) |
numeric | If this is true , host and port are saved numerically (25 instead of "smtp") |
>0 | n bytes of data were read into buf . |
0 | Peer sent EOF |
-1 | Socket is non-blocking and returned without any data. |
Every error makes the function throw an exception.
Definition at line 79 of file inetdgram.cpp.
|
inherited |
rcvfrom for C++ strings
Works like rcvfrom()
, but takes C++ strings instead of pointers.
buf | Buffer to copy the received data to |
len | The buffer's length |
srchost | String to place the remote host's name to |
srcport | Like srchost but for the remote port |
rcvfrom_flags | Flags to be passed to recvfrom(2) |
numeric | If remote host and port should be saved numerically |
>0 | n bytes of data were read into buf . |
0 | Peer sent EOF |
-1 | Socket is non-blocking and returned without any data. |
Every error makes the function throw an exception.
Definition at line 122 of file inetdgram.cpp.
|
inherited |
rcvfrom for C++ strings, implemented consistently
Works like every other rcvfrom()
library call, but places the received memory to the C++ string buf
.
buf | The string where the received data should be stored at. Its length determines how much data will be stored; the library will not resize buf . |
srchost | String to place the remote host's name to |
srcport | Like srchost but for the remote port |
rcvfrom_flags | Flags to be passed to recvfrom(2) |
numeric | If remote host and port should be saved numerically |
>0 | n bytes of data were read into buf . |
0 | Peer sent EOF |
-1 | Socket is non-blocking and returned without any data. |
Every error makes the function throw an exception.
Definition at line 167 of file inetdgram.cpp.
|
inherited |
For sockets behaving as client: Returns the remote host. For sockets behaving as server: Returns the address bound to.
Definition at line 59 of file inetbase.cpp.
|
inherited |
For sockets behaving as client: Returns the remote port. For sockets behaving as server: Returns the port bound to.
Definition at line 65 of file inetbase.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.
|
protectedinherited |
The address we're bound or connected to.
Definition at line 55 of file inetbase.hpp.
|
protectedinherited |
The port we're bound or connected to.
Definition at line 57 of file inetbase.hpp.
|
protectedinherited |
Which internet protocol version we're using.
Definition at line 59 of file inetbase.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.