本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
示例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();
}
}
示例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());
}
}
示例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));
}
}