Library: RemotingNG/TCP
Package: TCP
Header: Poco/RemotingNG/TCP/Connection.h
This class represents a TCP connection between a client and a server.
A Connection is used by multiple proxies simultaneously. It is also used to send event messages from a server to a client.
A Connection is split up into multiple channels, with each channel belonging to exactly one Proxy or EventSubscriber.
Messages sent between the client and the server are split up into frames, with each frame being transmitted on a specific channel.
Each connection is handled by a thread. Incoming requests or event messages will typically be handled by a separate thread obtained from a ThreadPool, but this is outside the scope of the Connection object.
Direct Base Classes: Poco::Runnable, Poco::RemotingNG::AttributedObject
All Base Classes: Poco::RefCountedObject, Poco::RemotingNG::AttributedObject, Poco::Runnable
Member Functions: abort, addCapability, allocChannel, close, getIdleTimeout, hasCapability, localAddress, mode, peerHasCapability, popFrameHandler, processFrame, pushFrameHandler, receiveBYE, receiveFrame, receiveHELO, receiveNBytes, releaseChannel, remoteAddress, returnFrame, run, runImpl, secure, sendBYE, sendFrame, sendHELO, sendProtocolFrame, setIdleTimeout, state, waitReady
Inherited Functions: duplicate, getAttribute, hasAttribute, referenceCount, release, run, setAttribute
typedef Poco::AutoPtr < Connection > Ptr;
A connection created by a client.
A connection created by a server.
The connection has been established, but no handshake (HELO) frames have been exchanged.
The first handshake frame has been sent, and the connection is waiting for the peer's handshake frame.
The connection is ready.
The connection is being actively closed and a BYE frame has been sent to the peer. Waiting for the confirming BYE frame from the peer.
A BYE frame has been received and a confirming BYE frame will be sent.
The connection has been forcefully closed, without a closing handshake, due to a protocol violation.
The connection has been orderly closed.
Connection(
const Poco::Net::StreamSocket & socket,
ConnectionMode mode
);
Creates the Connection for the given socket and endpoint mode.
~Connection();
Destroys the Connection.
void abort();
Aborts the connection.
void addCapability(
Poco::UInt32 capability
);
Adds the given capability to the connection.
This must be done before the connection handshake takes place.
Poco::UInt32 allocChannel();
Allocates a channel number.
void close();
Orderly closes the connection.
Poco::Timespan getIdleTimeout() const;
Returns the idle connection timeout.
bool hasCapability(
Poco::UInt32 capability
);
Returns true if the connection has the given capability.
Poco::Net::SocketAddress localAddress() const;
Returns the socket's local address.
ConnectionMode mode() const;
Returns the connection mode.
bool peerHasCapability(
Poco::UInt32 capability
);
Returns true if the peer has the given capability.
Peer capabilities will be available after the connection handshake.
void popFrameHandler(
Poco::AutoPtr < FrameHandler > pHandler
);
Removes the FrameHandler from the internal stack.
void pushFrameHandler(
Poco::AutoPtr < FrameHandler > pHandler
);
Pushes the FrameHandler to the internal stack.
void releaseChannel(
Poco::UInt32 channel
);
Releases the given channel number.
Poco::Net::SocketAddress remoteAddress() const;
Returns the remote peer's socket address.
void returnFrame(
Frame::Ptr pFrame
);
Returns the frame to the pool.
bool secure() const;
Returns true if and only if the connection uses a secure socket.
void sendFrame(
Frame::Ptr pFrame
);
Send a single frame. The connection must be in STATE_ESTABLISHED.
void setIdleTimeout(
Poco::Timespan timeout
);
Sets the timeout after an idle connection is closed.
ConnectionState state() const;
Returns the connection state.
bool waitReady(
Poco::Timespan timeout = 2 * TIMEOUT_HELO
);
Waits until the connection is established, or the given timeout expires.
void processFrame(
Frame::Ptr pFrame
);
Process a single frame.
void receiveBYE();
Waits for and receives the final BYE frame.
Frame::Ptr receiveFrame();
Receives the next frame from the connection, or returns null if no frame has been received within a certain time.
void receiveHELO();
Waits for and receives the initial HELO frame.
int receiveNBytes(
char * buffer,
int bytes
);
Receive exactly the given number of bytes.
void run();
Handle incoming frames.
See also: Poco::Runnable::run()
void runImpl();
Handle incoming frames.
void sendBYE();
Sends the final BYE frame.
void sendHELO();
Sends the initial HELO frame.
void sendProtocolFrame(
Frame::Ptr pFrame
);
Send a single protocol frame.
Poco::BasicEvent < Connection::Ptr > connectionAborted;
Fired after the connection has been aborted.
Poco::BasicEvent < Connection::Ptr > connectionClosed;
Fired after the connection has been closed.
Poco::BasicEvent < Connection::Ptr > connectionClosing;
Fired when the connection is about to be closed.
Poco::BasicEvent < Connection::Ptr > connectionEstablished;
Fired after the handshake is complete and the connection has been established.