本文整理汇总了C++中boost::system::error_code::value方法的典型用法代码示例。如果您正苦于以下问题:C++ error_code::value方法的具体用法?C++ error_code::value怎么用?C++ error_code::value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::system::error_code
的用法示例。
在下文中一共展示了error_code::value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readCompleted
void SerialDevice::readCompleted(const boost::system::error_code& error,
const size_t bytesTransferred)
{
if(!error)
{
pImpl->result=resultSuccess;
pImpl->bytesTransferred=bytesTransferred;
return;
}
//In case a asynchronous operation is cancelled due to a timeout,
//each OS seems to have its way to react.
#ifdef _WIN32
if(error.value()==995) return; //Windows spits out error 995
#elif defined(__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
pImpl->port.async_read_some(
asio::buffer(pImpl->readBuffer,pImpl->readBufferSize),
boost::bind(&SerialDevice::readCompleted,this,boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
return;
}
#else //Linux
if(error.value()==125) return; //Linux outputs error 125
#endif
pImpl->result=resultError;
}
示例2: readMsg
void RemoteClient::readMsg(const boost::system::error_code& err) {
if(m_marked_for_delete) {
return;
} else if(err) {
switch(err.value()) {
case ENOENT:
std::cerr << "QntServer: client socket closed.\n";
break;
default:
std::cerr << "QntServer: got error reading from socket <" << strerror(err.value()) << ">\n";
}
m_server->removeClient(this);
m_marked_for_delete = true;
m_service.post(boost::bind(&RemoteClient::deleteSelf, this));
return;
}
ServerMsg *msg = ServerMsg::create(m_next_msg_type, this);
if(msg) {
msg->read(m_wrapper);
m_server->pushMessage(msg);
boost::asio::async_read(m_socket, boost::asio::buffer((char*)&m_next_msg_type, 4),
boost::bind(&RemoteClient::readMsg, this, boost::asio::placeholders::error));
} else {
std::cerr << "QntServer: received unknown message of type <" << m_next_msg_type << ">\n";
std::cerr << "QntServer: closing stream due to unknown error.\n";
m_server->removeClient(this);
m_marked_for_delete = true;
m_service.post(boost::bind(&RemoteClient::deleteSelf, this));
}
}
示例3: handle_timer_event
/*!
*
* @param error
*/
void Timer::handle_timer_event(const boost::system::error_code& error,
int TimerId) {
if (verbose) {
std::cout << "handle_timer_event, Timerid = " << TimerId << std::endl;
}
switch (error.value()) {
case boost::system::errc::success: {
if (interval_) {
timer_func_handler_pntr(TimerId);
_TimerList.pop_front();
initiate_timer();
} else {
}
}
break;
case boost::system::errc::operation_canceled: {
std::cout << "Timer " << TimerId << " cancelled" << std::endl;
}
break;
default: {
std::cout << "Assert unexpected case Timer = " << TimerId << " Error = "
<< error.value() << std::endl;
}
break;
}
}
示例4: HandleTcpSend
// void TCPSocket::HandleTcpSend(const boost::asio::error& err, size_t bytes_transferred, MyBuffer b)
void TCPClientSocket::HandleTcpSend(const boost::system::error_code& err, size_t bytes_transferred)
{
if ( m_SendQueue.empty() )
{
//TRACE("HandleTcpSend %lu %d\n", GetCurrentThreadId(), m_Socket->GetSocket().native());
APP_ERROR("TCPClientSocket::HandleTcpSend invalid empty buffer " << make_tuple( err.value(), bytes_transferred, m_SendQueue.size() ));
assert(false == m_Socket->GetSocket().is_open());
return;
}
m_SendQueue.pop_front();
if ( err )
{
// ·¢ËÍʧ°Ü
APP_ERROR("TCPClientSocket::HandleTcpSend error " << make_tuple( err.value(), bytes_transferred, m_SendQueue.size() ));
this->GetListener()->OnSocketReceiveFailed(this, err.value());
}
else
{
if ( m_SendQueue.empty() )
{
return;
}
else
{
this->DoAsyncSend(m_SendQueue.front());
}
}
}
示例5: onReadSection
void DVBProvider::onReadSection(
boost::asio::posix::stream_descriptor *io,
ID pid,
util::Buffer *buf,
const boost::system::error_code& error,
size_t transferred )
{
bool tryRead=true;
if (error) {
if (error.value() == boost::system::errc::timed_out) {
// Timeout
timeout( pid );
}
else if (error.value() != boost::system::errc::value_too_large) {
printf( "[DVBProvider] Read section error!!!: err(%s,%d), pid=%04x, transferred=%d, capacity=%d!\n",
error.message().c_str(), error.value(), pid, transferred, buf->capacity() );
tryRead=false;
}
}
if (transferred) {
buf->resize( transferred );
enqueue( pid, buf );
buf = NULL;
}
if (tryRead) {
readSection( io, pid, buf );
}
else {
freeNetworkBuffer( buf );
}
}
示例6: readCompleted
void TimeoutSerial::readCompleted(const boost::system::error_code& error,
const size_t bytesTransferred)
{
if(!error)
{
result=resultSuccess;
this->bytesTransferred=bytesTransferred;
return;
}
//In case a asynchronous operation is cancelled due to a timeout,
//each OS seems to have its way to react.
#ifdef _WIN32
if(error.value()==995) return; //Windows spits out error 995
#elif defined(__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
performReadSetup(setupParameters);
return;
}
#else //Linux
if(error.value()==125) return; //Linux outputs error 125
#endif
result=resultError;
}
示例7: read_handle
void c_udp_wrapper_asio::read_handle(const boost::system::error_code& error, size_t bytes_transferred) {
// std::cout << "udp read handle" << std::endl;
// std::cout << "readed " << bytes_transferred << " bytes" << std::endl;
if (error && (error.value() != 10061)) // http://stackoverflow.com/a/16763404
std::cout << error.message() << " value " << error.value() << std::endl;
// assert(m_bytes_readed == 0);
m_bytes_readed = bytes_transferred;
m_socket.async_receive_from(boost::asio::buffer(m_buffer), m_sender_endpoint,
boost::bind(&c_udp_wrapper_asio::read_handle, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
示例8: report
inline void length_framed_connection::report(boost::system::error_code ec) {
switch (ec.value()) {
case io::error::eof:
report(std::errc::not_connected);
break;
default:
report(static_cast<std::errc>(ec.value()));
break;
}
}
示例9: handle_send
/// dummy function, called after send
void CBoostTapNetAdapt::handle_send (boost::shared_ptr<CNetworkFrame> frame, const boost::system::error_code& error, std::size_t bytes_transferred)
{
if (error.value() != 0) {
DBG_ERROR(FMT("Error sending data (%1%): %2%") % error.value() % error.message());
} else if (bytes_transferred != frame->size) {
DBG_ERROR(FMT("bytes transferred (%1%) != buffer size (%2%)!") % bytes_transferred % frame->size);
}
}
示例10: OnSendComplete
void OnSendComplete(const boost::system::error_code &err, CMsgBuffer::Ptr msg)
{
std::cout << "ErrorCode" << err.value() << std::endl;
if (err.value() == boost::asio::error::not_connected)
{
cli.Reset();
return;
}
std::cout << "OnSendComplete" << std::endl;
std::cout << "OnSendComplete times \"" << times++ << "\"" <<std::endl;
}
示例11: HandleReadSome
void TtyStream::HandleReadSome(int reference, const boost::system::error_code& error, size_t bytes_transferred)
{
lua_State* L = LuaNode::GetLuaVM();
lua_rawgeti(L, LUA_REGISTRYINDEX, reference);
luaL_unref(L, LUA_REGISTRYINDEX, reference);
m_pending_reads--;
if(!error) {
LogDebug("TtyStream::HandleReadSome (%p) (id:%u) - Bytes Transferred (%lu)\n", this, m_fd, (unsigned long)bytes_transferred);
lua_getfield(L, 1, "read_callback");
if(lua_type(L, 2) == LUA_TFUNCTION) {
lua_pushvalue(L, 1);
const char* data = m_inputArray.c_array();
lua_pushlstring(L, data, bytes_transferred);
LuaNode::GetLuaVM().call(2, LUA_MULTRET);
}
else {
// do nothing?
if(lua_type(L, 1) == LUA_TUSERDATA) {
userdataType* ud = static_cast<userdataType*>(lua_touserdata(L, 1));
LogWarning("TtyStream::HandleReadSome (%p) (id:%u) - No read_callback set on %s (address: %p, possible obj: %p)", this, m_fd, luaL_typename(L, 1), ud, ud->pT);
}
else {
LogWarning("TtyStream::HandleReadSome (%p) (id:%u) - No read_callback set on %s", this, m_fd, luaL_typename(L, 1));
}
}
}
else {
lua_getfield(L, 1, "read_callback");
if(lua_type(L, 2) == LUA_TFUNCTION) {
lua_pushvalue(L, 1);
LuaNode::BoostErrorCodeToLua(L, error); // -> nil, error code, error message
if(error.value() != boost::asio::error::eof && error.value() != boost::asio::error::operation_aborted) {
LogError("TtyStream::HandleReadSome with error (%p) (id:%u) - %s", this, m_fd, error.message().c_str());
}
LuaNode::GetLuaVM().call(4, LUA_MULTRET);
}
else {
LogError("TtyStream::HandleReadSome with error (%p) (id:%u) - %s", this, m_fd, error.message().c_str());
if(lua_type(L, 1) == LUA_TUSERDATA) {
userdataType* ud = static_cast<userdataType*>(lua_touserdata(L, 1));
LogWarning("TtyStream::HandleReadSome (%p) (id:%u) - No read_callback set on %s (address: %p, possible obj: %p)", this, m_fd, luaL_typename(L, 1), ud, ud->pT);
}
else {
LogWarning("TtyStream::HandleReadSome (%p) (id:%u) - No read_callback set on %s", this, m_fd, luaL_typename(L, 1));
}
}
}
lua_settop(L, 0);
}
示例12: recvSerialPortErrorCB
void TransPanel::recvSerialPortErrorCB(boost::system::error_code ec)
{
if(ec.value() != 995)
{
LOG( "%d - %s" , ec.value() , ec.message().c_str());
QString com_error;
com_error.sprintf("串口读取错误:%s" ,ec.message().c_str() );
SERROR(com_error);
}
}
示例13: CheckErrorCode
bool CheckErrorCode(boost::system::error_code& err)
{
// connection reset can happen when host did not start up
// before the client wants to connect
if (!err || err.value() == connection_reset ||
err.value() == resource_unavailable_try_again) { // this should only ever happen with async sockets, but testing indicates it happens anyway...
return false;
} else {
LOG_L(L_WARNING, "Network error %i: %s", err.value(),
err.message().c_str());
return true;
}
}
示例14: data_recv_handler
void basic_socket_impl::data_recv_handler(const boost::system::error_code& ec, size_t bytes_transferred, bool ischeck)
{
if (!isworking()) return;
if (ec.value() == 0) {
recv_helper_.reading_buffer_.use_buffer(bytes_transferred);
int ret = on_data_recv(bytes_transferred);
if (ret == 0) {
if (recv_helper_.reading_buffer_.buffer_left() < 128) {
recv_helper_.reading_buffer_.remove_used();
}
//如果不是超时回调,则重置接收状态
if (!ischeck) {
recv_helper_.is_recving_ = false;
}
//如果缓冲有空闲,并且没有在接收状态
if (recv_helper_.reading_buffer_.buffer_left() > 0 && !recv_helper_.is_recving_) {
recv_helper_.is_recving_ = true;
s.async_receive(
boost::asio::buffer(recv_helper_.reading_buffer_.buffer(), recv_helper_.reading_buffer_.buffer_left()),
boost::bind(&basic_socket_impl::data_recv_handler,
this->shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred,
false));
}
else if (recv_helper_.reading_buffer_.buffer_left() == 0) {
if (option("close_on_rdbuffer_full") == "1") {
last_socket_error_ = 10055;
close(true);
}
else {
recv_helper_.is_recving_ = false;
//缓冲区满了,10ms后再读数据,让目前的数据有时间处理
check_data_recv_.expires_from_now(boost::posix_time::millisec(1));
check_data_recv_.async_wait(
boost::bind(&basic_socket_impl::on_recv_check,
this->shared_from_this(),
boost::asio::placeholders::error));
}
}
}
}
else {
if (work_state != work_state_closed) {
last_socket_error_ = ec.value();
close(true);
}
}
}
示例15: OnWrite
void CNetwork::OnWrite(const boost::system::error_code &error_code)
{
boost::lock_guard<boost::mutex> lock_guard(m_CmdWriteBufferQueueMutex);
#ifdef _DEBUG
logprintf("<<<< %s", m_CmdWriteBufferQueue.front().c_str());
#endif
m_CmdWriteBufferQueue.pop();
if (error_code.value() != 0)
{
CCallbackHandler::Get()->ForwardError(
EErrorType::CONNECTION_ERROR, error_code.value(),
fmt::format("error while writing: {}", error_code.message()));
}
}