PionNetworkLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pion::http::writer Class Referenceabstract

#include <writer.hpp>

Inheritance diagram for pion::http::writer:
Collaboration diagram for pion::http::writer:

Public Member Functions

virtual ~writer ()
 default destructor More...
 
void clear (void)
 clears out all of the memory buffers used to cache payload content data More...
 
template<typename T >
void write (const T &data)
 
void write (std::ostream &(*iomanip)(std::ostream &))
 
void write (const void *data, size_t length)
 
void write_no_copy (const std::string &data)
 
void write_no_copy (void *data, size_t length)
 
void send (void)
 
template<typename SendHandler >
void send (SendHandler send_handler)
 
template<typename SendHandler >
void send_chunk (SendHandler send_handler)
 
template<typename SendHandler >
void send_final_chunk (SendHandler send_handler)
 
void send_final_chunk (void)
 
tcp::connection_ptrget_connection (void)
 returns a shared pointer to the TCP connection More...
 
size_t get_content_length (void) const
 returns the length of the payload content (in bytes) More...
 
void supports_chunked_messages (bool b)
 sets whether or not the client supports chunked messages More...
 
bool supports_chunked_messages () const
 returns true if the client supports chunked messages More...
 
bool sending_chunked_message () const
 returns true if we are sending a chunked message to the client More...
 
void set_logger (logger log_ptr)
 sets the logger to be used More...
 
logger get_logger (void)
 returns the logger currently in use More...
 

Protected Types

typedef boost::function1< void,
const
boost::system::error_code & > 
finished_handler_t
 function called after the HTTP message has been sent More...
 
typedef boost::function2< void,
const
boost::system::error_code
&, std::size_t > 
write_handler_t
 data type for a function that handles write operations More...
 

Protected Member Functions

 writer (const tcp::connection_ptr &tcp_conn, finished_handler_t handler)
 
virtual void handle_write (const boost::system::error_code &write_error, std::size_t bytes_written)=0
 
virtual void prepare_buffers_for_send (http::message::write_buffers_t &write_buffers)=0
 
virtual write_handler_t bind_to_write_handler (void)=0
 returns a function bound to writer::handle_write() More...
 
void finished_writing (const boost::system::error_code &ec)
 called after we have finished sending the HTTP message More...
 

Detailed Description

writer: used to asynchronously send HTTP messages

Member Typedef Documentation

typedef boost::function1<void,const boost::system::error_code&> pion::http::writer::finished_handler_t
protected

function called after the HTTP message has been sent

typedef boost::function2<void,const boost::system::error_code&,std::size_t> pion::http::writer::write_handler_t
protected

data type for a function that handles write operations

Constructor & Destructor Documentation

pion::http::writer::writer ( const tcp::connection_ptr tcp_conn,
finished_handler_t  handler 
)
inlineprotected

protected constructor: only derived classes may create objects

Parameters
tcp_connTCP connection used to send the message
handlerfunction called after the request has been sent
virtual pion::http::writer::~writer ( )
inlinevirtual

default destructor

Member Function Documentation

virtual write_handler_t pion::http::writer::bind_to_write_handler ( void  )
protectedpure virtual

returns a function bound to writer::handle_write()

Implemented in pion::http::response_writer, and pion::http::request_writer.

void pion::http::writer::clear ( void  )
inline

clears out all of the memory buffers used to cache payload content data

Referenced by pion::http::request_writer::handle_write().

void pion::http::writer::finished_writing ( const boost::system::error_code &  ec)
inlineprotected

called after we have finished sending the HTTP message

Referenced by pion::http::request_writer::handle_write().

tcp::connection_ptr& pion::http::writer::get_connection ( void  )
inline

returns a shared pointer to the TCP connection

Referenced by pion::http::request_writer::prepare_buffers_for_send().

size_t pion::http::writer::get_content_length ( void  ) const
inline

returns the length of the payload content (in bytes)

Referenced by pion::http::request_writer::prepare_buffers_for_send().

logger pion::http::writer::get_logger ( void  )
inline

returns the logger currently in use

