KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ASYNC_SOCKET_HOLDER Class Reference

Spin up a thread to send messages via a socket. More...

Public Member Functions

 ASYNC_SOCKET_HOLDER ()
 
 ~ASYNC_SOCKET_HOLDER ()
 
bool Send (int aService, const std::string &aMessage)
 Attempt to send a message if the thread is available.
 

Private Member Functions

void worker ()
 Actual task that sends data to the socket server.
 

Private Attributes

std::thread m_thread
 
std::pair< int, std::string > m_message
 
bool m_messageReady
 
std::mutex m_mutex
 
std::condition_variable m_cv
 
bool m_shutdown
 

Detailed Description

Spin up a thread to send messages via a socket.

No message queuing, if a message is in flight when another is posted with Send(), the second is just dropped. This is a workaround for "non-blocking" sockets not always being non-blocking, especially on Windows. It is kept fairly simple and not exposed to the outside world because it should be replaced in a future KiCad version with a real message queue of some sort, and unified with the Kiway messaging system.

Definition at line 126 of file eda_dde.cpp.

Constructor & Destructor Documentation

◆ ASYNC_SOCKET_HOLDER()

ASYNC_SOCKET_HOLDER::ASYNC_SOCKET_HOLDER ( )
inline

Definition at line 129 of file eda_dde.cpp.

References HOSTNAME(), KICAD_PCB_PORT_SERVICE_NUMBER, m_thread, and worker().

◆ ~ASYNC_SOCKET_HOLDER()

ASYNC_SOCKET_HOLDER::~ASYNC_SOCKET_HOLDER ( )
inline

Definition at line 149 of file eda_dde.cpp.

References m_cv, m_mutex, m_shutdown, and m_thread.

Member Function Documentation

◆ Send()

bool ASYNC_SOCKET_HOLDER::Send ( int  aService,
const std::string &  aMessage 
)
inline

Attempt to send a message if the thread is available.

Parameters
aServiceis the port number (i.e. service) to send to.
aMessageis the message to send.
Returns
true if the message was queued.

Definition at line 175 of file eda_dde.cpp.

References m_cv, m_message, m_messageReady, and m_mutex.

◆ worker()

void ASYNC_SOCKET_HOLDER::worker ( )
inlineprivate

Actual task that sends data to the socket server.

Definition at line 193 of file eda_dde.cpp.

References HOSTNAME(), m_cv, m_message, m_messageReady, m_mutex, and m_shutdown.

Referenced by ASYNC_SOCKET_HOLDER().

Member Data Documentation

◆ m_cv

std::condition_variable ASYNC_SOCKET_HOLDER::m_cv
private

Definition at line 293 of file eda_dde.cpp.

Referenced by Send(), worker(), and ~ASYNC_SOCKET_HOLDER().

◆ m_message

std::pair<int, std::string> ASYNC_SOCKET_HOLDER::m_message
private

Definition at line 290 of file eda_dde.cpp.

Referenced by Send(), and worker().

◆ m_messageReady

bool ASYNC_SOCKET_HOLDER::m_messageReady
private

Definition at line 291 of file eda_dde.cpp.

Referenced by Send(), and worker().

◆ m_mutex

std::mutex ASYNC_SOCKET_HOLDER::m_mutex
mutableprivate

Definition at line 292 of file eda_dde.cpp.

Referenced by Send(), worker(), and ~ASYNC_SOCKET_HOLDER().

◆ m_shutdown

bool ASYNC_SOCKET_HOLDER::m_shutdown
private

Definition at line 294 of file eda_dde.cpp.

Referenced by worker(), and ~ASYNC_SOCKET_HOLDER().

◆ m_thread

std::thread ASYNC_SOCKET_HOLDER::m_thread
private

Definition at line 289 of file eda_dde.cpp.

Referenced by ASYNC_SOCKET_HOLDER(), and ~ASYNC_SOCKET_HOLDER().


The documentation for this class was generated from the following file: