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/uri.hpp>
36 #include <websocketpp/logger/levels.hpp>
38 #include <websocketpp/common/connection_hdl.hpp>
39 #include <websocketpp/common/memory.hpp>
40 #include <websocketpp/common/platforms.hpp>
55 template <
typename config>
56 class connection :
public lib::enable_shared_from_this< connection<config> > {
59 typedef connection<config>
type;
61 typedef lib::shared_ptr<type> ptr;
74 typedef lib::shared_ptr<timer> timer_ptr;
76 explicit connection(
bool is_server,
const lib::shared_ptr<alog_type> & alog,
const lib::shared_ptr<elog_type> & elog)
77 : m_reading(
false), m_is_server(is_server), m_alog(alog), m_elog(elog)
79 m_alog->write(log::alevel::devel,
"debug con transport constructor");
84 return type::shared_from_this();
147 return "unknown (debug transport)";
155 return connection_hdl();
169 m_alog->write(log::alevel::devel,
"debug connection set timer");
170 m_timer_handler = handler;
191 size_t total_read = 0;
192 size_t temp_read = 0;
195 temp_read =
this->read_some_impl(buf+total_read,len-total_read);
196 total_read += temp_read;
197 }
while (temp_read != 0 && total_read < len);
203 void expire_timer(lib::error_code
const & ec) {
207 void fullfil_write() {
208 m_write_handler(lib::error_code());
217 void init(init_handler handler) {
218 m_alog->write(log::alevel::devel,
"debug connection init");
219 handler(lib::error_code());
247 read_handler handler)
250 s <<
"debug_con async_read_at_least: " << num_bytes;
251 m_alog->write(log::alevel::devel,s.str());
253 if (num_bytes > len) {
254 handler(make_error_code(error::invalid_num_bytes),size_t(0));
258 if (m_reading ==
true) {
259 handler(make_error_code(error::double_read),size_t(0));
263 if (num_bytes == 0 || len == 0) {
264 handler(lib::error_code(),size_t(0));
270 m_bytes_needed = num_bytes;
271 m_read_handler = handler;
289 m_alog->write(log::alevel::devel,
"debug_con async_write");
290 m_write_handler = handler;
305 m_alog->write(log::alevel::devel,
"debug_con async_write buffer list");
306 m_write_handler = handler;
328 return lib::error_code();
336 handler(lib::error_code());
339 size_t read_some_impl(
char const * buf, size_t len) {
340 m_alog->write(log::alevel::devel,
"debug_con read_some");
343 m_elog->write(log::elevel::devel,
"write while not reading");
347 size_t bytes_to_copy = (std::min)(len,m_len-m_cursor);
349 std::copy(buf,buf+bytes_to_copy,m_buf+m_cursor);
351 m_cursor += bytes_to_copy;
353 if (m_cursor >= m_bytes_needed) {
354 complete_read(lib::error_code());
357 return bytes_to_copy;
379 read_handler handler = m_read_handler;
380 m_read_handler = read_handler();
382 handler(ec,m_cursor);
385 timer_handler m_timer_handler;
390 size_t m_bytes_needed;
391 read_handler m_read_handler;
395 connection_hdl m_connection_hdl;
396 write_handler m_write_handler;
397 shutdown_handler m_shutdown_handler;
400 bool const m_is_server;
402 lib::shared_ptr<alog_type> m_alog;
403 lib::shared_ptr<elog_type> m_elog;
404 std::string m_remote_endpoint;