当前位置: 首页>>代码示例>>C++>>正文


C++ error_code::assign方法代码示例

本文整理汇总了C++中std::error_code::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ error_code::assign方法的具体用法?C++ error_code::assign怎么用?C++ error_code::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::error_code的用法示例。


在下文中一共展示了error_code::assign方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getaddrinfo

	addrinfo_ptr getaddrinfo(const char * host, const char * service, std::error_code & err)
	{
		addrinfo_type hints;

		std::memset(&hints, 0, sizeof(hints));
		hints.ai_family = AF_UNSPEC;
		hints.ai_protocol = IPPROTO_TCP;
		hints.ai_socktype = SOCK_STREAM;

		int res;
		addrinfo_type * ptr;
		do res = ::getaddrinfo(host, service, &hints, &ptr); while (res == EAI_AGAIN);
		if (res == 0)
		{
			err.clear();
			return addrinfo_ptr(ptr);
		}

		if (res == EAI_SYSTEM)
		{
			err.assign(errno, std::generic_category());
			return addrinfo_ptr(nullptr);
		}
		else
		{
			err.assign(res, gai_error_category());
			return addrinfo_ptr(nullptr);
		}
	}
开发者ID:dmlys,项目名称:extlib,代码行数:29,代码来源:bsdsock_streambuf.cpp

示例2: space

space_info space(const std::string& path, std::error_code& ec)
{
  using WINDOWS::ToW;

  ec.clear();
  space_info sp;
  auto pathW = ToW(path);

  ULARGE_INTEGER capacity;
  ULARGE_INTEGER available;
  ULARGE_INTEGER free;
  auto result = GetDiskFreeSpaceExW(pathW.c_str(), &available, &capacity, &free);

  if (result == FALSE)
  {
    ec.assign(GetLastError(), std::system_category());
    sp.available = static_cast<uintmax_t>(-1);
    sp.capacity = static_cast<uintmax_t>(-1);
    sp.free = static_cast<uintmax_t>(-1);
    return sp;
  }

  sp.available = static_cast<uintmax_t>(available.QuadPart);
  sp.capacity = static_cast<uintmax_t>(capacity.QuadPart);
  sp.free = static_cast<uintmax_t>(free.QuadPart);

  return sp;
}
开发者ID:Elzevir,项目名称:xbmc,代码行数:28,代码来源:Filesystem.cpp

示例3: copy_file

  bool copy_file(const path& from,
                 const path& to,
                 copy_options options,
                 std::error_code& ec) noexcept
  {
    auto t = status(to, ec);
    if (!is_regular_file(from) ||
        (t.type() != file_type::not_found &&
         (t.type() != file_type::regular || equivalent(from, to) ||
          (options &
           (copy_options::skip_existing | copy_options::overwrite_existing |
            copy_options::update_existing)) == copy_options::none))) {
      ec.assign(EEXIST, std::system_category());
    } else {
      if (t.type() == file_type::not_found ||
          (options & copy_options::overwrite_existing) != copy_options::none ||
          ((options & copy_options::update_existing) != copy_options::none &&
           last_write_time(from) > last_write_time(to))) {
        std::ifstream src(from, std::ios::binary);
        std::ofstream dst(to, std::ios::binary | std::ios::trunc);

        dst << src.rdbuf();
        if (errno != 0) {
          ec = {errno, std::system_category()};
        } else {
          ec.clear();
          return true;
        }
      }
    }
    return false;
  }
开发者ID:daniel-varela,项目名称:OTTO,代码行数:32,代码来源:filesystem.cpp

示例4: FormatError

	std::string FormatError(std::error_code err)
	{
#if BOOST_OS_WINDOWS
		if (err.category() == std::system_category())
			err.assign(err.value(), ext::system_utf8_category());
#endif

		return FormatErrorImpl(err);
	}
开发者ID:dmlys,项目名称:extlib,代码行数:9,代码来源:Errors.cpp

示例5: ByteBuffer

std::vector<char> File::ReadAllBytes(std::error_code& ec)
{
    std::unique_ptr<HANDLE, CloseHandleDeleter> handle(CreateFile(
        m_path,
        GENERIC_READ,
        FILE_SHARE_READ,
        NULL,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL));

    if (handle.get() == INVALID_HANDLE_VALUE)
    {
        ec.assign(GetLastError(), std::system_category());
        return ByteBuffer();
    }

    ByteBuffer result;
    DWORD read = 0;

    do
    {
        char tmp[1024];
        read = 0;

        if (!ReadFile(
            handle.get(),
            tmp,
            ARRAYSIZE(tmp),
            &read,
            NULL))
        {
            ec.assign(GetLastError(), std::system_category());
            return ByteBuffer();
        }

        result.insert(
            result.end(),
            tmp,
            tmp + read);
    } while (read > 0);

    return result;
}
开发者ID:DoumanAsh,项目名称:picotorrent,代码行数:44,代码来源:File.cpp

示例6: unpack

    static inline
    void
    unpack(const msgpack::object& source, std::error_code& target) {
        int category_id;
        int ec;

        type_traits<sequence_type>::unpack(source, category_id, ec);

        target.assign(ec, error::registrar::map(category_id));
    }
开发者ID:3Hren,项目名称:cocaine-core,代码行数:10,代码来源:error_code.hpp

示例7: read_dir

  void DIter::read_dir(const path& p,
                       directory_options options,
                       std::error_code& ec)
  {
    _entries = std::make_shared<std::vector<DEntr>>();

    bool skip_denied = (options & directory_options::skip_permission_denied) !=
                       directory_options::none;

    errno = 0;
    auto* dir = opendir(p.c_str());
    if (dir == nullptr) {
      ec.assign(errno, std::system_category());
      return;
    }

    std::string name;
    dirent* de;
    do {
      errno = 0;
      de = readdir(dir);
      if (errno == EACCES && skip_denied) {
        continue;
      }
      if (!de) continue;
      name = de->d_name;
      if (name == "." || name == "..") continue;
      _entries->emplace_back(p / de->d_name);
    } while (de != nullptr);

    closedir(dir);

    if (errno != 0) {
      ec.assign(errno, std::system_category());
    }

    if (_entries->size() == 0) {
      _ptr = nullptr;
    } else {
      _ptr = _entries->data();
    }
  }
开发者ID:daniel-varela,项目名称:OTTO,代码行数:42,代码来源:filesystem.cpp

示例8: close

 /// Manually close the file descriptor
 void close(std::error_code& ec) noexcept
 {
     ec.clear();
     errno = 0;
     if (::close(fd_) == 0) {
         fd_ = -1;
         delete_ = false;
     } else {
         ec.assign(errno, std::system_category());
     }
 }
开发者ID:tcbrindle,项目名称:modern-io,代码行数:12,代码来源:file_descriptor_handle.hpp

示例9: create_pool

//#############################################################################
void basic_thread_pool_impl::create_pool(
    uint32_t size, std::error_code& ec)
  {
  if (size == 0)
    {
    return;
    }

  std::lock_guard<std::mutex> pool_lock(pool_mutex_);
  if (pool_.size() > 0 || pool_size_ != 0)
    {
    ec.assign(EALREADY, std::system_category());
    return;
    }

  for (uint32_t i = 0; i < size; i++)
    {
    thread_handler_.create_thread(
      std::bind(
        &basic_thread_pool_impl::on_thread_created, shared_from_this(),
          std::placeholders::_1, std::placeholders::_2));
    }
  }
开发者ID:nickfajones,项目名称:libapoa,代码行数:24,代码来源:basic_thread_pool_impl.cpp


注:本文中的std::error_code::assign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。