Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more::io::socket Struct Reference

A stream that can be attached to a socket. More...

#include <socket.h>

Inheritance diagram for more::io::socket:

Inheritance graph
[legend]
Collaboration diagram for more::io::socket:

Collaboration graph
[legend]
List of all members.

Public Types

Public Methods

Static Public Attributes


Detailed Description

A stream that can be attached to a socket.

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.


Member Enumeration Documentation

enum more::io::socket::state_type
 

Enumeration values:
state_unbound 
state_bound 
state_listening 
state_accepted 
state_connected 


Constructor & Destructor Documentation

more::io::socket::socket  
 

Construct a socket in states_unbound, i.e.

not attached to any port.

more::io::socket::socket _sub_init    init
 

Construct a socket from the return value of accept.

The socket will be in state_accepted, meaning that it has accepted a connection from a client and is ready to serve it by communicating over the std::iostream base class.

more::io::socket::~socket   [inline]
 

Destruction which closes the socket.


Member Function Documentation

_sub_init more::io::socket::accept  
 

Pop a connection off a listening socket.

The return type can be used as an argument to the ctor or open member of another socket object. If successful the socket constructed will be in state_accepted, otherwise it will be in state_unbound. A failure of this member function does not affect the state of the listening socket which it was called from.

socket_address const& more::io::socket::address   const [inline]
 

Returns the address of the socket.

bool more::io::socket::bind socket_address const &   
 

Bind a socket to a local IP V4 or V6 address.

After binding to the address, you may call listen to make the server accessible at this address. If successful, change to state_bound and return true, else return false.

void more::io::socket::close  
 

Close the socket.

Normally you don't need to call this, see open().

bool more::io::socket::connect socket_address const &   
 

Connect a socket to a remote IP V4 or V6 address.

If successful, return true and change to state_connected, else return false.

bool more::io::socket::is_streamable   const [inline]
 

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.

bool more::io::socket::listen int    backlog = 5
 

Signal that we are ready to accept connections.

If successful switch to state_listening and return true, else return false.

state_type more::io::socket::state   const [inline]
 

Return the state of the socket.

int more::io::socket::the_errno   const [inline]
 

Returns the C errno from the last error.

This can be passed to diag::strerror to obtain an informative description of the failure, or to diag::errno_exception to throw an exception with such a message. The result of this function only makes sense if there has been an error.


Member Data Documentation

const int more::io::socket::type_stream [static]
 


The documentation for this struct was generated from the following file:
Generated on Sat Sep 7 19:12:44 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.