libsocket
|
Using UDP/IP easy as never before. Class for connectable datagram sockets in the INET domain. You may connect this sockets to permanently associate a peer to which all data is sent and from which all data is received when using the functions defined in class dgram_client_socket
More...
#include <inetclientdgram.hpp>
Public Member Functions | |
inet_dgram_client (int proto_osi3, int flags=0) | |
Create normal datagram socket (connectable). More... | |
inet_dgram_client (const char *dsthost, const char *dstport, int proto_osi3, int flags=0) | |
Create datagram socket and connect it immediately to the given host and port. More... | |
inet_dgram_client (const string &dsthost, const string &dstport, int proto_osi3, int flags=0) | |
Create datagram socket and connect it immediately to the given host and port. More... | |
void | connect (const char *dsthost, const char *dstport) |
Connect datagram socket. More... | |
void | connect (const string &dsthost, const string &dstport) |
Connect datagram socket. More... | |
void | deconnect (void) |
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) |
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 | 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 |
bool | connected |
Private Member Functions | |
void | setup (int proto_osi3, int flags=0) |
Set up normal datagram socket (connectable). [NOT FOR EXTERNAL USE]. More... | |
void | setup (const char *dsthost, const char *dstport, int proto_osi3, int flags=0) |
Set up datagram socket and connect it immediately to the given host and port. [NOT FOR EXTERNAL USE]. More... | |
void | setup (const string &dsthost, const string &dstport, int proto_osi3, int flags=0) |
Set up datagram socket and connect it immediately to the given host and port. [NOT FOR EXTERNAL USE]. More... | |
Using UDP/IP easy as never before. Class for connectable datagram sockets in the INET domain. You may connect this sockets to permanently associate a peer to which all data is sent and from which all data is received when using the functions defined in class dgram_client_socket
Definition at line 55 of file inetclientdgram.hpp.
libsocket::inet_dgram_client::inet_dgram_client | ( | int | proto_osi3, |
int | flags = 0 |
||
) |
Create normal datagram socket (connectable).
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) . |
Definition at line 69 of file inetclientdgram.cpp.
libsocket::inet_dgram_client::inet_dgram_client | ( | const char * | dsthost, |
const char * | dstport, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Create datagram socket and connect it immediately to the given host and port.
dsthost | Remote host name |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 82 of file inetclientdgram.cpp.
libsocket::inet_dgram_client::inet_dgram_client | ( | const string & | dsthost, |
const string & | dstport, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Create datagram socket and connect it immediately to the given host and port.
dsthost | Remote host name |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 96 of file inetclientdgram.cpp.
void libsocket::inet_dgram_client::connect | ( | const char * | dsthost, |
const char * | dstport | ||
) |
Connect datagram socket.
Connect a datagram socket to a remote peer so only its packets are received and all data written is sent to it.
dsthost | Destination host |
dstport | Destination port |
Definition at line 166 of file inetclientdgram.cpp.
void libsocket::inet_dgram_client::connect | ( | const string & | dsthost, |
const string & | dstport | ||
) |
Connect datagram socket.
Connect a datagram socket to a remote peer so only its packets are received and all data written is sent to it.
dsthost | Destination host |
dstport | Destination port |
Definition at line 192 of file inetclientdgram.cpp.
|
private |
Set up normal datagram socket (connectable). [NOT FOR EXTERNAL USE].
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) . |
Definition at line 108 of file inetclientdgram.cpp.
|
private |
Set up datagram socket and connect it immediately to the given host and port. [NOT FOR EXTERNAL USE].
dsthost | Remote host name |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 127 of file inetclientdgram.cpp.
|
private |
Set up datagram socket and connect it immediately to the given host and port. [NOT FOR EXTERNAL USE].
dsthost | Remote host name |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 152 of file inetclientdgram.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.
|
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 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.
|
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.