Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

demo tidyup

  • Loading branch information...
commit 19955c64b91bf1cbbcad79f911e81d8a6a348dd0 1 parent beb6f74
@RJ authored
View
5 app/demo_messages.h
@@ -5,8 +5,9 @@
using namespace libf2f;
-#define PING 0
-#define PONG 1
+#define PING 0
+#define PONG 1
+#define QUERY 2
class PongMessage : public Message
{
View
13 include/libf2f/connection.h
@@ -67,7 +67,13 @@ class Connection
std::string str() const;
+ const bool ready() const { return m_ready; }
+ void set_ready( bool b ) { m_ready = b; }
+ const std::string& name() const { return m_name; }
+ void set_name( const std::string& n ) { m_name = n; }
+
private:
+
boost::asio::ip::tcp::socket m_socket; // underlying socket
boost::mutex m_mutex; // protects outgoing message queue
@@ -76,9 +82,10 @@ class Connection
size_t max_writeq_size; // max number of bytes in the queue
/// Stateful stuff the protocol handler/servent will set:
- std::string m_username; // username of user at end of Connection
- //bool m_authed;
- bool m_sending;
+ std::string m_name; // "name" of user at end of Connection
+
+ bool m_ready; // ready for normal messages (ie, we authed etc)
+ bool m_sending; // currently sending something?
std::vector< boost::function<void(message_ptr, connection_ptr)> > m_message_received_cbs;
boost::mutex m_message_received_cb_mutex; // protects the above
View
7 src/connection.cpp
@@ -8,7 +8,9 @@ using namespace std;
Connection::Connection( boost::asio::io_service& io_service,
boost::function< void(message_ptr, connection_ptr) > msg_cb,
boost::function< void(connection_ptr) > fin_cb )
- : m_socket(io_service), m_sending(false),
+ : m_socket(io_service),
+ m_ready(false),
+ m_sending(false),
m_fin_cb(fin_cb),
m_shuttingdown(false)
{
@@ -161,7 +163,8 @@ std::string
Connection::str() const
{
std::ostringstream os;
- os << "[Connection:"
+ os << "[Connection: '"
+ << m_name << "' "
<< m_socket.remote_endpoint().address().to_string()
<< ":"
<< m_socket.remote_endpoint().port()
View
2  src/router.cpp
@@ -191,9 +191,11 @@ Router::handle_connect( const boost::system::error_code& e,
void
Router::foreach_conns( boost::function<void(connection_ptr)> fun )
{
+ cout << "foreach_conns" << endl;
boost::mutex::scoped_lock lk(m_connections_mutex);
BOOST_FOREACH( connection_ptr conn, m_connections )
{
+ cout << "Sending to " << conn->str() << endl;
fun( conn );
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.