Referenced by pion::http::request_writer::handle_write().

virtual void pion::http::writer::handle_write ( const boost::system::error_code &  write_error,
std::size_t  bytes_written 
)
protectedpure virtual

called after the message is sent

Parameters
write_errorerror status from the last write operation
bytes_writtennumber of bytes sent by the last write operation

Implemented in pion::http::response_writer, and pion::http::request_writer.

virtual void pion::http::writer::prepare_buffers_for_send ( http::message::write_buffers_t write_buffers)
protectedpure virtual

initializes a vector of write buffers with the HTTP message information

Parameters
write_buffersvector of write buffers to initialize

Implemented in pion::http::response_writer, and pion::http::request_writer.

void pion::http::writer::send ( void  )
inline

Sends all data buffered as a single HTTP message (without chunking). Following a call to this function, it is not thread safe to use your reference to the writer object.

template<typename SendHandler >
void pion::http::writer::send ( SendHandler  send_handler)
inline

Sends all data buffered as a single HTTP message (without chunking). Following a call to this function, it is not thread safe to use your reference to the writer object until the send_handler has been called.

Parameters
send_handlerfunction that is called after the message has been sent to the client. Your callback function must end the connection by calling connection::finish().
template<typename SendHandler >
void pion::http::writer::send_chunk ( SendHandler  send_handler)
inline

Sends all data buffered as a single HTTP chunk. Following a call to this function, it is not thread safe to use your reference to the writer object until the send_handler has been called.

Parameters
send_handlerfunction that is called after the chunk has been sent to the client. Your callback function must end by calling one of send_chunk() or send_final_chunk(). Also, be sure to clear() the writer before writing data to it.

References pion::tcp::connection::LIFECYCLE_CLOSE.

template<typename SendHandler >
void pion::http::writer::send_final_chunk ( SendHandler  send_handler)
inline

Sends all data buffered (if any) and also sends the final HTTP chunk. This function (either overloaded version) must be called following any calls to send_chunk(). Following a call to this function, it is not thread safe to use your reference to the writer object until the send_handler has been called.

Parameters
send_handlerfunction that is called after the message has been sent to the client. Your callback function must end the connection by calling connection::finish().
void pion::http::writer::send_final_chunk ( void  )
inline

Sends all data buffered (if any) and also sends the final HTTP chunk. This function (either overloaded version) must be called following any calls to send_chunk(). Following a call to this function, it is not thread safe to use your reference to the writer object.

bool pion::http::writer::sending_chunked_message ( ) const
inline

returns true if we are sending a chunked message to the client

Referenced by pion::http::request_writer::handle_write(), and pion::http::request_writer::prepare_buffers_for_send().

void pion::http::writer::set_logger ( logger  log_ptr)
inline

sets the logger to be used

Referenced by pion::http::request_writer::request_writer().

void pion::http::writer::supports_chunked_messages ( bool  b)
inline

sets whether or not the client supports chunked messages

bool pion::http::writer::supports_chunked_messages ( ) const
inline

returns true if the client supports chunked messages

template<typename T >
void pion::http::writer::write ( const T &  data)
inline

write text (non-binary) payload content

Parameters
datathe data to append to the payload content
void pion::http::writer::write ( std::ostream &(*)(std::ostream &)  iomanip)
inline
void pion::http::writer::write ( const void *  data,
size_t  length 
)
inline

write binary payload content

Parameters
datapoints to the binary data to append to the payload content
lengththe length, in bytes, of the binary data
void pion::http::writer::write_no_copy ( const std::string &  data)
inline

write text (non-binary) payload content; the data written is not copied, and therefore must persist until the message has finished sending

Parameters
datathe data to append to the payload content

Referenced by pion::http::request_writer::request_writer().

void pion::http::writer::write_no_copy ( void *  data,
size_t  length 
)
inline

write binary payload content; the data written is not copied, and therefore must persist until the message has finished sending

Parameters
datapoints to the binary data to append to the payload content
lengththe length, in bytes, of the binary data

The documentation for this class was generated from the following files: