Commit 0c47c97e23b53124c65f1688f8ef5c818b107607

Authored by Jürgen Knödlseder
1 parent 5fec60e2

Remove debut outputs.

include/GVOHub.hpp
... ... @@ -142,7 +142,7 @@ protected:
142 142 std::string m_hub_port; //!< Hub port (extracted from XML-RPC endpoint)
143 143 std::string m_version; //!< The version of the SAMP Standard Profile implemented by the hub
144 144 std::string m_hub_id; //!< Hub identifier used by the hub when it sends message itself rather than forwarding from others
145   - int m_socket; //!< Hub socket
  145 + socklen_t m_socket; //!< Hub socket
146 146 int m_cback_socket; //!< Hub socket to callback clients
147 147 clients* m_clients; //!< Structure of registered clients
148 148 void* m_shmem; //!< Pointer to shared memory address
... ...
src/vo/GVOHub.cpp
... ... @@ -246,7 +246,7 @@ void GVOHub::init_members(void)
246 246 m_version = "1.3";
247 247 m_hub_id = "gammalib_hub";
248 248 m_socket = -1; // Signals no socket
249   - m_cback_socket = -1;
  249 + m_cback_socket = -1; // Signals no socket
250 250 m_clients = NULL;
251 251 m_shmem = NULL;
252 252 m_shmem_handler = 0;
... ... @@ -314,7 +314,16 @@ void GVOHub::copy_members(const GVOHub&amp; hub)
314 314 ***************************************************************************/
315 315 void GVOHub::free_members(void)
316 316 {
317   -
  317 + // Close sockets
  318 + if (m_socket != -1) {
  319 + close(m_socket);
  320 + m_socket = -1;
  321 + }
  322 + if (m_cback_socket != -1) {
  323 + close(m_cback_socket);
  324 + m_cback_socket = -1;
  325 + }
  326 +
318 327 // Remove lockfile
319 328 std::string lockurl = get_hub_lockfile();
320 329 std::remove(lockurl.c_str());
... ... @@ -356,10 +365,10 @@ void GVOHub::start_hub(void)
356 365 }
357 366  
358 367 // Create Hub socket
359   - socklen_t hub_socket = socket(AF_INET, SOCK_STREAM, 0);
  368 + m_socket = socket(AF_INET, SOCK_STREAM, 0);
