libsocket
|
Provides TCP/IP client sockets. This class is the most used socket class in libsocket++. It provides plain TCP client sockets which can be used for almost everything. More...
#include <inetclientstream.hpp>
Public Member Functions | |
inet_stream (void) | |
Void constructor; call connect() before using the socket! More... | |
inet_stream (const char *dsthost, const char *dstport, int proto_osi3, int flags=0) | |
Connecting constructor. More... | |
inet_stream (const string &dsthost, const string &dstport, int proto_osi3, int flags=0) | |
Connecting constructor. More... | |
void | connect (const char *dsthost, const char *dstport, int proto_osi3, int flags=0) |
Set up socket if not already done. More... | |
void | connect (const string &dsthost, const string &dstport, int proto_osi3, int flags=0) |
Set up socket if not already done. 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 socket. More... | |
ssize_t | rcv (void *buf, size_t len, int flags=0) |
Receive data from socket. More... | |
void | shutdown (int method=LIBSOCKET_WRITE) |
Shut a socket down. More... | |
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 | shut_rd |
bool | shut_wr |
Friends | |
class | inet_stream_server |
Provides TCP/IP client sockets. This class is the most used socket class in libsocket++. It provides plain TCP client sockets which can be used for almost everything.
Definition at line 54 of file inetclientstream.hpp.
libsocket::inet_stream::inet_stream | ( | void | ) |
Void constructor; call connect() before using the socket!
Definition at line 55 of file inetclientstream.cpp.
libsocket::inet_stream::inet_stream | ( | const char * | dsthost, |
const char * | dstport, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Connecting constructor.
Creates TCP/IP client socket and connects.
dsthost | Remote host |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 67 of file inetclientstream.cpp.
libsocket::inet_stream::inet_stream | ( | const string & | dsthost, |
const string & | dstport, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Connecting constructor.
Creates TCP/IP client socket and connects.
dsthost | Remote host |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 82 of file inetclientstream.cpp.
void libsocket::inet_stream::connect | ( | const char * | dsthost, |
const char * | dstport, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Set up socket if not already done.
Creates TCP/IP client socket and connects. Fails if the socket is already set up.
dsthost | Remote host |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 98 of file inetclientstream.cpp.
void libsocket::inet_stream::connect | ( | const string & | dsthost, |
const string & | dstport, | ||
int | proto_osi3, | ||
int | flags = 0 |
||
) |
Set up socket if not already done.
Creates TCP/IP client socket and connects. Fails if the socket is already set up.
dsthost | Remote host |
dstport | Remote port |
proto_osi3 | LIBSOCKET_IPv4 or LIBSOCKET_IPv6 or LIBSOCKET_BOTH |
flags | Flags for socket(2) |
Definition at line 132 of file inetclientstream.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 socket.
buf | Data to be sent |
len | Length of buf |
flags | Flags for send(2) . WARNING: Throws an exception if send() returns -1; this may be the case if the flag MSG_DONTWAIT is used. |
Definition at line 243 of file streamclient.cpp.
|
inherited |
Receive data from socket.
...and puts it in buf
.
buf | A writable memory buffer of length len |
len | Length of buf |
flags | Flags for recv(2) . WARNING: Throws an exception if recv() returns -1; this may be the case if the flag MSG_DONTWAIT is used. |
Definition at line 68 of file streamclient.cpp.
|
inherited |
Shut a socket down.
Shuts a socket down using shutdown(2)
.
method | LIBSOCKET_READ/LIBSOCKET_WRITE or an OR ed combination. |
Definition at line 279 of file streamclient.cpp.
|
friend |
inet_stream_server
is our friend so he may manipulate private members as sfd
when returning an instance (e.g. at accept()
)
Definition at line 67 of file inetclientstream.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.
|
protectedinherited |
If the socket was shut down for reading (-> no reads anymore)
Definition at line 54 of file streamclient.hpp.
|
protectedinherited |
If the socket was shut down for writing (-> no writes anymore)
Definition at line 56 of file streamclient.hpp.