@@ -164,50 +164,47 @@ int EventBroadcaster::getListeningPort() const
164164
165165int EventBroadcaster::setListeningPort (int port, bool forceRestart)
166166{
167+ int status = 0 ;
167168 int currPort = getListeningPort ();
168- if (currPort == port && ! forceRestart)
169+ if (( currPort != port) || forceRestart)
169170 {
170- return 0 ;
171- }
172-
173- int status = 0 ;
174-
175171#ifdef ZEROMQ
176- // unbind current socket (if any) to free up port
177- if (zmqSocket != nullptr )
178- {
179- zmqSocket->unbind ();
180- }
172+ // unbind current socket (if any) to free up port
173+ if (zmqSocket != nullptr )
174+ {
175+ zmqSocket->unbind ();
176+ }
181177
182- ScopedPointer<ZMQSocket> newSocket = new ZMQSocket ();
178+ ScopedPointer<ZMQSocket> newSocket = new ZMQSocket ();
183179
184- if (!newSocket->isValid ())
185- {
186- status = zmq_errno ();
187- std::cout << " Failed to create socket: " << zmq_strerror (status) << std::endl;
188- }
189- else
190- {
191- if (0 != newSocket->bind (port))
180+ if (!newSocket->isValid ())
192181 {
193182 status = zmq_errno ();
194- std::cout << " Failed to bind to port " << port << " : "
195- << zmq_strerror (status) << std::endl;
183+ std::cout << " Failed to create socket: " << zmq_strerror (status) << std::endl;
196184 }
197185 else
198186 {
199- // success
200- zmqSocket = newSocket;
187+ if (0 != newSocket->bind (port))
188+ {
189+ status = zmq_errno ();
190+ std::cout << " Failed to bind to port " << port << " : "
191+ << zmq_strerror (status) << std::endl;
192+ }
193+ else
194+ {
195+ // success
196+ zmqSocket = newSocket;
197+ }
201198 }
202- }
203199
204- if (status != 0 && zmqSocket)
205- {
206- // try to rebind current socket to previous port
207- zmqSocket->bind (currPort);
208- }
200+ if (status != 0 && zmqSocket)
201+ {
202+ // try to rebind current socket to previous port
203+ zmqSocket->bind (currPort);
204+ }
209205
210206#endif
207+ }
211208
212209 // update editor
213210 auto editor = static_cast <EventBroadcasterEditor*>(getEditor ());
0 commit comments