+
+int flag = 1;
+
+if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)))
+ {
+ errorStr = "Setsockopt failed.";
+ logger("setsockopt error: %s", strerror(errno));
+ printfd(__FILE__, "Setsockopt failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+struct sockaddr_in addr;
+addr.sin_family = AF_INET;
+addr.sin_port = htons(rpcConfigSettings.GetPort());
+addr.sin_addr.s_addr = inet_addr("0.0.0.0");
+
+if (bind(fd, reinterpret_cast<sockaddr *>(&addr), sizeof(addr)))
+ {
+ logger("Cannot bind the socket: %s", strerror(errno));
+ errorStr = "Failed to bind socket";
+ printfd(__FILE__, "Failed to bind listening socket: %s\n", strerror(errno));
+ return -1;
+ }
+
+if (listen(fd, 10))
+ {
+ logger("Cannot listen the socket: %s", strerror(errno));
+ errorStr = "Failed to listen socket";
+ printfd(__FILE__, "Failed to listen listening socket: %s\n", strerror(errno));
+ return -1;
+ }
+
+rpcServer = new xmlrpc_c::serverAbyss(
+ xmlrpc_c::serverAbyss::constrOpt()
+ .registryP(&rpcRegistry)
+ .logFileName("/var/log/stargazer_rpc.log")
+ .socketFd(fd)
+ );
+
+m_thread = std::jthread([this](auto token){ Run(std::move(token)); });
+