Exemplo n.º 1
0
 static typename Visitor::result_type
 apply_impl(Self& x, Visitor& f) {
   switch (x.type_) {
     default: CAF_RAISE_ERROR("invalid type found");
     CAF_VARIANT_CASE(0);
     CAF_VARIANT_CASE(1);
     CAF_VARIANT_CASE(2);
     CAF_VARIANT_CASE(3);
     CAF_VARIANT_CASE(4);
     CAF_VARIANT_CASE(5);
     CAF_VARIANT_CASE(6);
     CAF_VARIANT_CASE(7);
     CAF_VARIANT_CASE(8);
     CAF_VARIANT_CASE(9);
     CAF_VARIANT_CASE(10);
     CAF_VARIANT_CASE(11);
     CAF_VARIANT_CASE(12);
     CAF_VARIANT_CASE(13);
     CAF_VARIANT_CASE(14);
     CAF_VARIANT_CASE(15);
     CAF_VARIANT_CASE(16);
     CAF_VARIANT_CASE(17);
     CAF_VARIANT_CASE(18);
     CAF_VARIANT_CASE(19);
   }
 }
Exemplo n.º 2
0
typename std::enable_if<
  std::is_same<
    error,
    decltype(std::declval<deserializer&>().apply(std::declval<T&>()))
  >::value
>::type
operator&(deserializer& source, T& x) {
  auto e = source.apply(x);
  if (e)
    CAF_RAISE_ERROR(to_string(e));
}
Exemplo n.º 3
0
void for_each_address(bool get_ipv4, bool get_ipv6, F fun) {
  ULONG tmp_size = 16 * 1024; // try 16kb buffer first
  IP_ADAPTER_ADDRESSES* tmp = nullptr;
  constexpr size_t max_tries = 3;
  size_t try_nr = 0;
  int retval = 0;
  do {
    if (tmp)
      free(tmp);
    tmp = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(malloc(tmp_size));
    if (!tmp)
      CAF_RAISE_ERROR("malloc() failed");
    retval = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX,
                                  nullptr, tmp, &tmp_size);
  } while (retval == ERROR_BUFFER_OVERFLOW && ++try_nr < max_tries);
  std::unique_ptr<IP_ADAPTER_ADDRESSES, decltype(free)*> ifs{tmp, free};
  if (retval != NO_ERROR) {
    std::cerr << "Call to GetAdaptersAddresses failed with error: "
              << retval << std::endl;
    if (retval == ERROR_NO_DATA) {
      std::cerr << "No addresses were found for the requested parameters"
                << std::endl;
    } else {
      void* msgbuf = nullptr;
      if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
                        | FORMAT_MESSAGE_FROM_SYSTEM
                        | FORMAT_MESSAGE_IGNORE_INSERTS,
                        nullptr, retval,
                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                        (LPTSTR) &msgbuf, 0, nullptr)) {
        printf("Error: %s", static_cast<char*>(msgbuf));
        LocalFree(msgbuf);
      }
    }
    return;
  }
  char buffer[INET6_ADDRSTRLEN];
  for (auto i = ifs.get(); i != nullptr; i = i->Next) {
    for (auto j = i->FirstUnicastAddress; j != nullptr; j = j->Next) {
      auto addr = j->Address.lpSockaddr;
      auto family = fetch_addr_str(get_ipv4, get_ipv6, buffer, addr);
      if (family != AF_UNSPEC)
        fun(i->AdapterName, family == AF_INET ? protocol::ipv4 : protocol::ipv6,
            false, buffer);
    }
  }
}
Exemplo n.º 4
0
platform_ptr platform::create(cl_platform_id platform_id,
                              unsigned start_id) {
  vector<unsigned> device_types = {CL_DEVICE_TYPE_GPU,
                                   CL_DEVICE_TYPE_ACCELERATOR,
                                   CL_DEVICE_TYPE_CPU};
  vector<cl_device_id> ids;
  for (cl_device_type device_type : device_types) {
    auto known = ids.size();
    cl_uint discoverd;
    auto err = clGetDeviceIDs(platform_id, device_type, 0, nullptr, &discoverd);
    if (err == CL_DEVICE_NOT_FOUND) {
      continue; // no devices of the type found
    } else if (err != CL_SUCCESS) {
      throwcl("clGetDeviceIDs", err);
    }
    ids.resize(known + discoverd);
    v2callcl(CAF_CLF(clGetDeviceIDs), platform_id, device_type,
             discoverd, (ids.data() + known));
  }
  vector<detail::raw_device_ptr> devices;
  devices.resize(ids.size());
  auto lift = [](cl_device_id ptr) {
    return detail::raw_device_ptr{ptr, false};
  };
  transform(ids.begin(), ids.end(), devices.begin(), lift);
  detail::raw_context_ptr context;
  context.reset(v2get(CAF_CLF(clCreateContext), nullptr,
                      static_cast<unsigned>(ids.size()),
                      ids.data(), pfn_notify, nullptr),
                false);
  vector<device_ptr> device_information;
  for (auto& device_id : devices) {
    device_information.push_back(device::create(context, device_id,
                                                start_id++));
  }
  if (device_information.empty())
    CAF_RAISE_ERROR("no devices for the platform found");
  auto name = platform_info(platform_id, CL_PLATFORM_NAME);
  auto vendor = platform_info(platform_id, CL_PLATFORM_VENDOR);
  auto version = platform_info(platform_id, CL_PLATFORM_VERSION);
  return make_counted<platform>(platform_id, move(context), move(name),
                                move(vendor), move(version),
                                move(device_information));
}
opencl::manager& actor_system::opencl_manager() const {
  if (!opencl_manager_)
    CAF_RAISE_ERROR("cannot access opencl manager: module not loaded");
  return *opencl_manager_;
}
io::middleman& actor_system::middleman() {
  if (!middleman_)
    CAF_RAISE_ERROR("cannot access middleman: module not loaded");
  return *middleman_;
}
error empty_type_erased_tuple::load(size_t, deserializer&) {
    CAF_RAISE_ERROR("empty_type_erased_tuple::get_mutable");
}
void* empty_type_erased_tuple::get_mutable(size_t) {
    CAF_RAISE_ERROR("empty_type_erased_tuple::get_mutable");
}
error empty_type_erased_tuple::save(size_t, serializer&) const {
    CAF_RAISE_ERROR("empty_type_erased_tuple::copy");
}
type_erased_value_ptr empty_type_erased_tuple::copy(size_t) const {
    CAF_RAISE_ERROR("empty_type_erased_tuple::copy");
}
std::string empty_type_erased_tuple::stringify(size_t) const {
    CAF_RAISE_ERROR("empty_type_erased_tuple::stringify");
}
const void* empty_type_erased_tuple::get(size_t) const noexcept {
    CAF_RAISE_ERROR("empty_type_erased_tuple::get");
}