本文整理汇总了C++中std::error_code::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ error_code::clear方法的具体用法?C++ error_code::clear怎么用?C++ error_code::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::error_code
的用法示例。
在下文中一共展示了error_code::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wait_until
inline bool wait_until(
const child_handle &p,
int & exit_code,
const std::chrono::time_point<Clock, Duration>& time_out,
std::error_code & ec) noexcept
{
pid_t ret;
int status;
bool timed_out;
do
{
ret = ::waitpid(p.pid, &status, WNOHANG);
if (ret == 0)
{
timed_out = Clock::now() >= time_out;
if (timed_out)
return false;
}
}
while ((ret == 0) ||
(((ret == -1) && errno == EINTR) ||
((ret != -1) && !WIFEXITED(status) && !WIFSIGNALED(status))));
if (ret == -1)
ec = boost::process::detail::get_last_error();
else
{
ec.clear();
exit_code = status;
}
return true;
}
示例2: 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);
}
}
示例3: makeNotCurrent
bool GlContext::makeNotCurrent(std::error_code& ec)
{
ec.clear();
std::mutex* mutex;
auto threadid = std::this_thread::get_id();
auto& map = contextCurrentMap(mutex);
decltype(map.begin()) thisThreadIt {};
//check if it is already not current
{
std::lock_guard<std::mutex> lock(*mutex);
thisThreadIt = map.find(threadid);
if(thisThreadIt == map.end()) thisThreadIt = map.insert({threadid, {}}).first;
if(thisThreadIt->second.first != this)
{
ec = Errc::contextAlreadyNotCurrent;
return true;
}
}
if(!makeNotCurrentImpl(ec)) return false;
std::lock_guard<std::mutex> lock(*mutex);
thisThreadIt->second = {nullptr, nullptr};
return true;
}
示例4: 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;
}
示例5: wait_until
inline bool wait_until(
child_handle &p,
int & exit_code,
const std::chrono::time_point<Clock, Duration>& timeout_time,
std::error_code &ec) noexcept
{
std::chrono::milliseconds ms =
std::chrono::duration_cast<std::chrono::milliseconds>(
timeout_time - std::chrono::system_clock::now());
::boost::detail::winapi::DWORD_ _exit_code = 1;
if (::boost::detail::winapi::WaitForSingleObject(p.process_handle(),
static_cast<::boost::detail::winapi::DWORD_>(ms.count()))
== ::boost::detail::winapi::wait_failed)
ec = std::error_code(
::boost::detail::winapi::GetLastError(),
std::system_category());
else if (!::boost::detail::winapi::GetExitCodeProcess(p.process_handle(), &_exit_code))
ec = std::error_code(
::boost::detail::winapi::GetLastError(),
std::system_category());
else
ec.clear();
exit_code = static_cast<int>(exit_code);
::boost::detail::winapi::CloseHandle(p.proc_info.hProcess);
p.proc_info.hProcess = ::boost::detail::winapi::INVALID_HANDLE_VALUE_;
return true;
;
}
示例6: swapInterval
bool GlxContext::swapInterval(int interval, std::error_code& ec) const
{
//TODO: check for interval < 0 and tear extensions not supported.
ec.clear();
if(!GLAD_GLX_EXT_swap_control || !glXSwapIntervalEXT)
{
ec = {GlContextErrc::extensionNotSupported};
return false;
}
const GlSurface* currentSurface;
GlContext::current(¤tSurface);
auto currentGlxSurface = dynamic_cast<const GlxSurface*>(currentSurface);
if(!currentGlxSurface)
{
// ec = {GlContextErrorCode::surfaceNotCurrent}; //TODO: add error for this case
return false;
}
::glXSwapIntervalEXT(xDisplay(), currentGlxSurface->xDrawable(), interval);
//TODO: handle possible error into ec
return true;
}
示例7: terminate
inline void terminate(const group_handle &p, std::error_code &ec) noexcept
{
if (!::boost::winapi::TerminateJobObject(p.handle(), EXIT_FAILURE))
ec = boost::process::detail::get_last_error();
else
ec.clear();
}
示例8: link_status
file_status link_status(path p, struct stat& st, std::error_code& ec)
{
if (::stat(p.c_str(), &st) != 0) {
if (errno == ENOENT) {
ec.clear();
return file_status{file_type::not_found, perms::none};
} else {
ec = {errno, std::system_category()};
return {};
}
}
ec.clear();
file_type type = to_file_type(st, ec);
perms prms = static_cast<perms>(st.st_mode) & perms::mask;
return file_status{type, prms};
}
示例9: 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;
}
示例10: wait_for
inline bool wait_for(
const group_handle &p,
const std::chrono::duration<Rep, Period>& rel_time,
std::error_code & ec) noexcept
{
pid_t ret;
int status;
auto start = std::chrono::system_clock::now();
auto time_out = start + rel_time;
bool time_out_occured = false;
do
{
ret = ::waitpid(-p.grp, &status, WUNTRACED | WNOHANG);
if (std::chrono::system_clock::now() >= time_out)
{
time_out_occured = true;
break;
}
}
while (((ret == -1) && errno == EINTR) ||
((ret != -1) && !WIFEXITED(status)));
if (ret == -1)
ec = boost::process::detail::get_last_error();
else
ec.clear();
return !time_out_occured;
}
示例11: resize_file
void resize_file(const path& p, uintmax_t size, std::error_code& ec) noexcept
{
if (::truncate(p.c_str(), static_cast<off_t>(size))) {
ec = {errno, std::system_category()};
} else {
ec.clear();
}
}
示例12: rename
void rename(const path& from, const path& to, std::error_code& ec) noexcept
{
if (::rename(from.c_str(), to.c_str())) {
ec = {errno, std::system_category()};
} else {
ec.clear();
}
}
示例13: current_path
void current_path(const path& p, std::error_code& ec) noexcept
{
if (chdir(p.c_str()) == 0) {
ec = {errno, std::system_category()};
} else {
ec.clear();
}
}
示例14: hard_link_count
uintmax_t hard_link_count(struct stat st, std::error_code& ec)
{
if (ec.value() == 0) {
ec.clear();
} else {
return 0;
}
return st.st_nlink;
}
示例15: migrate
void
state_machine_t::shutdown(std::error_code ec) {
if (shutdowned.exchange(true)) {
return;
}
auto state = *this->state.synchronize();
COCAINE_LOG_DEBUG(log, "slave is shutting down from state %s: %s", state->name(), ec.message());
state->cancel();
if(state->terminating()) {
// We don't consider any reason for termination in "terminating" state as an error
ec.clear();
}
migrate(std::make_shared<stopped_t>(ec));
fetcher.apply([&](std::shared_ptr<fetcher_t>& fetcher) {
fetcher->close();
fetcher.reset();
});
if (ec && ec != error::overseer_shutdowning) {
dump();
}
data.channels.apply([&](channels_map_t& channels) {
const auto size = channels.size();
if (size > 0) {
COCAINE_LOG_WARNING(log, "slave is dropping %d sessions", size);
}
for (auto& channel : channels) {
loop.post([=]() {
channel.second->close_both();
});
}
channels.clear();
});
// Check if the slave has been terminated externally. If so, do not call the cleanup callback.
if (closed) {
return;
}
// NOTE: To prevent deadlock between session.channels and overseer.pool. Consider some
// other solution.
const auto cleanup_handler = cleanup;
loop.post([=]() {
try {
cleanup_handler(ec);
} catch (const std::exception& err) {
// Just eat an exception, we don't care why the cleanup handler failed to do its job.
COCAINE_LOG_WARNING(log, "unable to cleanup after slave's death: %s", err.what());
}
});
}