本文整理汇总了C++中system::error_code类的典型用法代码示例。如果您正苦于以下问题:C++ error_code类的具体用法?C++ error_code怎么用?C++ error_code使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了error_code类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: now
steady_clock::time_point steady_clock::now(system::error_code & ec)
{
timespec ts;
if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
{
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
errno,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::steady_clock" ));
}
else
{
ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
}
if (!BOOST_CHRONO_IS_THROWS(ec))
{
ec.clear();
}
return time_point(duration(
static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
}
示例2: now
void process_clock::now( process_times & times_, system::error_code & ec ) {
tms tm;
clock_t c = ::times( &tm );
if ( c == clock_t(-1) ) // error
{
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
errno,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::process_clock" ));
}
else
{
ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
times_.real = times_.system = times_.user = nanoseconds(-1);
}
}
else
{
times_.real = microseconds(c);
times_.system = microseconds(tm.tms_stime + tm.tms_cstime);
times_.user = microseconds(tm.tms_utime + tm.tms_cutime);
if ( chrono_detail::tick_factor() != -1 )
{
if (!BOOST_CHRONO_IS_THROWS(ec))
{
ec.clear();
}
times_.real *= chrono_detail::tick_factor();
times_.user *= chrono_detail::tick_factor();
times_.system *= chrono_detail::tick_factor();
}
else
{
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
errno,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::process_clock" ));
}
else
{
ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
times_.real = times_.user = times_.system = nanoseconds(-1);
}
}
}
}
示例3: now
process_cpu_clock::time_point process_cpu_clock::now(
system::error_code & ec )
{
tms tm;
clock_t c = ::times( &tm );
if ( c == clock_t(-1) ) // error
{
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
errno,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::process_clock" ));
}
else
{
ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
}
else
{
if ( chrono_detail::tick_factor() != -1 )
{
time_point::rep r(
c*chrono_detail::tick_factor(),
(tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
(tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
return time_point(duration(r));
}
else
{
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
errno,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::process_clock" ));
}
else
{
ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
}
}
}
示例4: now
process_cpu_clock::time_point process_cpu_clock::now(
system::error_code & ec )
{
// note that Windows uses 100 nanosecond ticks for FILETIME
boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
#ifdef UNDER_CE
// Windows CE does not support GetProcessTimes
assert( 0 && "GetProcessTimes not supported under Windows CE" );
return time_point();
#else
if ( boost::detail::win32::GetProcessTimes(
boost::detail::win32::GetCurrentProcess(), &creation, &exit,
&system_time, &user_time ) )
{
if (!BOOST_CHRONO_IS_THROWS(ec))
{
ec.clear();
}
time_point::rep r(
steady_clock::now().time_since_epoch().count(),
((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
| user_time.dwLowDateTime
) * 100,
((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
| system_time.dwLowDateTime
) * 100
);
return time_point(duration(r));
}
else
{
boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
cause,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::process_cpu_clock" ));
}
else
{
ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
}
#endif
}
示例5: now
process_cpu_clock::time_point process_cpu_clock::now(
system::error_code & ec )
{
tms tm;
clock_t c = ::times( &tm );
if ( c == clock_t(-1) ) // error
{
if (::boost::chrono::is_throws(ec))
{
boost::throw_exception(
system::system_error(
errno,
::boost::system::system_category(),
"chrono::process_clock" ));
}
else
{
ec.assign( errno, ::boost::system::system_category() );
return time_point();
}
}
else
{
if ( chrono_detail::tick_factor() != -1 )
{
time_point::rep r(
c*chrono_detail::tick_factor(),
(tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
(tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
return time_point(duration(r));
}
else
{
if (::boost::chrono::is_throws(ec))
{
boost::throw_exception(
system::system_error(
errno,
::boost::system::system_category(),
"chrono::process_clock" ));
}
else
{
ec.assign( errno, ::boost::system::system_category() );
return time_point();
}
}
}
}
示例6: throw_system_error
inline
void throw_system_error(system::error_code ec)
{
if (ec)
{
if (ec.category() == runtime_error_category())
{
throw runtime_system_error(ec, ec.message());
}
if (ec.category() == logic_error_category()) {
throw logic_system_error(ec, ec.message());
}
throw system::system_error(ec, ec.message());
}
}
示例7: would_block
bool basic_io_device::would_block(system::error_code const &e)
{
int code = e.value();
bool block = 0
#ifdef EAGAIN
|| code==EAGAIN
#endif
#ifdef EINPROGRESS
|| code == EINPROGRESS
#endif
#ifdef EWOULDBLOCK
|| code == EWOULDBLOCK
#endif
#ifdef WSAEAGAIN
|| code==WSAEAGAIN
#endif
#ifdef WSAEINPROGRESS
|| code == WSAEINPROGRESS
#endif
#ifdef WSAEWOULDBLOCK
|| code == WSAEWOULDBLOCK
#endif
;
return block;
}
示例8: now
process_cpu_clock::time_point process_cpu_clock::now(
system::error_code & ec )
{
// note that Windows uses 100 nanosecond ticks for FILETIME
autoboost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
if ( autoboost::detail::winapi::GetProcessTimes(
autoboost::detail::winapi::GetCurrentProcess(), &creation, &exit,
&system_time, &user_time ) )
{
if (!AUTOBOOST_CHRONO_IS_THROWS(ec))
{
ec.clear();
}
time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
,
((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
| user_time.dwLowDateTime
) * 100,
((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
| system_time.dwLowDateTime
) * 100
);
return time_point(duration(r));
}
else
{
autoboost::detail::winapi::DWORD_ cause = autoboost::detail::winapi::GetLastError();
if (AUTOBOOST_CHRONO_IS_THROWS(ec))
{
autoboost::throw_exception(
system::system_error(
cause,
AUTOBOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::process_cpu_clock" ));
}
else
{
ec.assign( cause, AUTOBOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
}
}
示例9: on_empty_buffer
void CProtocol::on_empty_buffer(const system::error_code& error, std::size_t bytes) {
empty_buffer_[bytes] = 0;
std::string reply(empty_buffer_);
if (bytes > 0)
std::cout << "on_empty_buffer: " << bytes << " " << reply << std::endl;
buffer_empty_ = true;
if(error != 0)
std::cout << "on_empty_buffer error: " << error << " message: "<< error.message() << std::endl;
}
示例10: OnSend
void CTcpSocket::OnSend( const system::error_code &ec, size_t nByteTransferred )
{
if (ec)
{
LOGError(ec.message().c_str());
DoClose();
return ;
}
m_wSendLength -= nByteTransferred;
if (m_wSendLength > 0)
{
LOGError("理论来讲,这里是进不来的!");
// 理论来讲,这里是进不来的。
memcpy(m_szSendBuffer, m_szSendBuffer + nByteTransferred, m_wSendLength);
// 发送数据
m_pSock->async_write_some(buffer(m_szSendBuffer, m_wSendLength),
bind(&CTcpSocket::OnSend, this, placeholders::error, placeholders::bytes_transferred));
}
else if (0 == m_wSendLength)
{
// 拷贝数据
std::list<MsgData>::iterator it = m_listMsgData.begin();
for (; it!=m_listMsgData.end(); )
{
MsgData &msgData = (*it);
if (MAX_SEND_BUFFER_LENGTH - m_wSendLength >= msgData.wLength)
{
USHORT *pPacketLength = (USHORT *)m_szSendBuffer;
*pPacketLength = msgData.wLength;
m_wSendLength += sizeof(USHORT);
memcpy(m_szSendBuffer + m_wSendLength, msgData.szData, msgData.wLength);
m_wSendLength += msgData.wLength;
it = m_listMsgData.erase(it);
}
else
{
break;
}
}
// 发送数据
m_pSock->async_write_some(buffer(m_szSendBuffer, m_wSendLength),
bind(&CTcpSocket::OnSend, this, placeholders::error, placeholders::bytes_transferred));
}
else
{
LOGError("异常错误!");
}
}
示例11: handle_read
void Peer::handle_read(const system::error_code& e, std::size_t bytes_transferred) {
log_trace("args error: %s, bytes: %d", e.message(), bytes_transferred);
if (!e) {
_activity = true;
string rx;
for(int i = 0; i < bytes_transferred; i++)
rx.push_back(_buffer[i]);
vRecv += rx;
// Now call the parser:
bool fRet = false;
loop {
boost::tuple<boost::tribool, CDataStream::iterator> parser_result = _msgParser.parse(_chain, _message, vRecv.begin(), vRecv.end());
tribool result = get<0>(parser_result);
vRecv.erase(vRecv.begin(), get<1>(parser_result));
if (result) {
if (_messageHandler.handleMessage(this, _message) ) fRet = true;
}
else if (!result) {
log_warn("Peer %s sending bogus - disconnecting", addr.toString());
_peerManager.post_stop(shared_from_this());
}// continue; // basically, if we get a false result, we should consider to disconnect from the Peer!
else
break;
}
// now if fRet is true, something were processed by the filters - we want to send to the peers / we check for which vSends cointains stuff and the we run
if (fRet && nVersion > 0) {
// first reply
reply();
// then trickle
Peers peers = _peerManager.getAllPeers();
size_t rand = GetRand(peers.size());
for (Peers::iterator peer = peers.begin(); peer != peers.end(); ++peer)
if(rand-- == 0) {
(*peer)->trickle();
break;
}
// then broadcast
for (Peers::iterator peer = peers.begin(); peer != peers.end(); ++peer)
(*peer)->broadcast();
// now write to the peers with non-empty vSend buffers
for (Peers::iterator peer = peers.begin(); peer != peers.end(); ++peer) {
(*peer)->flush();
}
}
// then wait for more data
_socket.async_read_some(buffer(_buffer), boost::bind(&Peer::handle_read, shared_from_this(), asio::placeholders::error, asio::placeholders::bytes_transferred));
// async_read(_socket, _recv, boost::bind(&Peer::handle_read, shared_from_this(), asio::placeholders::error, asio::placeholders::bytes_transferred));
}
示例12: handle_write
void Proxy::handle_write(const system::error_code& e, size_t bytes_transferred) {
if (!e) {
// ignore
}
else if (e != error::operation_aborted) {
log_error("Proxy write error %s, disconnecting...", e.message());
// forward the error to the connection handler callback
_connection_handler(e);
}
}
示例13: report
void run_timer::report( system::error_code & ec )
{
m_reported = true;
if ( m_format.empty() ) m_format = chrono_detail::default_format();
process_times times;
elapsed( times, ec );
if (ec) return;
if ( BOOST_CHRONO_IS_THROWS(ec) )
{
chrono_detail::show_time( times, m_format.c_str(), m_places, m_os );
}
else // non-throwing
{
try
{
chrono_detail::show_time( times, m_format.c_str(), m_places, m_os );
if (!BOOST_CHRONO_IS_THROWS(ec))
{
ec.clear();
}
}
catch (...) // eat any exceptions
{
BOOST_ASSERT( 0 && "error reporting not fully implemented yet" );
if (BOOST_CHRONO_IS_THROWS(ec))
{
boost::throw_exception(
system::system_error(
errno,
BOOST_CHRONO_SYSTEM_CATEGORY,
"chrono::run_timer" ));
}
else
{
ec.assign(system::errc::success, BOOST_CHRONO_SYSTEM_CATEGORY);
}
}
}
}
示例14: callback
void callback(system::error_code ec) {
std::cout << __PRETTY_FUNCTION__ << "\n";
if (ec != asio::error::operation_aborted) {
std::cout << " - continuing wait - keeps the object alive (as it should)\n";
tim.expires_from_now(posix_time::seconds(2));
tim.async_wait(bind(&MySessionThing::callback, shared_from_this(), asio::placeholders::error));
}
std::cout << " - " << ec.message() << ": exiting handler - also implicitly releases the lock on MySessionThing\n";
// only if the new async_wait has *not* been posted, this will cause the destructor to run
}
示例15: Handle_Write_HTTP_Request
void Sony_Remote_Camera_Implementation::Handle_Write_HTTP_Request(bool mode_liveview, bool event_thread, const system::error_code& err) {
asio::ip::tcp::socket& s = mode_liveview ? socket_liveview : (event_thread ? socket_event_listener : socket_options);
asio::streambuf& buf = mode_liveview ? tcp_response_liveview : (event_thread ? tcp_response_events : tcp_response_options);
if (!err) {
boost::asio::async_read_until(s, buf, "\r\n",
boost::bind(&Sony_Remote_Camera_Implementation::Handle_Read_Status_Line, this, mode_liveview, event_thread,
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
} else {
throw(ios_base::failure(err.message()));
}
}
开发者ID:ernest-galbrun,项目名称:sony_remote_camera_cpp_drivers,代码行数:11,代码来源:sony_remote_camera_implementation.cpp