summaryrefslogtreecommitdiff
path: root/indra/llcorehttp
diff options
context:
space:
mode:
authorRider Linden <rider@lindenlab.com>2025-08-24 21:16:36 -0700
committerRider Linden <rider@lindenlab.com>2025-10-07 09:19:34 -0700
commit7b174ab2a7c54d3e25a56530a2179848db2d46c0 (patch)
treeed45d05732a78f0e2cec5ad2f74dcf6d14ba22e7 /indra/llcorehttp
parentde65dbfcaf4a4f9d3083f014caa1fe2294952e7b (diff)
First pass at websocket server for editing.
Diffstat (limited to 'indra/llcorehttp')
-rw-r--r--indra/llcorehttp/llwebsocketmgr.cpp27
-rw-r--r--indra/llcorehttp/llwebsocketmgr.h13
2 files changed, 32 insertions, 8 deletions
diff --git a/indra/llcorehttp/llwebsocketmgr.cpp b/indra/llcorehttp/llwebsocketmgr.cpp
index 0427bdab54..3e4262b49b 100644
--- a/indra/llcorehttp/llwebsocketmgr.cpp
+++ b/indra/llcorehttp/llwebsocketmgr.cpp
@@ -30,6 +30,7 @@
#include "llerror.h"
#include "llsdserialize.h"
#include "llhost.h"
+#include "llsdjson.h"
#include <websocketpp/config/boost_config.hpp>
#include <websocketpp/config/asio_no_tls.hpp>
@@ -242,14 +243,16 @@ struct Server_impl
*/
bool start()
{
- if (!mServer.stopped())
- {
- LL_WARNS("WebSocket") << "WebSocket server is already running" << LL_ENDL;
- return false;
- }
+ //if (!mServer.stopped())
+ //{
+ // LL_WARNS("WebSocket") << "WebSocket server is already running" << LL_ENDL;
+ // return false;
+ //}
try
{
+ LL_INFOS("WebSocket") << "Starting WebSocket server on port " << mPort
+ << (mLocalOnly ? " (localhost only)" : " (all interfaces)") << LL_ENDL;
mServer.start_accept();
// Run controlled event loop with periodic stop flag checking
@@ -592,6 +595,7 @@ void LLWebsocketMgr::WSServer::handleOpenConnection(const connection_h& handle)
{
LL_WARNS("WebSocket") << mServerName << " failed to create connection object" << LL_ENDL;
return;
+ }
// Removed redundant assignment to mConnections[handle]
size = mConnections.size();
}
@@ -641,7 +645,7 @@ void LLWebsocketMgr::WSServer::handleMessage(const connection_h& handle, const s
}
//------------------------------------------------------------------------
-bool LLWebsocketMgr::WSConnection::sendMessage(const std::string& message)
+bool LLWebsocketMgr::WSConnection::sendMessage(const std::string& message) const
{
if (!mServer)
{
@@ -651,6 +655,17 @@ bool LLWebsocketMgr::WSConnection::sendMessage(const std::string& message)
return mServer->sendMessageTo(mConnectionHandle, message);
}
+bool LLWebsocketMgr::WSConnection::sendMessage(const boost::json::value& json) const
+{
+ std::string message = boost::json::serialize(json);
+ return sendMessage(message);
+}
+
+bool LLWebsocketMgr::WSConnection::sendMessage(const LLSD& data) const
+{
+ return sendMessage(LlsdToJson(data));
+}
+
void LLWebsocketMgr::WSConnection::closeConnection(U16 code, const std::string& reason)
{
if (!mServer)
diff --git a/indra/llcorehttp/llwebsocketmgr.h b/indra/llcorehttp/llwebsocketmgr.h
index 5634acde01..08f6f22dbc 100644
--- a/indra/llcorehttp/llwebsocketmgr.h
+++ b/indra/llcorehttp/llwebsocketmgr.h
@@ -39,6 +39,8 @@
#include <thread>
#include <atomic>
+#include <boost/json.hpp>
+
#include <websocketpp/common/connection_hdl.hpp>
struct Server_impl;
@@ -148,7 +150,9 @@ public:
* connection->sendMessage(LLSDSerialize::toJSON(response));
* @endcode
*/
- bool sendMessage(const std::string& message);
+ bool sendMessage(const std::string& message) const;
+ bool sendMessage(const boost::json::value& json) const;
+ bool sendMessage(const LLSD& data) const;
/**
* @brief Close the WebSocket connection gracefully
@@ -260,6 +264,11 @@ public:
virtual void onConnectionClosed(const WSConnection::ptr_t& connection) { }
bool isRunning() const;
+ size_t getConnectionCount() const
+ {
+ LLMutexLock lock(&mConnectionMutex);
+ return mConnections.size();
+ }
void broadcastMessage(const std::string& message);
protected:
@@ -294,7 +303,7 @@ public:
std::string mServerName;
std::unique_ptr<Server_impl> mImpl;
connection_map_t mConnections;
- LLMutex mConnectionMutex;
+ mutable LLMutex mConnectionMutex;
// Threading support
std::thread mServerThread; ///< Thread running the ASIO event loop