本文整理汇总了C++中std::error_code::value方法的典型用法代码示例。如果您正苦于以下问题:C++ error_code::value方法的具体用法?C++ error_code::value怎么用?C++ error_code::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::error_code
的用法示例。
在下文中一共展示了error_code::value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: finalize
void
finalize(const std::error_code& ec) {
// Prepare the internal socket object for consequential operations by moving its contents to a
// heap-allocated object, which in turn might be attached to an engine.
auto ptr = std::make_unique<protocol_type::socket>(std::move(socket));
switch(ec.value()) {
case 0:
COCAINE_LOG_DEBUG(parent->m_log, "accepted connection on fd {}", ptr->native_handle());
try {
auto base = parent->fact();
auto session = parent->m_context.engine().attach(std::move(ptr), base);
parent->bind(base, std::move(session));
} catch(const std::system_error& e) {
COCAINE_LOG_ERROR(parent->m_log, "unable to attach connection to engine: {}",
error::to_string(e));
ptr = nullptr;
}
break;
case asio::error::operation_aborted:
return;
default:
COCAINE_LOG_ERROR(parent->m_log, "unable to accept connection: [{}] {}", ec.value(),
ec.message());
break;
}
// TODO: Find out if it's always a good idea to continue accepting connections no matter what.
// For example, destroying a socket from outside this thread will trigger weird stuff on Linux.
operator()();
}
示例2: handleMergeWriterError
static void handleMergeWriterError(std::error_code &Error,
StringRef WhenceFile = "",
StringRef WhenceFunction = "",
bool ShowHint = true) {
if (!WhenceFile.empty())
errs() << WhenceFile << ": ";
if (!WhenceFunction.empty())
errs() << WhenceFunction << ": ";
errs() << Error.message() << "\n";
if (ShowHint) {
StringRef Hint = "";
if (Error.category() == instrprof_category()) {
instrprof_error instrError = static_cast<instrprof_error>(Error.value());
switch (instrError) {
case instrprof_error::hash_mismatch:
case instrprof_error::count_mismatch:
case instrprof_error::value_site_count_mismatch:
Hint = "Make sure that all profile data to be merged is generated "
"from the same binary.";
break;
default:
break;
}
}
if (!Hint.empty())
errs() << Hint << "\n";
}
}
示例3: is_session_level_protocol_error
/// The error is a connection-level protocol error.
bool is_session_level_protocol_error() const
{
if (error_code.category() != realm::sync::protocol_error_category()) {
return false;
}
return realm::sync::is_session_level_error(static_cast<ProtocolError>(error_code.value()));
}
示例4: ErrorEquals
static ::testing::AssertionResult ErrorEquals(std::error_code Expected,
std::error_code Found) {
if (Expected == Found)
return ::testing::AssertionSuccess();
return ::testing::AssertionFailure() << "error " << Found.value()
<< ": " << Found.message();
}
示例5: readEnd
void AsyncSerial::readEnd(const std::error_code& error,
size_t bytes_transferred)
{
if(error)
{
#ifdef __APPLE__
if(error.value()==45)
{
//Bug on OS X, it might be necessary to repeat the setup
//http://osdir.com/ml/lib.boost.asio.user/2008-08/msg00004.html
doRead();
return;
}
#endif //__APPLE__
//error can be true even because the serial port was closed.
//In this case it is not a real error, so ignore
if(isOpen())
{
doClose();
setErrorStatus(true);
}
} else {
if(pimpl->callback) pimpl->callback(pimpl->readBuffer,
bytes_transferred);
doRead();
}
}
示例6: pack
static inline
void
pack(msgpack::packer<Stream>& target, const std::error_code& source) {
int category_id = error::registrar::map(source.category());
int ec = source.value();
type_traits<sequence_type>::pack(target, category_id, ec);
}
示例7: catch
void
multicast_t::on_receive(const std::error_code& ec, size_t bytes_received,
const std::shared_ptr<announce_t>& ptr)
{
if(ec) {
if(ec != asio::error::operation_aborted) {
COCAINE_LOG_ERROR(m_log, "unexpected error in multicast_t::on_receive(): [%d] %s",
ec.value(), ec.message()
);
}
return;
}
msgpack::unpacked unpacked;
try {
msgpack::unpack(&unpacked, ptr->buffer.data(), bytes_received);
} catch(const msgpack::unpack_error& e) {
COCAINE_LOG_ERROR(m_log, "unable to unpack announce: %s", e.what());
return;
}
std::string uuid;
std::vector<tcp::endpoint> endpoints;
try {
type_traits<announce_t::tuple_type>::unpack(unpacked.get(), std::tie(uuid, endpoints));
} catch(const msgpack::type_error& e) {
COCAINE_LOG_ERROR(m_log, "unable to decode announce: %s", e.what());
return;
}
if(uuid != m_locator.uuid()) {
COCAINE_LOG_DEBUG(m_log, "received %d endpoint(s) from %s", endpoints.size(), ptr->endpoint)(
"uuid", uuid
);
auto& expiration = m_expirations[uuid];
if(!expiration) {
expiration = std::make_unique<deadline_timer>(m_locator.asio());
// Link a new node only when seen for the first time.
m_locator.link_node(uuid, endpoints);
}
expiration->expires_from_now(m_cfg.interval * 3);
expiration->async_wait(std::bind(&multicast_t::on_expired, this, ph::_1, uuid));
}
const auto announce = std::make_shared<announce_t>();
m_socket.async_receive_from(buffer(announce->buffer.data(), announce->buffer.size()),
announce->endpoint,
std::bind(&multicast_t::on_receive, this, ph::_1, ph::_2, announce)
);
}
示例8: 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;
}
示例9: file_size
uintmax_t file_size(struct stat st, std::error_code& ec)
{
if (ec.value() == 0) {
ec.clear();
} else {
return 0;
}
return st.st_size;
}
示例10: 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);
}
示例11: _networkErrorCallback
void NetworkInterfaceASIO::_networkErrorCallback(AsyncOp* op, const std::error_code& ec) {
if (ec.category() == mongoErrorCategory()) {
// If we get a Mongo error code, we can preserve it.
_completeOperation(op, Status(ErrorCodes::fromInt(ec.value()), ec.message()));
} else {
// If we get an asio or system error, we just convert it to a network error.
_completeOperation(op, Status(ErrorCodes::HostUnreachable, ec.message()));
}
}
示例12:
static mb::optional<int> extract_errno(std::error_code ec)
{
if (ec.category() == std::generic_category()
|| ec.category() == std::system_category()) {
return ec.value();
}
return {};
}
示例13: to_file_type
file_type to_file_type(struct stat st, std::error_code& ec)
{
if (ec != std::error_code()) {
switch (ec.value()) {
case ENOENT: return file_type::not_found;
default: return file_type::none;
}
}
return to_file_type(st.st_mode);
}
示例14: updateTransactionSendingState
void WalletUserTransactionsCache::updateTransactionSendingState(TransactionId transactionId, std::error_code ec) {
auto& txInfo = m_transactions.at(transactionId);
if (ec) {
txInfo.state = ec.value() == error::TX_CANCELLED ? WalletLegacyTransactionState::Cancelled : WalletLegacyTransactionState::Failed;
m_unconfirmedTransactions.erase(txInfo.hash);
} else {
txInfo.sentTime = time(nullptr); // update sending time
txInfo.state = WalletLegacyTransactionState::Active;
}
}
示例15: exitWithErrorCode
static void exitWithErrorCode(const std::error_code &Error, StringRef Whence = "") {
if (Error.category() == instrprof_category()) {
instrprof_error instrError = static_cast<instrprof_error>(Error.value());
if (instrError == instrprof_error::unrecognized_format) {
// Hint for common error of forgetting -sample for sample profiles.
exitWithError(Error.message(), Whence,
"Perhaps you forgot to use the -sample option?");
}
}
exitWithError(Error.message(), Whence);
}