mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Comm session re-architecture and self comm channel. (#145)
* Introduced self comm channel instead of loopback websocket. * Introduced comm_session and comm_server inheritance hierarchy. * Separated peer session and user session classes.
This commit is contained in:
28
src/p2p/self_node.cpp
Normal file
28
src/p2p/self_node.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "../pchheader.hpp"
|
||||
#include "peer_session_handler.hpp"
|
||||
|
||||
namespace p2p::self
|
||||
{
|
||||
// Holds self messages waiting to be processed.
|
||||
moodycamel::ConcurrentQueue<std::string> msg_queue;
|
||||
|
||||
/**
|
||||
* Processes the next queued message (if any).
|
||||
* @return 0 if no messages in queue. 1 if message was processed successfully. -1 on error.
|
||||
*/
|
||||
int process_next_message()
|
||||
{
|
||||
std::string msg;
|
||||
if (msg_queue.try_dequeue(msg))
|
||||
return p2p::handle_self_message(msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void send(std::string_view message)
|
||||
{
|
||||
// Passing the ownership of message to the queue.
|
||||
msg_queue.enqueue(std::string(message));
|
||||
}
|
||||
|
||||
} // namespace p2p::self
|
||||
Reference in New Issue
Block a user