Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

msg_handler< Header, Lock > Class Template Reference

Inherits net_handler< Lock >< Lock >.

List of all members.


Detailed Description

template<class Header = length_header, class Lock = __nmstl_no_lock>
class msg_handler< Header, Lock >

A handler which reads and writes messages, each with a fixed-size message described by the struct Header.

Header must have a public length field allowing the payload length to be get/set.

Handlers should override connected (inherited from net_handler); incoming_message(const Header&, databuf) to read messages; and end_messages(unsigned int) to be notified of stream closure.


Public Methods

bool write (Header &head, const omessage &p)
 Populates the header with the payload length and writes a message.

bool write (Header &head, constbuf payload)
 Populates the header with the payload length and writes a message.

bool write (const Header &head, const omessage &p)
 Copies the header, populates it with the payload length, and writes a message.

bool write (const Header &head, constbuf payload)
 Populates the header with the payload length and writes a message.

bool write (const Header &head)
 Writes a message with no payload.

bool write (constbuf payload)
 Writes a message with a default-constructed header.

bool write (string payload)
 Writes a message with a default-constructed header.

bool write_asis (const Header &p, constbuf payload)
 Writes a message without setting the payload length (use this only if the payload length is known to have been set properly).


Protected Methods

 msg_handler (io_event_loop &loop, iohandle ioh, bool established=false)
 msg_handler (io_event_loop &loop)
virtual ~msg_handler ()
virtual void incoming_message (const Header &head, constbuf buf)=0
 Invoked when a complete message has been received.

virtual void end_messages (unsigned int remaining)
 Invoked when the stream has been closed for reading, i.e., there cannot possibly be more incoming messages.


Constructor & Destructor Documentation

template<class Header = length_header, class Lock = __nmstl_no_lock>
msg_handler< Header, Lock >::msg_handler io_event_loop   loop,
iohandle    ioh,
bool    established = false
[protected]
 

template<class Header = length_header, class Lock = __nmstl_no_lock>
msg_handler< Header, Lock >::msg_handler io_event_loop   loop [protected]
 

template<class Header = length_header, class Lock = __nmstl_no_lock>
virtual msg_handler< Header, Lock >::~msg_handler   [protected, virtual]
 


Member Function Documentation

template<class Header = length_header, class Lock = __nmstl_no_lock>
virtual void msg_handler< Header, Lock >::end_messages unsigned int    remaining [protected, virtual]
 

Invoked when the stream has been closed for reading, i.e., there cannot possibly be more incoming messages.

Parameters:
remaining  the number of bytes left in the input buffer but not belonging to a message (should be 0 if the stream was closed cleanly).

template<class Header = length_header, class Lock = __nmstl_no_lock>
virtual void msg_handler< Header, Lock >::incoming_message const Header &    head,
constbuf    buf
[protected, pure virtual]
 

Invoked when a complete message has been received.

Parameters:
head  the message header.
buf  the message payload.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write string    payload
 

Writes a message with a default-constructed header.

Reimplemented from net_handler< Lock >.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write constbuf    payload
 

Writes a message with a default-constructed header.

Reimplemented from net_handler< Lock >.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write const Header &    head
 

Writes a message with no payload.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write const Header &    head,
constbuf    payload
 

Populates the header with the payload length and writes a message.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write const Header &    head,
const omessage   p
 

Copies the header, populates it with the payload length, and writes a message.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write Header &    head,
constbuf    payload
 

Populates the header with the payload length and writes a message.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write Header &    head,
const omessage   p
 

Populates the header with the payload length and writes a message.

template<class Header = length_header, class Lock = __nmstl_no_lock>
bool msg_handler< Header, Lock >::write_asis const Header &    p,
constbuf    payload
 

Writes a message without setting the payload length (use this only if the payload length is known to have been set properly).


The documentation for this class was generated from the following file:
Generated on Fri Dec 20 13:35:10 2002 for NMSTL