void TcpConnectionImpl::handle_read(const boost::system::error_code& error) { if (!error) { std::string msg; std::istream is(&m_buffer); std::getline(is, msg); // TODO: you could do some message processing here, like breaking it up // into smaller parts, rejecting unknown messages or handling the message protocol while (!msg.empty()) { // create function to notify listeners MessageCallback(msg); std::getline(is, msg); } // restart heartbeat timer (optional) restartHeartbeatTimer(); // wait for the next message read(); } else { ExceptionCallback(error); // try to reconnect if external host disconnects if(error.value() != 0) { m_isConnected = false; // let listeners know DisconnectedCallback(m_endPoint); // schedule a timer to reconnect after 5 seconds restartReconnectTimer(); } else { do_close(); } } }
void CWiiRemote::MessageCallback(cwiid_wiimote_t *wiiremote, int mesg_count, union cwiid_mesg mesg[]) { MessageCallback(wiiremote, mesg_count, mesg, NULL); }