Changeset 165:36e703e3df51 in finroc_plugins_tcp


Ignore:
Timestamp:
28.06.2018 12:15:36 (3 years ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
14.08
Children:
167:b27ce10f0427, 175:867742b1f15b
Phase:
public
Message:

Makes TCP plugin more robust with respect to invalid network addresses to connect to (typically provided by user)

Location:
internal
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • internal/tPeerImplementation.cpp

    r149 r165  
    135135      endpoints = ParseAndResolveNetworkAddress(connect_to); 
    136136      Connect("no endpoints resolved"); 
     137    } 
     138    catch (const std::invalid_argument &e) 
     139    { 
     140      FINROC_LOG_PRINT(ERROR, "Could not connect to invalid address '", connect_to, "'. Reason: ", e.what()); 
    137141    } 
    138142    catch (const std::exception &e) 
     
    699703  if (actively_connect) 
    700704  { 
    701     for (auto it = connect_to.begin(); it != connect_to.end(); ++it) 
    702     { 
    703       FINROC_LOG_PRINT(DEBUG, "Connecting to ", *it); 
    704       tAddressConnectorTask connector_task(*this, *it); 
    705     } 
    706     connect_to.clear(); 
     705    std::vector<std::string> connect_to_copy = std::move(connect_to); 
     706    for (auto & address : connect_to_copy) 
     707    { 
     708      FINROC_LOG_PRINT(DEBUG, "Connecting to ", address); 
     709      tAddressConnectorTask connector_task(*this, address); 
     710    } 
    707711 
    708712    for (auto it = other_peers.begin(); it != other_peers.end(); ++it) 
  • internal/util.cpp

    r117 r165  
    7777  if (colon_pos == std::string::npos) 
    7878  { 
    79     throw std::runtime_error("Could not parse network address: " + network_address); 
     79    throw std::invalid_argument("Could not parse network address: " + network_address); 
    8080  } 
    8181  int port = atoi(network_address.substr(colon_pos + 1).c_str()); 
     
    8383  if (port <= 20 || port > 65535) 
    8484  { 
    85     throw std::runtime_error("Invalid port in network address: " + network_address); 
     85    throw std::invalid_argument("Invalid port in network address: " + network_address); 
    8686  } 
    8787  try 
  • internal/util.h

    r116 r165  
    7979/*! 
    8080 * Parses and resolves network address in specified string 
    81  * Throws exception if address cannot be parsed or resolved 
    8281 * 
    8382 * \param network_address Network address (e.g. 'localhost:4444') 
    8483 * \return std::vector of TCP endpoints corresponding to this address 
     84 * 
     85 * \throw Throws std::invalid_argument if address cannot be parsed 
     86 * \throw Throws std::runtime_error if address cannot be resolved 
    8587 */ 
    8688std::vector<boost::asio::ip::tcp::endpoint> ParseAndResolveNetworkAddress(const std::string& network_address); 
Note: See TracChangeset for help on using the changeset viewer.