25 #include <condition_variable> 36 static const wxString
HOSTNAME( wxT(
"localhost" ) );
39 #define IPC_BUF_SIZE 4096 48 addr.Service( service );
66 wxSocketBase* sock = evt.GetSocket();
68 switch( evt.GetSocketEvent() )
73 if( sock->LastCount() == 0 )
77 len = 1 + sock->LastCount();
87 wxPrintf( wxT(
"EDA_DRAW_FRAME::OnSockRequest() error: Invalid event !" ) );
96 wxSocketServer* server = (wxSocketServer*) evt.GetSocket();
98 socket = server->Accept();
100 if( socket ==
nullptr )
105 socket->Notify(
true );
107 socket->SetNotify( wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG );
129 wxSocketClient* client =
new wxSocketClient;
135 client->Connect( addr,
false );
146 std::lock_guard<std::mutex> lock(
m_mutex );
169 bool Send(
int aService,
const std::string& aMessage )
174 std::lock_guard<std::mutex> lock(
m_mutex );
176 m_message = std::make_pair( aService, aMessage );
192 std::unique_lock<std::mutex> lock(
m_mutex );
206 wxSocketClient* sock_client;
211 addr.Service( port );
263 sock_client =
new wxSocketClient( wxSOCKET_BLOCK );
264 sock_client->SetTimeout( 1 );
265 sock_client->Connect( addr,
false );
266 sock_client->WaitOnConnect( 0, 250 );
268 if( sock_client->Ok() && sock_client->IsConnected() )
270 sock_client->SetFlags( wxSOCKET_NOWAIT );
271 sock_client->Write( message.c_str(), message.length() );
274 sock_client->Close();
275 sock_client->Destroy();
bool Send(int aService, const std::string &aMessage)
Attempt to send a message if the thread is available.
#define KICAD_PCB_PORT_SERVICE_NUMBER
< Pcbnew listens on this port for commands from Eeschema
bool SendCommand(int aService, const std::string &aMessage)
Used by a client to sent (by a socket connection) a data to a server.
Spin up a thread to send messages via a socket.
static char client_ipc_buffer[IPC_BUF_SIZE]
void CreateServer(int service, bool local=true)
virtual void ExecuteRemoteCommand(const char *cmdline)
Execute a remote command sent via socket (to port KICAD_PCB_PORT_SERVICE_NUMBER, currently 4242).
static const wxString HOSTNAME(wxT("localhost"))
void OnSockRequest(wxSocketEvent &evt)
std::condition_variable m_cv
void OnSockRequestServer(wxSocketEvent &evt)
std::pair< int, std::string > m_message
wxSocketServer * m_socketServer
void worker()
Actual task that sends data to the socket server.
std::vector< wxSocketBase * > m_sockets
interprocess communication
std::unique_ptr< ASYNC_SOCKET_HOLDER > socketHolder