insd::Connection class
An object of the Connection class represents an endpoint of a socket connection
between client and server processes.
To send data from the client to the server, you push characters into an appropriate Connection
object in the client process, then retrieve them from a different connection object in the server process.
The reverse procedure will send data back the other way.
The Connection class has no public constructors. New connection objects are created and returned when a new connection is established but cannot be copied or constructed explicitly.
Methods
bool active()
Returns true unless the connection is known to have disconnected.
void put(std::string s)
Sends the contents of string s down the tube. s consists of one or more characters.
During a put operation, a connection-terminated condition may be detected. In this case,
a insd::ConnectionTerminatedException is thrown, and the Connection object's active
method thenceforth returns false.
std::string get(int nchar=1)
Waits for and retrieves a string of length nchar through the connection. nchar is an optional parameter. If omitted, a single character is retrieved.
The retrieved character sequence is then returned as a C++ string.
The get() method will nominally block the thread's execution until it has
received the specified number of characters, nchar. These are then returned.
However, it will break out of the blocked state automatically by throwing an exception early under the following circumstances:
The connection has been terminated by the peer. A ConnectionTerminatedException is thrown.
On the server side, the SocketServ object that created it has ceased to be in the active state,
and is now waiting for all active connection threads to terminate.
An exception of type ConnectionTerminatedException is thrown.