File tree Expand file tree Collapse file tree 4 files changed +26
-10
lines changed
Expand file tree Collapse file tree 4 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,11 @@ namespace sofa::openigtlink
1818
1919 iGTLinkBase::~iGTLinkBase ()
2020 {
21- m_receiverThread ->stopThread ();
22- delete m_receiverThread;
21+ if (m_receiverThread)
22+ {
23+ m_receiverThread ->stopThread ();
24+ delete m_receiverThread;
25+ }
2326 }
2427
2528 void iGTLinkBase::addMessageObject (iGTLinkMessageBase *_object)
@@ -86,7 +89,9 @@ namespace sofa::openigtlink
8689 {
8790 if (sofa::simulation::AnimateBeginEvent::checkEventType (event))
8891 {
89- if (d_componentState.getValue ()!=ComponentState::Valid)
92+ // If we are not a sender, then we let the thread deal with connexions to avoid having
93+ // to slow everything with mutex
94+ if (d_sender.getValue () && d_componentState.getValue ()!=ComponentState::Valid)
9095 {
9196 if (!tryConnect ()) return ;
9297 }
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ namespace sofa::openigtlink
1616 {
1717 public:
1818 iGTLinkClient ();
19- ~iGTLinkClient () = default ;
19+ ~iGTLinkClient ();
2020
2121 void init ();
2222
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ iGTLinkClient::iGTLinkClient()
1212
1313}
1414
15+ iGTLinkClient::~iGTLinkClient ()
16+ {
17+ m_socket->CloseSocket ();
18+ }
19+
1520
1621void iGTLinkClient::init ()
1722{
@@ -50,13 +55,16 @@ bool iGTLinkClient::tryConnect()
5055
5156bool iGTLinkClient::isConnected ()
5257{
53- bool connected = m_socket->GetConnected ();
58+ bool connected = m_socket && m_socket ->GetConnected ();
5459 if (!connected)
5560 {
5661 msg_warning (this ) << " Socket not connected to hostname : " << d_hostname.getValue () << " :" <<d_port.getValue ();
5762 d_componentState.setValue (ComponentState::Loading);
5863 }
59- d_componentState.setValue (ComponentState::Valid);
64+ else
65+ {
66+ d_componentState.setValue (ComponentState::Valid);
67+ }
6068 return connected;
6169}
6270
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ bool iGTLinkServer::tryConnect()
4545 m_socket = m_serverSocket->WaitForConnection (10 );
4646 if (!m_socket)
4747 {
48- std::cout << ( std::string ( " No client connected currently on port :" ) + std::to_string (d_port.getValue ())) <<std::endl;
48+ std::cout << " No client connected currently on port :" << std::to_string (d_port.getValue ())<<std::endl;
4949 d_componentState.setValue (ComponentState::Loading);
5050 }
5151 else
@@ -69,13 +69,16 @@ bool iGTLinkServer::tryConnect()
6969
7070bool iGTLinkServer::isConnected ()
7171{
72- bool connected = m_socket->GetConnected ();
72+
73+ bool connected = m_socket && m_socket->GetConnected ();
7374 if (!connected)
7475 {
75- msg_warning (std::string (" Socket not connected to port : " ) + std::to_string (d_port.getValue ()));
7676 d_componentState.setValue (ComponentState::Loading);
7777 }
78- d_componentState.setValue (ComponentState::Valid);
78+ else
79+ {
80+ d_componentState.setValue (ComponentState::Valid);
81+ }
7982 return connected;
8083}
8184
You can’t perform that action at this time.
0 commit comments