Esempio n. 1
0
bool SINQHMListener::connect(const Poco::Net::SocketAddress &address) {
  std::string host = address.toString();
  std::string::size_type i = host.find(':');
  if (i != std::string::npos) {
    host.erase(i);
  }
  httpcon.setHost(host);
  httpcon.setPort(address.port());
  httpcon.setKeepAlive(true);
  connected = true;
  return true;
}
Esempio n. 2
0
bool isLocalAddress(const Poco::Net::SocketAddress & address, UInt16 clickhouse_port)
{
    static auto interfaces = Poco::Net::NetworkInterface::list();

    if (clickhouse_port == address.port())
    {
        return interfaces.end() != std::find_if(interfaces.begin(), interfaces.end(),
            [&] (const Poco::Net::NetworkInterface & interface)
            {
                /** Compare the addresses without taking into account `scope`.
                  * Theoretically, this may not be correct - depends on `route` setting
                  *  - through which interface we will actually access the specified address.
                  */
                return interface.address().length() == address.host().length()
                    && 0 == memcmp(interface.address().addr(), address.host().addr(), address.host().length());
            });
    }

    return false;
}
Esempio n. 3
0
/** Connect to the specified address and checks that is valid
  *  @param address   The IP address and port to contact (port is ignored).
  *  @return True if the connection was successfully established
  */
bool ISISHistoDataListener::connect(const Poco::Net::SocketAddress &address) {

  m_daeName = address.toString();
  // remove the port part
  auto i = m_daeName.find(':');
  if (i != std::string::npos) {
    m_daeName.erase(i);
  }

  // set IDC reporter function for errors
  IDCsetreportfunc(&ISISHistoDataListener::IDCReporter);

  if (IDCopen(m_daeName.c_str(), 0, 0, &m_daeHandle, address.port()) != 0) {
    m_daeHandle = NULL;
    return false;
  }

  m_numberOfPeriods = getInt("NPER");
  g_log.information() << "Number of periods " << m_numberOfPeriods << std::endl;

  // Set the spectra list to load
  std::vector<specid_t> spectra = getProperty("SpectraList");
  if (!spectra.empty()) {
    setSpectra(spectra);
  }

  // Set the period list to load
  std::vector<int> periodList = getProperty("PeriodList");
  if (!periodList.empty()) {
    setPeriods(periodList);
  }

  loadSpectraMap();

  loadTimeRegimes();

  return true;
}