From c175ec4f428d571bdf03501d0bc16dcefdbd632b Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Fri, 27 Sep 2013 21:24:33 -0500 Subject: [PATCH] Adds preliminary signaling to iostream transport of eof and fatal transport errors --- changelog.md | 2 ++ websocketpp/transport/iostream/connection.hpp | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/changelog.md b/changelog.md index 3c407b9ff1..7d065fca76 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,6 @@ HEAD +- Adds preliminary signaling to iostream transport of eof and fatal transport + errors - Updates transport code to use shared pointers rather than raw pointers to prevent asio from retaining pointers to connection methods after the connection goes out of scope. #293 Thank you otaras for reporting. diff --git a/websocketpp/transport/iostream/connection.hpp b/websocketpp/transport/iostream/connection.hpp index 24ed580a17..1984b2b5de 100644 --- a/websocketpp/transport/iostream/connection.hpp +++ b/websocketpp/transport/iostream/connection.hpp @@ -142,6 +142,36 @@ public: return this->readsome_impl(buf,len); } + /// Signal EOF + /** + * Signals to the transport that data stream being read has reached EOF and + * that no more bytes may be read or written to/from the transport. + */ + void eof() { + // this serializes calls to external read. + scoped_lock_type lock(m_read_mutex); + + if (m_reading) { + m_reading = false; + m_read_handler(make_error_code(transport::error::eof), m_cursor); + } + } + + /// Signal transport error + /** + * Signals to the transport that a fatal data stream error has occurred and + * that no more bytes may be read or written to/from the transport. + */ + void fatal_error() { + // this serializes calls to external read. + scoped_lock_type lock(m_read_mutex); + + if (m_reading) { + m_reading = false; + m_read_handler(make_error_code(transport::error::pass_through), m_cursor); + } + } + /// Set whether or not this connection is secure /** * The iostream transport does not provide any security features. As such