360 369  
361 370 // Creation of hub main socket
362   - if (hub_socket < 0) {
  371 + if (m_socket < 0) {
363 372 std::string msg = "Unable to create Hub socket. Errno="+
364 373 gammalib::str(errno);
365 374 throw GException::runtime_error(G_START_HUB, msg);
... ... @@ -367,13 +376,13 @@ void GVOHub::start_hub(void)
367 376  
368 377 // Set hub main socket to allow multiple connections
369 378 int opt = 1;
370   - if (setsockopt(hub_socket, SOL_SOCKET, SO_REUSEADDR, (char*)&opt, sizeof(opt)) < 0) {
  379 + if (setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, (char*)&opt, sizeof(opt)) < 0) {
371 380 std::string msg = "Unable to set Hub socket to multiple connections."
372 381 " Errno="+gammalib::str(errno);
373 382 throw GException::runtime_error(G_START_HUB, msg);
374 383 }
375 384 #ifdef SO_REUSEPORT
376   - if (setsockopt(hub_socket, SOL_SOCKET, SO_REUSEPORT, (char*)&opt, sizeof(opt)) < 0) {
  385 + if (setsockopt(m_socket, SOL_SOCKET, SO_REUSEPORT, (char*)&opt, sizeof(opt)) < 0) {
377 386 std::string msg = "Unable to set Hub socket to multiple connections."
378 387 " Errno="+gammalib::str(errno);
379 388 throw GException::runtime_error(G_START_HUB, msg);
... ... @@ -381,7 +390,7 @@ void GVOHub::start_hub(void)
381 390 #endif
382 391  
383 392 // Server socket is opened. Now, bind it to the port, with family etc.
384   - if (bind(hub_socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
  393 + if (bind(m_socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
385 394 std::string msg = "Unable to bind Hub socket to server socket. Errno="+
386 395 gammalib::str(errno);
387 396 throw GException::runtime_error(G_START_HUB, msg);
... ... @@ -389,7 +398,7 @@ void GVOHub::start_hub(void)
389 398  
390 399 // Now start listening for the clients: 5 requests simultaneously pending
391 400 // at maximum
392   - if (listen(hub_socket, 5) < 0) {
  401 + if (listen(m_socket, 5) < 0) {
393 402 std::string msg = "Unable to start listening on Hub socket. Errno="+
394 403 gammalib::str(errno);
395 404 throw GException::runtime_error(G_START_HUB, msg);
... ... @@ -403,8 +412,8 @@ void GVOHub::start_hub(void)
403 412 while (1) {
404 413  
405 414 // Accept connection from the client
406   - socklen_t newsocket = accept(hub_socket, (struct sockaddr *)&cli_addr, &clilen);
407   - if (newsocket < 0) {
  415 + socklen_t socket = accept(m_socket, (struct sockaddr *)&cli_addr, &clilen);
  416 + if (socket < 0) {
408 417 std::string msg = "Client connection to socket not accepted.";
409 418 throw GException::runtime_error(G_START_HUB, msg);
410 419 }
... ... @@ -421,15 +430,13 @@ void GVOHub::start_hub(void)
421 430 if (pid == 0) {
422 431  
423 432 // Handle request
424   - handle_request(newsocket);
  433 + handle_request(socket);
425 434  
426 435 // Exit child process
427 436 exit(0);
428 437 }
429 438  
430   - // ... otherwise we are in the parent process. Set SIG_IGN to child
431   - // so that the kernel can close it without sending it to zombie state
432   - // <defunct>
  439 + // ... otherwise we are in the parent process.
433 440 else {
434 441  
435 442 // Wait for the child process to terminate
... ... @@ -437,9 +444,10 @@ void GVOHub::start_hub(void)
437 444 waitpid(pid, &status, 0);
438 445  
439 446 // Close socket
440   - close(newsocket);
  447 + close(socket);
441 448  
442   - // Send SIG_IGN to child process
  449 + // Send SIG_IGN to the child process so that the kernel can
  450 + // close it without sending it to zombie state <defunct>
443 451 std::signal(pid, SIG_IGN);
444 452  
445 453 // If we have received a shutdown request then exit the event
... ... @@ -453,9 +461,8 @@ void GVOHub::start_hub(void)
453 461 } // endwhile: main event loop
454 462  
455 463 // Close socket
456   - close(hub_socket);
457   -std::cout << "\n\n*** Hub shutdown ***" << std::endl;
458   -system("netstat -npta");
  464 + close(m_socket);
  465 + m_socket = -1;
459 466  
460 467 // Return
461 468 return;
... ...
test/test_GVO.cpp
... ... @@ -90,8 +90,6 @@ void TestGVO::test_GVOHub(void)
90 90 {
91 91 // Declare thread
92 92 pthread_t thread;
93   -std::cout << "\n*** Before start of thread ***" << std::endl;
94   -system("netstat -npta");
95 93  
96 94 // Start Hub in a thread
97 95 test_try("Start hub");
... ... @@ -102,8 +100,6 @@ system(&quot;netstat -npta&quot;);
102 100 catch (std::exception &e) {
103 101 test_try_failure(e);
104 102 }
105   -std::cout << "\n*** After start of thread ***" << std::endl;
106   -system("netstat -npta");
107 103  
108 104 // Test Hub connection
109 105 GVOClient client;
... ... @@ -121,14 +117,8 @@ system(&quot;netstat -npta&quot;);
121 117 // Disconnect client
122 118 client.disconnect();
123 119  
124   - // Cancel thread. We do this here so that for the next test
125   - // there is no Hub anymore. We do some sleeping to assure that
126   - // the thread has been canceled.
127   - //pthread_cancel(thread);
128   - //sleep(1);
  120 + // We now shutdown the Hub via the client
129 121 client.shutdown_hub();
130   -std::cout << "\n*** After thread canel ***" << std::endl;
131   -system("netstat -npta");
132 122  
133 123 // Return
134 124 return;
... ... @@ -151,17 +141,15 @@ void TestGVO::test_GVOClient(void)
151 141 test_try_failure(e);
152 142 }
153 143  
154   -std::cout << "\n*** Before client connect ***" << std::endl;
155   -system("netstat -npta");
156 144 // Create client
157 145 GVOClient client;
158 146  
  147 + // Test ping
  148 + test_assert(!client.ping_hub(), "Ping Hub (should not be alive).");
  149 +
159 150 // Connect client
160 151 client.connect();
161 152 test_assert(client.is_connected(), "Check for connection.");
162   - //std::cout << client << std::endl;
163   -std::cout << "\n*** After client connect ***" << std::endl;
164   -system("netstat -npta");
165 153  
166 154 // Test ping
167 155 test_assert(client.ping_hub(), "Ping Hub.");
... ... @@ -169,7 +157,6 @@ system(&quot;netstat -npta&quot;);
169 157 // Disconnect client
170 158 client.disconnect();
171 159 test_assert(!client.is_connected(), "Check for disconnection.");
172   - //std::cout << client << std::endl;
173 160  
174 161 // Test ping
175 162 test_assert(client.ping_hub(), "Ping Hub.");
... ... @@ -177,6 +164,9 @@ system(&quot;netstat -npta&quot;);
177 164 // Shutdown VO Hub
178 165 client.shutdown_hub();
179 166  
  167 + // Test ping
  168 + test_assert(!client.ping_hub(), "Ping Hub (should not be alive).");
  169 +
180 170 // Return
181 171 return;
182 172 }
... ...