Commit 7ecadae80eed7aaad0f3e919863748418667dba1

Authored by Jürgen Knödlseder
1 parent f0d40796

Close socket after usage.

include/GVOClient.hpp
... ... @@ -41,13 +41,16 @@
41 41 *
42 42 * This class implements a client for the Virtual Observatory. Upon
43 43 * construction of an instance of the class, the client will search for a
44   - * SAMP Hub. If no such Hub exists, a GammaLib owned Hub will be started
45   - * using the GVOHub class. Once a Hub is running, the client will retrieve
46   - * its information and store it.
  44 + * VO Hub. The has_hub() method signals whether VO Hub information was
  45 + * found.
47 46 *
48   - * The connect() and disconnect() methods exist to connect or disconnect
49   - * from the Hub. Connecting means opening a socket to the Hub and registering
50   - * the client to the Hub.
  47 + * The connect() method will connect the client to the VO Hub. If no VO
  48 + * Hub has been found or if the VO Hub that was found is not alive the
  49 + * client will start an own VO Hub using the GVOHub class. The
  50 + * is_connected() method signals whether the client is connected to a
  51 + * Hub.
  52 + *
  53 + * The disconnect() method disconnects a client from the VO Hub.
51 54 ***************************************************************************/
52 55 class GVOClient : public GBase {
53 56  
... ...
src/vo/GVOClient.cpp
... ... @@ -319,6 +319,12 @@ GXml GVOClient::execute(const std::string& request) const
319 319 xml = GXml(response.substr(start, std::string::npos));
320 320 }
321 321  
  322 + // Close socket
  323 + if (m_socket != -1) {
  324 + close(m_socket);
  325 + m_socket = -1;
  326 + }
  327 +
322 328 } // endif: connection has been established
323 329  
324 330 // Return response
... ... @@ -363,11 +369,10 @@ std::string GVOClient::print(const GChatter& chatter) const
363 369 if (!m_client_key.empty()) {
364 370 result.append("registered as \""+m_client_id);
365 371 result.append("\" on Hub \""+m_hub_id);
366   - result.append("\" via socket "+gammalib::str(m_socket));
  372 + result.append("\".");
367 373 }
368 374 else {
369   - result.append("established on socket ");
370   - result.append(gammalib::str(m_socket));
  375 + result.append("established.");
371 376 }
372 377 }
373 378 }
... ...
test/test_GVO.cpp
... ... @@ -148,6 +148,7 @@ void TestGVO::test_GVOClient(void)
148 148  
149 149 // Connect client
150 150 client.connect();
  151 + test_assert(client.is_connected(), "Check for connection.");
151 152 //std::cout << client << std::endl;
152 153  
153 154 // Test ping
... ... @@ -155,6 +156,7 @@ void TestGVO::test_GVOClient(void)
155 156  
156 157 // Disconnect client
157 158 client.disconnect();
  159 + test_assert(!client.is_connected(), "Check for disconnection.");
158 160 //std::cout << client << std::endl;
159 161  
160 162 // Test ping
... ...