@@ -8,12 +8,15 @@ namespace dbus2http {
88
99using websocketpp::log::alevel;
1010
11- SignalSocket::SignalSocket (const InterfaceContext& context, int port, Config config)
11+ SignalSocket::SignalSocket (const InterfaceContext& context, int port,
12+ Config config)
1213 : context_(context), config_(config) {
1314 ws_server_.init_asio ();
15+ ws_server_.set_reuse_addr (true );
1416 ws_server_.set_open_handler ([&](auto conn_hdl) {
1517 websocketpp::lib::error_code ec;
16- server::connection_ptr ws_conn = ws_server_.get_con_from_hdl (conn_hdl, ec);
18+ const server::connection_ptr ws_conn =
19+ ws_server_.get_con_from_hdl (conn_hdl, ec);
1720 if (ec) {
1821 PLOGE << " get_con_from_hdl error: " << ec.message ();
1922 return ;
@@ -32,15 +35,14 @@ SignalSocket::SignalSocket(const InterfaceContext& context, int port, Config con
3235 match = replaceAll (match, " %20" , " " );
3336 match = replaceAll (match, " %27" , " '" );
3437 match = replaceAll (match, " %2C" , " ," );
35- match = replaceAll (match, " %3D" , " =" );
3638 match = replaceAll (match, " %2F" , " /" );
3739 match = replaceAll (match, " %3A" , " :" );
3840 match = replaceAll (match, " %3D" , " =" );
3941 PLOGI << " match : " << match;
4042 try {
4143 conn2slot_[conn_hdl] = dbus_connection_->addMatch (
4244 match,
43- [&, conn_hdl](sdbus::Message msg) {
45+ [this , & conn_hdl](sdbus::Message msg) {
4446 PLOGD << " get message from service: " << msg.getInterfaceName ()
4547 << " member: " << msg.getMemberName ();
4648 std::vector<Argument> args;
@@ -59,6 +61,7 @@ SignalSocket::SignalSocket(const InterfaceContext& context, int port, Config con
5961
6062 nlohmann::json j = Message2Json::WrapHeader (
6163 msg, message2json.ExtractMessage (msg, args));
64+ websocketpp::lib::error_code ec;
6265 server::connection_ptr conn =
6366 ws_server_.get_con_from_hdl (conn_hdl, ec);
6467 if (conn) {
@@ -71,6 +74,8 @@ SignalSocket::SignalSocket(const InterfaceContext& context, int port, Config con
7174 },
7275 sdbus::return_slot_t ());
7376 } catch (const std::exception& e) {
77+ ws_server_.close (conn_hdl, websocketpp::close::status::policy_violation,
78+ " add match failed: " + std::string (e.what ()));
7479 PLOGE << " add match failed: " << e.what ();
7580 }
7681 });
@@ -102,7 +107,7 @@ SignalSocket::SignalSocket(const InterfaceContext& context, int port, Config con
102107 ws_server_.set_access_channels (alevel::all);
103108 ws_server_.set_error_channels (alevel::all);
104109#endif
105- dbus_connection_ = DbusUtils::createConnection (system );
110+ dbus_connection_ = DbusUtils::createConnection (config. system_bus );
106111}
107112
108113void SignalSocket::on_message (server* s, websocketpp::connection_hdl conn_hdl,
0 commit comments