本文整理汇总了C++中tcp::socket::is_open方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::is_open方法的具体用法?C++ socket::is_open怎么用?C++ socket::is_open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tcp::socket
的用法示例。
在下文中一共展示了socket::is_open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CloseConnection
static void CloseConnection(tcp::acceptor &_acceptor, tcp::socket &_socket) {
log_info(LOG_PREFIX, "disconnecting");
if (_acceptor.is_open()) {
_acceptor.close();
}
if (_socket.is_open()) {
_socket.close();
}
}
示例2: configure
void EthernetRelayDriver::configure(std::string host, int port){
tcp::endpoint endpoint(boost::asio::ip::address::from_string(host.c_str()), port);
socket.connect(endpoint);
if(socket.is_open()){
ROS_INFO("TCP/IP socket opened.");
}
}
示例3: Close
inline bool TCPServerSession::Close()
{
try
{
if (!mSocket.is_open()) return false;
mSocket.shutdown(socket_base::shutdown_both);
mSocket.close();
return true;
}
catch (...)
{
return false;
}
}
示例4: processPackets
error_code Packet::processPackets( tcp::socket& socket )
{
error_code ec;
// Send welcome message to client
ec = welcomeClient( socket );
if ( ec ) return ec;
// Communicate with client using defined protocol
do
{
ec = recv( socket );
if ( !ec )
{
if ( isValidVersion() && isValidMsgType() )
{
if ( getMsgType() == MSG_EXIT )
{
lockStream();
LOG_INF() << "EXIT packet received! -> " << *this << endl;
unlockStream();
}
else
if ( getMsgType() == MSG_COMMAND )
{
ec = processCommand( getMessage(), socket );
lockStream();
LOG_INF() << "COMMAND PROCESSING COMPLETED!" << endl;
unlockStream();
}
}
else
{
lockStream();
LOG_ERR() << "Invalid message format! -> " << *this << endl;
unlockStream();
}
}
} while ( !ec && socket.is_open() &&
getMsgType() != MSG_EXIT &&
getMessage() != "EXIT" );
lockStream();
LOG_INF() << "Session ended with client!" << endl;
unlockStream();
return ec;
}
示例5: GetPort
static inline int GetPort(const tcp::socket &socket) {
return (socket.is_open() ? socket.local_endpoint().port() : 0);
}