RemoteInspectorServer.cpp [plain text]
#include "config.h"
#include "RemoteInspectorServer.h"
#if ENABLE(REMOTE_INSPECTOR)
#include "RemoteInspectorMessageParser.h"
#include <wtf/MainThread.h>
namespace Inspector {
RemoteInspectorServer& RemoteInspectorServer::singleton()
{
static LazyNeverDestroyed<RemoteInspectorServer> shared;
static std::once_flag onceKey;
std::call_once(onceKey, [&] {
shared.construct();
});
return shared;
}
RemoteInspectorServer::~RemoteInspectorServer()
{
auto& endpoint = Inspector::RemoteInspectorSocketEndpoint::singleton();
endpoint.invalidateListener(*this);
}
bool RemoteInspectorServer::start(const char* address, uint16_t port)
{
if (isRunning())
return false;
auto& endpoint = Inspector::RemoteInspectorSocketEndpoint::singleton();
m_server = endpoint.listenInet(address, port, *this);
return isRunning();
}
Optional<uint16_t> RemoteInspectorServer::getPort() const
{
if (!isRunning())
return WTF::nullopt;
const auto& endpoint = Inspector::RemoteInspectorSocketEndpoint::singleton();
return endpoint.getPort(m_server.value());
}
Optional<ConnectionID> RemoteInspectorServer::doAccept(RemoteInspectorSocketEndpoint& endpoint, PlatformSocketType socket)
{
ASSERT(!isMainThread());
auto& inspector = RemoteInspector::singleton();
if (inspector.isConnected()) {
LOG_ERROR("RemoteInspector can accept only 1 client");
return WTF::nullopt;
}
if (auto newID = endpoint.createClient(socket, inspector)) {
inspector.connect(newID.value());
return newID;
}
return WTF::nullopt;
}
}
#endif // ENABLE(REMOTE_INSPECTOR)