本文整理汇总了C++中socket_ptr::remote_endpoint方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_ptr::remote_endpoint方法的具体用法?C++ socket_ptr::remote_endpoint怎么用?C++ socket_ptr::remote_endpoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket_ptr
的用法示例。
在下文中一共展示了socket_ptr::remote_endpoint方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: async_connect_handler
/// 连接回调
void tcp_connector::async_connect_handler( boost::system::error_code const& ec
, socket_ptr pSock, FactoryFunc fact_func, ConnectHandler const& handler
, options_ptr opts, tcp::resolver::iterator resolver_it )
{
tcp_session_ptr ptr;
boost::system::error_code remote_ec, local_ec;
if (!ec && pSock->remote_endpoint(remote_ec) != pSock->local_endpoint(local_ec)
&& !remote_ec && !local_ec)
ptr = fact_func(pSock, session_initialized(session_id(), group_id(), opts));
else if (tcp::resolver::iterator() != resolver_it)
{
boost::system::error_code close_ec;
pSock->close(close_ec);
if (close_ec)
pSock.reset(new socket(m_ios));
tcp::endpoint endpoint = *resolver_it++;
pSock->async_connect(endpoint
, boost::bind(&tcp_connector::async_connect_handler, this, placeholders::error
, pSock, fact_func, handler, opts, resolver_it ));
return ;
}
handler(ptr, ec);
}
示例2: connection
void Server::connection(socket_ptr _sock) {
try {
CLOG_INFO << "Connection, peer IP: " << _sock->remote_endpoint().address().to_string() << endl;
Operation op;
receive(_sock, op);
if ( op == Operation::CREATE ) {
Counter(_sock, this);
}
else if ( op == Operation::INFO_DEVICE ||
op == Operation::LIST_DEVICES ||
op == Operation::CMD_STATUS ||
op == Operation::READ_DEVICE ) {
Info(_sock, op, this);
}
else {
send<int>(_sock, (int)Retval::ERROR);
}
_sock->close();
}
catch (exception& e) {
CLOG_ERROR << "Exception in thread: " << e.what() << endl;
}
}
示例3: handle_accept
void network_impl::handle_accept(socket_ptr socket)
{
tcp::endpoint remote_endpoint = socket->remote_endpoint();
log_debug() << "New incoming connection from "
<< remote_endpoint.address().to_string();
channel_handle chanid = create_channel(socket);
kernel_->handle_connect(chanid);
socket.reset(new tcp::socket(*service()));
acceptor_->async_accept(*socket,
std::bind(&network_impl::handle_accept, shared_from_this(),
socket));
}
示例4: handle_incomming_package
void Server::handle_incomming_package(Package_ptr & package, socket_ptr & socket, boost::system::error_code const & error)
{
if (!error)
{
std::clog << "[LOG] Incomming package from : " << socket->remote_endpoint().address().to_string() << std::endl;
boost::lock_guard<boost::mutex> lock(in_packages_mut_);
incomming_packages_.push_back(package);
set_handle_read(socket, error);
}
else
{
disconnected(socket);
}
}
示例5: session
void session( socket_ptr sock ) {
try {
#ifdef VERBOSE
std::cout << "New client " << sock->remote_endpoint() << " connected." << std::endl << std::flush;
#endif
for (;;) {
boost::system::error_code error;
size_t length = sock->read_some( boost::asio::buffer( z, sizeof( Ccharacter ) ), error );
if ( error == boost::asio::error::eof ) {
#ifdef VERBOSE
std::cout << "Client " << sock->remote_endpoint() << " disconnected." << std::endl << std::flush;
#endif
break; // Connection closed cleanly by peer.
}
else if ( error )
throw boost::system::system_error( error ); // Some other error.
boost::asio::write( *sock, boost::asio::buffer( z, sizeof( Ccharacter ) ));
}
}
catch (std::exception& e) {
std::cerr << "Exception in thread: " << e.what() << "\n";
}
}
示例6: handleAccept
void StreamServer::handleAccept(socket_ptr socket)
{
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
setsockopt(socket->native(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
logS(kLogNotice) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket);
{
std::lock_guard<std::mutex> mlock(sessionsMutex_);
session->setBufferMs(settings_.bufferMs);
session->start();
sessions_.insert(session);
}
startAccept();
}
示例7: handle_accept
void Server::handle_accept(socket_ptr & socket, boost::system::error_code const & error)
{
if (!error)
{
boost::lock_guard<boost::mutex> lock(sockets_mut_);
std::clog << "[LOG] new connection from : " << socket->remote_endpoint().address().to_string() << std::endl;
sockets_[socket->native_handle()] = socket;
set_handle_read(socket, error);
if (!synchronize_.empty())
synchronize_(socket);
}
else
{
std::cerr << "Error : " << error.message() << std::endl;
}
start();
}
示例8: client_session
void network::client_session(socket_ptr sock){
using namespace boost::property_tree;
ip::tcp::endpoint remote_endpoint = sock->remote_endpoint();
cout<<"NEW CONNECTION BUILT:FROM:IP{"<<remote_endpoint.address().to_string().c_str()<<"},PORT:{"<<remote_endpoint.port()<<"}"<<endl;
connection_center.register_(remote_endpoint.address().to_string(),
remote_endpoint.port(),sock);
stringstream strings;
strings<<"WELCOME !! ["<<remote_endpoint.address().to_string().c_str()<<":"<<remote_endpoint.port()<<"] login.";
loader->process_request(sock,MSG_WELCOME,strlen(MSG_WELCOME));
try
{
while(true){
char data[MSG_LEN];
memset(data,0,MSG_LEN);
size_t len = sock->read_some(buffer(data));
if(len > 0){
cout<<"RECEIVE ["<<data<<"]FROM:IP{"<<remote_endpoint.address().to_string().c_str()<<"},PORT:{"<<remote_endpoint.port()<<"}"<<endl;
//同步 进行
loader->process_request(sock,data,strlen(data));
}
}
}
catch(boost::system::system_error & e)
{
cout<<"EXCEPTION TERMINATE: BY IP{"<<remote_endpoint.address().to_string().c_str()<<"},PORT:{"<<remote_endpoint.port()<<"}"<<endl;
connection_center.login_out(remote_endpoint.address().to_string(),
remote_endpoint.port());
loader->process_request(sock,MSG_DISCONNECT,strlen(MSG_DISCONNECT));
return;
}
cout<<"SESSION CLOSED OF IP{"<<remote_endpoint.address().to_string().c_str()<<"},PORT:{"<<remote_endpoint.port()<<"}"<<endl;
connection_center.login_out(remote_endpoint.address().to_string(),
remote_endpoint.port());
loader->process_request(sock,MSG_EXIT,strlen(MSG_EXIT));
return;
}