#include <socket.h>
Inheritance diagram for more::io::socket:
errno
from the last error. More...
Using the default ctor, a socket is initially in state_unbound
. The scenario then depends on whether the program is a client or a server.
If the program is a server, it will typically call the bind
member function to associate to a port, and then listen
to indicate that it is ready to accept connections from clients. The socket will then be in state_listening
. Requests from clients are processed by constructing new sockets from the return value of accept
. The new sockets will be in state_accepted
, whereas the socket from which the connections are popped will stay in state_listening
.
A client program simply calls connect
to establish a connection with the server. It will then enter state_connected
.
Some members returns false
in case of failure. This will also store the corresponding error condition internally, which can be probed with errno()
. Member functions will throw a logic error if it detects an error from the callers side, i.e. not originating from the unpredictable outside world.
|
|
|
Construct a socket in not attached to any port. |
|
Construct a socket from the return value of accept.
The socket will be in |
|
Destruction which closes the socket.
|
|
Pop a connection off a listening socket.
The return type can be used as an argument to the ctor or |
|
Returns the address of the socket.
|
|
Bind a socket to a local IP V4 or V6 address.
After binding to the address, you may call |
|
Close the socket. Normally you don't need to call this, see open(). |
|
Connect a socket to a remote IP V4 or V6 address.
If successful, return true and change to |
|
Return true iff the socket can be read from or written to. This is the case iff it is in the connected or the accepted state. |
|
Signal that we are ready to accept connections.
If successful switch to |
|
Return the state of the socket.
|
|
Returns the C
This can be passed to |
|
|