本文整理汇总了C++中boost::system::error_code::message方法的典型用法代码示例。如果您正苦于以下问题:C++ error_code::message方法的具体用法?C++ error_code::message怎么用?C++ error_code::message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::system::error_code
的用法示例。
在下文中一共展示了error_code::message方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
////////////////////////////////////////////////////////////////////////////////
/// This is the main communication engine.
///
/// @IO
/// At every timestep, a message is sent to the FPGA via TCP socket
/// connection, then a message is retrieved from FPGA via the same
/// connection. On the FPGA side, it's the reverse order -- receive and
/// then send. Both DGI and FPGA receive functions will block until a
/// message arrives, creating a synchronous, lock-step communication between
/// DGI and the FPGA. We keep the timestep (a static member of CRtdsAdapter)
/// very small so that how frequently send and receive get executed is
/// dependent on how fast the FPGA runs.
///
/// @Error_Handling
/// Throws std::runtime_error if reading from or writing to socket fails.
///
/// @pre Connection with FPGA is established.
///
/// @post All values in the receive buffer are sent to the FPGA. All values in
/// the send buffer are updated with data from the FPGA.
///
/// @limitations This function uses synchronous communication.
////////////////////////////////////////////////////////////////////////////////
void CRtdsAdapter::Run(const boost::system::error_code & e)
{
Logger.Trace << __PRETTY_FUNCTION__ << std::endl;
if( e )
{
if (e == boost::asio::error::operation_aborted)
{
return;
}
else
{
Logger.Fatal << "Run called with error: " << e.message()
<< std::endl;
throw boost::system::system_error(e);
}
}
// Always send data to FPGA first
if( !m_txBuffer.empty() )
{
boost::unique_lock<boost::shared_mutex> writeLock(m_txMutex);
Logger.Debug << "Obtained the txBuffer mutex." << std::endl;
EndianSwapIfNeeded(m_txBuffer);
try
{
Logger.Debug << "Blocking for a socket write call." << std::endl;
TimedWrite(m_socket, boost::asio::buffer(m_txBuffer,
m_txBuffer.size() * sizeof(SignalValue)),
CTimings::Get("DEV_SOCKET_TIMEOUT"));
}
catch(boost::system::system_error & e)
{
Logger.Fatal << "Send to FPGA failed: " << e.what();
throw;
}
EndianSwapIfNeeded(m_txBuffer);
Logger.Debug << "Releasing the txBuffer mutex." << std::endl;
}
// Receive data from FPGA next
if( !m_rxBuffer.empty() )
{
// must be a unique_lock for endian swaps
boost::unique_lock<boost::shared_mutex> writeLock(m_rxMutex);
Logger.Debug << "Obtained the rxBuffer mutex." << std::endl;
try
{
Logger.Debug << "Blocking for a socket read call." << std::endl;
TimedRead(m_socket, boost::asio::buffer(m_rxBuffer,
m_rxBuffer.size() * sizeof(SignalValue)),
CTimings::Get("DEV_SOCKET_TIMEOUT"));
}
catch (boost::system::system_error & e)
{
Logger.Fatal << "Receive from FPGA failed: " << e.what();
throw;
}
EndianSwapIfNeeded(m_rxBuffer);
if( m_buffer_initialized == false )
{
m_buffer_initialized = true;
for( unsigned int i = 0; i < m_rxBuffer.size(); i++ )
{
if( m_rxBuffer[i] == NULL_COMMAND )
{
m_buffer_initialized = false;
}
}
if( m_buffer_initialized )
{
//.........这里部分代码省略.........
示例2: error
//executed from io-service thread
void Cserial::error(int id, const boost::system::error_code& error)
{
//dummy
ERROR("serial " << id << " had an error:" << error.message());
}
示例3: onError
void ProtocolLogin::onError(const boost::system::error_code& error)
{
callLuaField("onError", error.message(), true);
disconnect();
}
示例4: wrote
void ClientConnection::wrote( const boost::system::error_code& error,
size_t bytes_transferred )
{
if (error)
LOGERROR(LT("Failed to write to "), this->socket->remote_endpoint(), LT(" - transferred "), bytes_transferred, LT(" bytes - "), error.message());
else
{
LOGTRACE(LT("Succesfully wrote "), this->outbox.front(), LT(" to "), this->socket->remote_endpoint());
boost::lock_guard<boost::mutex> scope_guard(this->outbox_mutex);
this->outbox.pop_front();
}
if( !this->outbox.empty() )
this->write();
}
示例5: SafeGetIPAddress
void
TCPConnection::ReportDebugMessage(const String &message, const boost::system::error_code &error)
{
String formattedMessage;
formattedMessage.Format(_T("%s Remote IP: %s, Session: %d, Code: %d, Message: %s"), message.c_str(), SafeGetIPAddress().c_str(), GetSessionID(), error.value(), String(error.message()).c_str());
LOG_DEBUG(formattedMessage);
}
示例6: operator
// boost::asio::async_read 回调.
void operator()( const boost::system::error_code &ec, int bytes_transferred )
{
bool try_http_redirect = false;
if( ec && (ec != boost::asio::error::eof ))
{
m_sender( boost::str( boost::format("@%s, 获取url有错 %s") % m_speaker % ec.message() ) );
return;
}
m_html_page->append_partial_html(std::string( &(*m_content)[0], bytes_transferred));
// 解析 <title>
auto title = (*m_html_page)["title"].to_plain_text();
if (title.empty() && !ec)
{
m_httpstream->async_read_some(boost::asio::buffer(*m_content, 512), *this);
return;
}else if (ec == boost::asio::error::eof)
{
try_http_redirect = true;
return;
}
// 获取charset
auto charset = (*m_html_page).charset();
if(!try_http_redirect)
{
try
{
if( charset != "utf8" && charset != "utf" && charset != "utf-8" )
{
title = boost::locale::conv::between( title, "UTF-8", charset );
}
boost::trim( title );
title = html_unescape(title);
// 将 &bnp 这种反格式化.
m_sender( boost::str( boost::format("@%s ⇪ 标题: %s ") % m_speaker % title ) );
}
catch( const std::runtime_error & )
{
m_sender( boost::str( boost::format("@%s ⇪ 解码网页发生错误 ") % m_speaker ) );
}
}
else
{
// 解析是不是 html 重定向
auto dom_page = (*m_html_page)["meta [http-equiv][content][url]"];
auto cd = dom_page.get_children();
if (!cd.empty())
{
auto url = cd[0]->get_attr("url");
if (m_redirect < 10 && !url.empty())
{
urlpreview(io_service, m_sender, m_speaker, url, m_redirect + 1);
}else
{
m_sender( boost::str( boost::format("@%s ⇪ url 无标题 ") % m_speaker ) );
}
}else
{
// 还是没有 title ?
m_sender( boost::str( boost::format("@%s, 获取url有错 %s") % m_speaker % ec.message() ) );
}
}
}
示例7: on_disconnected
void on_disconnected(boost::system::error_code const& ec, uint32_t sock_id)
{
LogInfo("Client " << sock_id << " disconnected with error: " << ec.message() );
sockets_.erase(sock_id);
// peers_.erase(std::find_if(peers_.begin(), peers_.end(), [sock_id](std::pair<id_type, uint32_t> p) { return p.second == sock_id; }));
}
示例8: HandleRead
void CSapConnection::HandleRead(const boost::system::error_code& err,std::size_t dwTransferred)
{
SS_XLOG(XLOG_DEBUG,"CSapConnection::%s,id[%d],bytes_transferred[%d]\n",__FUNCTION__,m_nId,dwTransferred);
if(!err)
{
gettimeofday_a(&m_AlivePoint,NULL);
buffer_.inc_loc(dwTransferred);
while(buffer_.top()>=m_pHeader+sizeof(SSapMsgHeader))
{
SSapMsgHeader *ptrHeader=(SSapMsgHeader *)m_pHeader;
unsigned int packetlen=ntohl(ptrHeader->dwPacketLen);
if(packetlen<=MAX_SAP_PAKET_LEN&&packetlen>0&&(ptrHeader->byIdentifer==SAP_PACKET_REQUEST||ptrHeader->byIdentifer==SAP_PACKET_RESPONSE))
{
if(buffer_.top()>=m_pHeader+packetlen)
{
ReadPacketCompleted(m_pHeader,packetlen);
m_pHeader+=packetlen;
}
else
{
break;
}
}
else
{
SS_XLOG(XLOG_WARNING,"CSapConnection::%s,id[%d],packetlen[%d],identifier[%d], will close this socket\n",__FUNCTION__,m_nId,packetlen,ptrHeader->byIdentifer);
StopConnection();
return;
}
}
if(m_pHeader!=buffer_.base())
{
memmove(buffer_.base(),m_pHeader,buffer_.top()-m_pHeader);
buffer_.reset_loc(buffer_.top()-m_pHeader);
m_pHeader=buffer_.base();
}
else if(buffer_.capacity()==0)
{
m_pHeader=buffer_.base();
SSapMsgHeader *ptrHeader=(SSapMsgHeader *)m_pHeader;
unsigned int packetlen=ntohl(ptrHeader->dwPacketLen);
buffer_.add_capacity(SAP_ALIGN(packetlen));
m_pHeader=buffer_.base();
}
m_socket.async_read_some(boost::asio::buffer(buffer_.top(),buffer_.capacity()),
MakeSapAllocHandler(m_allocReader,boost::bind(&CSapConnection::HandleRead, shared_from_this(),
boost::asio::placeholders::error,boost::asio::placeholders::bytes_transferred)));
}
else
{
SS_SLOG(XLOG_WARNING,"CSapConnection::"<<__FUNCTION__<<",id["<<m_nId<<"],error:" <<err.message()<<"\n");
StopConnection();
}
}
示例9: HandleWrite
void CSapConnection::HandleWrite(const boost::system::error_code& err)
{
SS_XLOG(XLOG_DEBUG,"CSapConnection::%s,id[%d]\n",__FUNCTION__,m_nId);
SSapMsgHeader *pHeader=NULL;
unsigned int dwServiceId=0;
unsigned int dwMsgId=0;
if(err)
{
SS_SLOG(XLOG_WARNING,"CSapConnection::"<<__FUNCTION__<<",id["<<m_nId<<"],error:" <<err.message()<<"\n");
while(!m_queue.empty())
{
SSapMsgHeader *pHeader=(SSapMsgHeader *)(m_queue.front().pBuffer);
unsigned int dwServiceId=ntohl(pHeader->dwServiceId);
unsigned int dwMsgId=ntohl(pHeader->dwMsgId);
if(!(dwServiceId==0&&dwMsgId==0))
{
if(pHeader->byIdentifer==SAP_PACKET_REQUEST && m_pSession!=NULL)
{
SSapMsgHeader stSendFailResponse;
stSendFailResponse.byIdentifer=SAP_PACKET_RESPONSE;
stSendFailResponse.byHeadLen=sizeof(SSapMsgHeader);
stSendFailResponse.dwPacketLen=htonl(sizeof(SSapMsgHeader));
stSendFailResponse.byVersion=0x1;
stSendFailResponse.dwCode=htonl(ERROR_SOS_SEND_FAIL);
stSendFailResponse.dwServiceId=pHeader->dwServiceId;
stSendFailResponse.dwMsgId=pHeader->dwMsgId;
stSendFailResponse.dwSequence=pHeader->dwSequence;
m_pSession->OnReceiveSosAvenueResponse(m_nId,&stSendFailResponse,sizeof(stSendFailResponse),m_strRemoteIp,m_dwRemotePort);
}
free((void *)(m_queue.front().pBuffer));
}
m_queue.pop_front();
m_nQueueLen--;
}
HandleStop();
return;
}
pHeader=(SSapMsgHeader *)(m_queue.front().pBuffer);
dwServiceId=ntohl(pHeader->dwServiceId);
dwMsgId=ntohl(pHeader->dwMsgId);
if(!(dwServiceId==0&&dwMsgId==0))
{
free((void *)(m_queue.front().pBuffer));
}
m_queue.pop_front();
m_nQueueLen--;
if (!m_queue.empty())
{
boost::asio::async_write(m_socket,
boost::asio::buffer(m_queue.front().pBuffer,m_queue.front().nLen),
MakeSapAllocHandler(m_allocWrite,boost::bind(&CSapConnection::HandleWrite, shared_from_this(),
boost::asio::placeholders::error)));
}
}
示例10: handle_handshake
void ssl_connection::handle_handshake(const boost::system::error_code& error) {
if (!error)
connection::start();
else {
handler_->log_error(__FILE__, __LINE__, _T("Failed to establish secure connection: ") + to_wstring(error.message()));
//ConnectionManager_.stop(shared_from_this());
}
}
示例11: handle_read
void Connection::handle_read(const boost::system::error_code& e,
std::size_t bytes_transferred)
{
if (!e)
{
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "in handle read with no error";
#endif
boost::tribool result;
result = requestParser->parse(request_.get(), buffer_.data(), bytes_transferred);
if (result)
{
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "in result";
#endif
reply_ = Response_ptr(factory->produceResponse());
requestHandler->handleRequest(request_.get(), reply_.get());
std::ostream ostream(&outBuff);
reply_->parseIntoOstream(&ostream);
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "Sending reply to: " << socket().remote_endpoint().address().to_string()
<< " size: " << reply_->getSize() << " status: " << reply_->status();
#endif
boost::asio::async_write(socket_, outBuff,
strand_.wrap(
boost::bind(&Connection::handle_write, shared_from_this(),
boost::asio::placeholders::error)));
}
else if (!result)
{
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "in not result";
#endif
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "Result not parsed";
#endif
reply_ = Response_ptr(factory->produceResponse());
requestHandler->badRequestResponse(reply_.get());
std::ostream ostream(&outBuff);
reply_->parseIntoOstream(&ostream);
boost::asio::async_write(socket_, outBuff,
strand_.wrap(
boost::bind(&Connection::handle_write, shared_from_this(),
boost::asio::placeholders::error)));
}
else
{
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "in else";
#endif
socket_.async_read_some(boost::asio::buffer(buffer_), strand_.wrap(
boost::bind(&Connection::handle_read, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
}
}
else {
#ifdef DEBUG_LOGGING
BOOST_LOG_TRIVIAL(debug) << "Error in handle_read: " << e.message();
#endif
}
}
示例12: SendEvent
//----------------------------------------------------------------------------------
void TNetControlTCP::SendEvent(const boost::system::error_code& error,size_t bytes_transferred)
{
if(error)
GetLogger(STR_NAME_NET_TRANSPORT)->
WriteF_time("SendEvent TCP error=%s.\n",error.message().data());
}
示例13: HandleAccept
void Acceptor::HandleAccept(int reference, boost::shared_ptr<boost::asio::ip::tcp::socket> socket, const boost::system::error_code& error) {
LogDebug("Acceptor::HandleAccept (%p) (id:%u) (new socket %p)", this, m_acceptorId, socket.get());
lua_State* L = LuaNode::GetLuaVM();
lua_rawgeti(L, LUA_REGISTRYINDEX, reference);
luaL_unref(L, LUA_REGISTRYINDEX, reference);
lua_getfield(L, 1, "callback");
assert(lua_type(L, -1) == LUA_TFUNCTION); //An acceptor must have a callback"
if(!error) {
// Get the remote endpoint, dealing with the case the connection is already closed when we get here.
boost::system::error_code ec;
const boost::asio::ip::tcp::endpoint& endpoint = socket->remote_endpoint(ec);
if(ec) {
if(ec == boost::asio::error::not_connected) {
LogWarning("Acceptor::HandleAccept (%p) (id:%u) (new socket %p) - Socket was already closed when accepted. %s",
this, m_acceptorId, socket.get(), ec.message().c_str());
}
else {
LogWarning("Acceptor::HandleAccept (%p) (id:%u) (new socket %p) - Error retrieving remote endpoint. %s",
this, m_acceptorId, socket.get(), ec.message().c_str());
}
LogInfo("Acceptor::HandleAccept - Retrying accept operation");
lua_settop(L, 1); // leave only 'self' on the stack
Accept(L);
return;
}
boost::asio::ip::address address = endpoint.address();
lua_pushnil(L);
lua_newtable(L);
int peer = lua_gettop(L);
lua_pushstring(L, "socket");
Socket* luasocket = new Socket(L, socket);
Socket::push(L, luasocket, true); // now Socket is the owner
lua_rawset(L, peer);
const std::string& sAddress = address.to_string();
lua_pushstring(L, "address");
lua_pushlstring(L, sAddress.c_str(), sAddress.length());
lua_rawset(L, peer);
lua_pushstring(L, "port");
lua_pushnumber(L, endpoint.port());
lua_rawset(L, peer);
LuaNode::GetLuaVM().call(2, LUA_MULTRET);
}
else {
if(error != boost::asio::error::operation_aborted) {
LogError("Acceptor::HandleAccept (%p) (id:%u) (new socket %p) - %s", this, m_acceptorId, socket.get(), error.message().c_str());
}
int ret = BoostErrorToCallback(L, error);
LuaNode::GetLuaVM().call(ret, LUA_MULTRET);
}
lua_settop(L, 0);
}
示例14:
// Report a failure
void
fail(boost::system::error_code ec, char const* what)
{
std::cerr << what << ": " << ec.message() << "\n";
}
示例15: HandleResolve
void CSapConnection::HandleResolve(const boost::system::error_code& err,tcp::resolver::iterator endpoint_iterator,unsigned int dwLocalPort)
{
if (!err)
{
if(dwLocalPort!=0)
{
boost::system::error_code ec;
m_socket.open(tcp::v4(),ec);
if(ec)
{
SS_SLOG(XLOG_WARNING,"CSapConnection::"<<__FUNCTION__<<",id["<<m_nId<<"],open socket error:" <<ec.message()<<"\n");
ConnectFinish(-1);
return;
}
m_socket.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true),ec);
m_socket.set_option(boost::asio::ip::tcp::no_delay(true),ec);
m_socket.bind(tcp::endpoint(tcp::v4(),dwLocalPort),ec);
if(ec)
{
SS_SLOG(XLOG_WARNING,"CSapConnection::"<<__FUNCTION__<<",id["<<m_nId<<"],bind port error:" <<ec.message()<<"\n");
ConnectFinish(-1);
return;
}
}
tcp::endpoint endpoint = *endpoint_iterator;
SS_XLOG(XLOG_DEBUG,"CSapConnection::%s,id[%d],addr[%s:%d]\n",__FUNCTION__,m_nId,endpoint.address().to_string() .c_str() ,endpoint.port());
m_socket.async_connect(endpoint,
MakeSapAllocHandler(m_allocReader, boost::bind(&CSapConnection::HandleConnected, shared_from_this(),
boost::asio::placeholders::error, ++endpoint_iterator)));
}
else
{
SS_SLOG(XLOG_WARNING,"CSapConnection::"<<__FUNCTION__<<",id["<<m_nId<<"],error:" <<err.message()<<"\n");
ConnectFinish(-2);
}
}