Keep track of open sockets and dispose of them in d'tor.

Fixes: lp:1760936
* https://bugs.launchpad.net/kicad/+bug/1760936
This commit is contained in:
Jeff Young 2018-04-04 12:01:47 +01:00
parent 5e36fe8df7
commit df43f071e1
6 changed files with 41 additions and 38 deletions

View File

@ -132,6 +132,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
m_galDisplayOptions( std::make_unique<KIGFX::GAL_DISPLAY_OPTIONS>() )
{
m_socketServer = nullptr;
m_drawToolBar = NULL;
m_optionsToolBar = NULL;
m_auxiliaryToolBar = NULL;
@ -216,6 +217,13 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
{
delete m_socketServer;
for( auto socket : m_sockets )
{
socket->Shutdown();
socket->Destroy();
}
if( m_canvasTypeDirty )
saveCanvasTypeSetting( m_canvasType );

View File

@ -46,7 +46,7 @@ static char client_ipc_buffer[IPC_BUF_SIZE];
/* Function to initialize a server socket
*/
wxSocketServer* CreateServer( wxWindow* window, int service, bool local )
void EDA_DRAW_FRAME::CreateServer( int service, bool local )
{
wxIPV4address addr;
@ -57,16 +57,12 @@ wxSocketServer* CreateServer( wxWindow* window, int service, bool local )
if( local )
addr.Hostname( HOSTNAME );
wxSocketServer* server = new wxSocketServer( addr );
delete m_socketServer;
m_socketServer = new wxSocketServer( addr );
if( server )
{
server->SetNotify( wxSOCKET_CONNECTION_FLAG );
server->SetEventHandler( *window, ID_EDA_SOCKET_EVENT_SERV );
server->Notify( true );
}
return server;
m_socketServer->SetNotify( wxSOCKET_CONNECTION_FLAG );
m_socketServer->SetEventHandler( *this, ID_EDA_SOCKET_EVENT_SERV );
m_socketServer->Notify( true );
}
@ -106,17 +102,19 @@ void EDA_DRAW_FRAME::OnSockRequest( wxSocketEvent& evt )
*/
void EDA_DRAW_FRAME::OnSockRequestServer( wxSocketEvent& evt )
{
wxSocketBase* sock2;
wxSocketBase* socket;
wxSocketServer* server = (wxSocketServer*) evt.GetSocket();
sock2 = server->Accept();
socket = server->Accept();
if( sock2 == NULL )
if( socket == NULL )
return;
sock2->Notify( true );
sock2->SetEventHandler( *this, ID_EDA_SOCKET_EVENT );
sock2->SetNotify( wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG );
m_sockets.push_back( socket );
socket->Notify( true );
socket->SetEventHandler( *this, ID_EDA_SOCKET_EVENT );
socket->SetNotify( wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG );
}

View File

@ -83,7 +83,7 @@ static struct IFACE : public KIFACE_I
if( Kiface().IsSingle() )
{
// only run this under single_top, not under a project manager.
CreateServer( frame, KICAD_SCH_PORT_SERVICE_NUMBER );
frame->CreateServer( KICAD_SCH_PORT_SERVICE_NUMBER );
}
return frame;
}

View File

@ -32,6 +32,7 @@
#include <gal/gal_display_options.h>
#include <gal/color4d.h>
#include <class_draw_panel_gal.h>
#include "hotkeys_basic.h"
class wxSingleInstanceChecker;
class EDA_HOTKEY;
@ -72,9 +73,13 @@ class EDA_DRAW_FRAME : public KIWAY_PLAYER
protected:
wxSocketServer* m_socketServer;
std::vector<wxSocketBase*> m_sockets; ///< interprocess communication
std::unique_ptr<wxSingleInstanceChecker> m_file_checker; ///< prevents opening same file multiple times.
EDA_HOTKEY_CONFIG* m_hotkeysDescrList;
EDA_HOTKEY_CONFIG* m_hotkeysDescrList;
int m_LastGridSizeId; // the command id offset (>= 0) of the last selected grid
// 0 is for the grid corresponding to
// a wxCommand ID = ID_POPUP_GRID_LEVEL_1000.
@ -772,6 +777,7 @@ public:
void CopyToClipboard( wxCommandEvent& event );
/* interprocess communication */
void CreateServer( int service, bool local = true );
void OnSockRequest( wxSocketEvent& evt );
void OnSockRequestServer( wxSocketEvent& evt );

View File

@ -45,7 +45,6 @@
#define MSG_TO_PCB KICAD_PCB_PORT_SERVICE_NUMBER
#define MSG_TO_SCH KICAD_SCH_PORT_SERVICE_NUMBER
wxSocketServer* CreateServer( wxWindow * window, int port, bool local = true );
bool SendCommand( int port, const char* cmdline );
#endif // EDA_DDE_H_

View File

@ -106,50 +106,42 @@ static struct IFACE : public KIFACE_I
wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
{
wxWindow* frame = NULL;
switch( aClassId )
{
case FRAME_PCB:
frame = dynamic_cast< wxWindow* >( new PCB_EDIT_FRAME( aKiway, aParent ) );
{
auto frame = new PCB_EDIT_FRAME( aKiway, aParent );
#if defined( KICAD_SCRIPTING )
// give the scripting helpers access to our frame
ScriptingSetPcbEditFrame( (PCB_EDIT_FRAME*) frame );
ScriptingSetPcbEditFrame( frame );
#endif
if( Kiface().IsSingle() )
{
// only run this under single_top, not under a project manager.
CreateServer( frame, KICAD_PCB_PORT_SERVICE_NUMBER );
frame->CreateServer( KICAD_PCB_PORT_SERVICE_NUMBER );
}
break;
return frame;
}
case FRAME_PCB_MODULE_EDITOR:
frame = dynamic_cast< wxWindow* >( new FOOTPRINT_EDIT_FRAME( aKiway, aParent ) );
break;
return new FOOTPRINT_EDIT_FRAME( aKiway, aParent );
case FRAME_PCB_MODULE_VIEWER:
case FRAME_PCB_MODULE_VIEWER_MODAL:
frame = dynamic_cast< wxWindow* >( new FOOTPRINT_VIEWER_FRAME( aKiway, aParent,
FRAME_T( aClassId ) ) );
break;
return new FOOTPRINT_VIEWER_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
case FRAME_PCB_FOOTPRINT_WIZARD_MODAL:
frame = dynamic_cast< wxWindow* >( new FOOTPRINT_WIZARD_FRAME( aKiway, aParent,
FRAME_T( aClassId ) ) );
break;
return new FOOTPRINT_WIZARD_FRAME( aKiway, aParent, FRAME_T( aClassId ) );
case FRAME_PCB_FOOTPRINT_PREVIEW:
frame = dynamic_cast< wxWindow* >( FOOTPRINT_PREVIEW_PANEL::New( aKiway, aParent ) );
break;
return dynamic_cast< wxWindow* >( FOOTPRINT_PREVIEW_PANEL::New( aKiway, aParent ) );
default:
break;
return nullptr;
}
return frame;
}
/**