25#include <condition_variable>
36static const wxString
HOSTNAME( wxT(
"localhost" ) );
39#define IPC_BUF_SIZE 4096
48 addr.Service( service );
72 wxSocketBase* sock = evt.GetSocket();
74 switch( evt.GetSocketEvent() )
79 if( sock->LastCount() == 0 )
83 len = 1 + sock->LastCount();
93 wxPrintf( wxT(
"EDA_DRAW_FRAME::OnSockRequest() error: Invalid event !" ) );
101 wxSocketBase* socket;
102 wxSocketServer* server = (wxSocketServer*) evt.GetSocket();
104 socket = server->Accept();
106 if( socket ==
nullptr )
111 socket->Notify(
true );
113 socket->SetNotify( wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG );
135 wxSocketClient* client =
new wxSocketClient;
141 client->Connect( addr,
false );
152 std::lock_guard<std::mutex> lock(
m_mutex );
175 bool Send(
int aService,
const std::string& aMessage )
180 std::lock_guard<std::mutex> lock(
m_mutex );
182 m_message = std::make_pair( aService, aMessage );
198 std::unique_lock<std::mutex> lock(
m_mutex );
212 wxSocketClient* sock_client;
217 addr.Service( port );
269 sock_client =
new wxSocketClient( wxSOCKET_BLOCK );
270 sock_client->SetTimeout( 1 );
271 sock_client->Connect( addr,
false );
272 sock_client->WaitOnConnect( 0, 250 );
274 if( sock_client->Ok() && sock_client->IsConnected() )
276 sock_client->SetFlags( wxSOCKET_NOWAIT );
277 sock_client->Write( message.c_str(), message.length() );
280 sock_client->Close();
281 sock_client->Destroy();
Spin up a thread to send messages via a socket.
void worker()
Actual task that sends data to the socket server.
std::condition_variable m_cv
std::pair< int, std::string > m_message
bool Send(int aService, const std::string &aMessage)
Attempt to send a message if the thread is available.
virtual void ExecuteRemoteCommand(const char *cmdline)
Execute a remote command sent via socket (to port KICAD_PCB_PORT_SERVICE_NUMBER, currently 4242).
void CreateServer(int service, bool local=true)
std::vector< wxSocketBase * > m_sockets
interprocess communication
void OnSockRequestServer(wxSocketEvent &evt)
void OnSockRequest(wxSocketEvent &evt)
wxSocketServer * m_socketServer
std::unique_ptr< ASYNC_SOCKET_HOLDER > socketHolder
bool SendCommand(int aService, const std::string &aMessage)
Used by a client to sent (by a socket connection) a data to a server.
static char client_ipc_buffer[IPC_BUF_SIZE]
static const wxString HOSTNAME(wxT("localhost"))
#define KICAD_PCB_PORT_SERVICE_NUMBER
< Pcbnew listens on this port for commands from Eeschema
@ ID_EDA_SOCKET_EVENT_SERV