28 #ifndef WEBSOCKETPP_TRANSPORT_DEBUG_CON_HPP
29 #define WEBSOCKETPP_TRANSPORT_DEBUG_CON_HPP
31 #include <websocketpp/transport/debug/base.hpp>
33 #include <websocketpp/transport/base/connection.hpp>
35 #include <websocketpp/logger/levels.hpp>
37 #include <websocketpp/common/connection_hdl.hpp>
38 #include <websocketpp/common/memory.hpp>
39 #include <websocketpp/common/platforms.hpp>
54 template <
typename config>
55 class connection :
public lib::enable_shared_from_this< connection<config> > {
60 typedef lib::shared_ptr<type>
ptr;
70 typedef typename concurrency_type::scoped_lock_type scoped_lock_type;
71 typedef typename concurrency_type::mutex_type mutex_type;
73 typedef lib::shared_ptr<timer> timer_ptr;
75 explicit connection(
bool is_server, alog_type & alog, elog_type & elog)
76 : m_reading(false), m_is_server(is_server), m_alog(alog), m_elog(elog)
83 return type::shared_from_this();
132 return "unknown (debug transport)";
155 m_timer_handler = handler;
176 size_t total_read = 0;
177 size_t temp_read = 0;
180 temp_read = this->read_some_impl(buf+total_read,len-total_read);
181 total_read += temp_read;
182 }
while (temp_read != 0 && total_read < len);
188 void expire_timer(lib::error_code
const & ec) {
192 void fullfil_write() {
193 m_write_handler(lib::error_code());
204 handler(lib::error_code());
235 s <<
"debug_con async_read_at_least: " << num_bytes;
238 if (num_bytes > len) {
239 handler(make_error_code(error::invalid_num_bytes),
size_t(0));
243 if (m_reading ==
true) {
244 handler(make_error_code(error::double_read),
size_t(0));
248 if (num_bytes == 0 || len == 0) {
249 handler(lib::error_code(),
size_t(0));
255 m_bytes_needed = num_bytes;
256 m_read_handler = handler;
275 m_write_handler = handler;
291 m_write_handler = handler;
313 return lib::error_code();
321 handler(lib::error_code());
324 size_t read_some_impl(
char const * buf,
size_t len) {
332 size_t bytes_to_copy = (std::min)(len,m_len-m_cursor);
334 std::copy(buf,buf+bytes_to_copy,m_buf+m_cursor);
336 m_cursor += bytes_to_copy;
338 if (m_cursor >= m_bytes_needed) {
342 return bytes_to_copy;
367 handler(ec,m_cursor);
375 size_t m_bytes_needed;
385 bool const m_is_server;
389 std::string m_remote_endpoint;
397 #endif // WEBSOCKETPP_TRANSPORT_DEBUG_CON_HPP
ptr get_shared()
Get a shared pointer to this component.
config::concurrency_type concurrency_type
transport concurrency policy
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
void set_remote_endpoint(std::string)
Set human readable remote endpoint address.
void set_handle(connection_hdl)
Set Connection Handle.
std::string get_remote_endpoint() const
Get human readable remote endpoint address.
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
Initiate an async_read for at least num_bytes bytes into buf.
lib::function< void(lib::error_code const &)> write_handler
The type and signature of the callback passed to the write method.
static level const devel
Low level debugging information (warning: very chatty)
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
lib::function< void(lib::error_code const &, size_t)> read_handler
The type and signature of the callback passed to the read method.
config::alog_type alog_type
Type of this transport's access logging policy.
connection_hdl get_handle() const
Get the connection handle.
void complete_read(lib::error_code const &ec)
Signal that a requested read is complete.
static level const devel
Development messages (warning: very chatty)
void async_write(char const *, size_t, write_handler handler)
Asyncronous Transport Write.
timer_ptr set_timer(long, timer_handler handler)
Call back a function after a period of time.
connection< config > type
Type of this connection transport component.
config::elog_type elog_type
Type of this transport's error logging policy.
void set_secure(bool)
Set whether or not this connection is secure.
lib::function< void()> dispatch_handler
The type and signature of the callback passed to the dispatch method.
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
void init(init_handler handler)
Initialize the connection transport.
lib::function< void(lib::error_code const &)> shutdown_handler
The type and signature of the callback passed to the shutdown method.
Namespace for the WebSocket++ project.
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
lib::error_code dispatch(dispatch_handler handler)
Call given handler back within the transport's event system (if present)
void async_write(std::vector< buffer > const &, write_handler handler)
Asyncronous Transport Write (scatter-gather)
void async_shutdown(shutdown_handler handler)
Perform cleanup on socket shutdown_handler.
bool is_secure() const
Tests whether or not the underlying transport is secure.
size_t read_all(char const *buf, size_t len)
Manual input supply (read all)