当前位置: 首页>>代码示例>>C++>>正文


C++ socket::close方法代码示例

本文整理汇总了C++中tcp::socket::close方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::close方法的具体用法?C++ socket::close怎么用?C++ socket::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcp::socket的用法示例。


在下文中一共展示了socket::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: connectSocket

void connectSocket(boost::asio::io_service& io_service, tcp::socket& socket, const std::string& url, const std::string &port) {
	boost::system::error_code error = boost::asio::error::host_not_found;

	// connect
	if (isIpAddress(url.c_str())) {
		boost::asio::ip::address addr = boost::asio::ip::address::from_string(url);
		boost::asio::ip::tcp::endpoint endpoint = boost::asio::ip::tcp::endpoint(addr, lexical_cast<int>(port));
		socket.close();
		socket.connect(endpoint);
	}
	else {
		tcp::resolver::query query(url, "http");
		tcp::resolver resolver(io_service);
		tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
		tcp::resolver::iterator end;

		while (error && endpoint_iterator != end)
		{
			socket.close();
			socket.connect(*endpoint_iterator++, error);
		}
		if (error)
			throw boost::system::system_error(error);
	}
}
开发者ID:hamling-ling,项目名称:KirinCam,代码行数:25,代码来源:StreamDump.cpp

示例2: handle_connect

	// Conexion al servidor
	void handle_connect(const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator){
		debugOUT("handle_connect");
		if (!error){
			connected = true;
			debugOUT("Connected");

			boost::asio::async_read(socket_,
									boost::asio::buffer(receiveBuffer, transferAtLeast),
									boost::asio::transfer_at_least(transferAtLeast),
									boost::bind(&TCPClient::handle_read, this,
									boost::asio::placeholders::error,
									boost::asio::placeholders::bytes_transferred));

			debugOUT("async_read dispatched");
		}
		else if (endpoint_iterator != tcp::resolver::iterator()){
			debugOUT("Next Endpoint");
			// Conexion fallida, intentemos con el siguiente endpoint
			socket_.close();
			tcp::endpoint endpoint = *endpoint_iterator;
			
			socket_.async_connect(	endpoint,
									boost::bind(&TCPClient::handle_connect, this,
									boost::asio::placeholders::error, ++endpoint_iterator));
		}
		else{
			debugOUT("Error: " << error.message());
		}
	}
开发者ID:dragondgold,项目名称:BrightnessController-Windows,代码行数:30,代码来源:TCPClient.hpp

示例3: acceptor

void
controller::listen_for_command()
{
    LOG(INFO) << "Listening for commands...";
    boost::system::error_code error;
    asio::streambuf buffer;

    try
    {
        uint16_t port = global::config()->get("controller.port", 3103);
        tcp::acceptor acceptor(this->io_service_,
                               tcp::endpoint(tcp::v4(), port));

        while (true)
        {
            acceptor.accept(controll_socket_);
            while (true)
            {
                asio::read_until(controll_socket_, buffer, regex("\n"), error);
                if (error)
                    break;

                std::istream is(&buffer);
                string line;
                std::getline(is, line);
                process_command(line);
            }
            controll_socket_.close();
        }
    }
    catch (std::exception& e)
    {
        LOG(ERROR) << e.what();
    }
}
开发者ID:khoinguyentran,项目名称:hdb-node,代码行数:35,代码来源:controller.cpp

示例4: accept

    void accept()
    {
        // Clean up any previous connection.
        boost::beast::error_code ec;
        socket_.close(ec);
        buffer_.consume(buffer_.size());

        acceptor_.async_accept(
            socket_,
            [this](boost::beast::error_code ec)
            {
                if (ec)
                {
                    accept();
                }
                else
                {
                    // Request must be fully processed within 60 seconds.
                    request_deadline_.expires_after(
                        std::chrono::seconds(60));

                    read_request();
                }
            });
    }
开发者ID:miguelportilla,项目名称:Beast,代码行数:25,代码来源:http_server_fast.cpp

示例5: catch

		~Client()
		{
			try {
				tcp_socket->close();
			} catch (bs::system_error e) {}
			
			delete tcp_socket;
		}
开发者ID:tomciokotar,项目名称:Sound-Broadcaster,代码行数:8,代码来源:server.cpp

示例6: 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();
   }
 }
开发者ID:gitmesen,项目名称:carla,代码行数:9,代码来源:TCPServer.cpp

示例7: really_disconnect

static void really_disconnect(tcp::socket& socket, Logger* logger)
{
	try {
		socket.shutdown(socket_base::shutdown_both);
		socket.close();
	} catch(const system::system_error& e) {
		// This might be totally okay. Depends on the error.
		logger->warning(format("Failed to shut down the socket. This shouldn't happen! (%1%)") % e.what());
	}
}
开发者ID:gogo-dev,项目名称:GoGo,代码行数:10,代码来源:Client.cpp

示例8: reply

void CMD::reply(tcp::socket& s, std::string message)
{
  try {
      boost::asio::write(s, boost::asio::buffer(
						str(boost::format("%1% %2%\r\n") % id % message)
					       )
			);
      s.close();
  } catch (boost::system::system_error &e) {
      std::cerr <<  "Exception:" << e.what() << std::endl;
  }
}
开发者ID:snyh,项目名称:WHMon,代码行数:12,代码来源:cmd.cpp

示例9: 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;
	}
}
开发者ID:scp1513,项目名称:cppserver,代码行数:14,代码来源:tcp_server.cpp

示例10: check_deadline

    void check_deadline()
    {
        // The deadline may have moved, so check it has really passed.
        if (request_deadline_.expiry() <= std::chrono::steady_clock::now())
        {
            // Close socket to cancel any outstanding operation.
            boost::beast::error_code ec;
            socket_.close();

            // Sleep indefinitely until we're given a new deadline.
            request_deadline_.expires_at(
                std::chrono::steady_clock::time_point::max());
        }

        request_deadline_.async_wait(
            [this](boost::beast::error_code)
            {
                check_deadline();
            });
    }
开发者ID:miguelportilla,项目名称:Beast,代码行数:20,代码来源:http_server_fast.cpp

示例11: find

void L2Socket::Disconnect(tcp::socket& _socket,size_t _agentOID)
{
    //return;
    if( _agentOID != -1 )
    {
        UIntAry::iterator _it = find( agentOIDAry.begin(),agentOIDAry.end(),_agentOID );
        
        if( _it != agentOIDAry.end() )
        {
            shared_ptr<L2Agent> agt = L2_FIND_OBJ(L2Agent, _agentOID);
            agt->Disconnect();
            agentOIDAry.erase( _it );
            
            LOG( "Disconnect !!! ip: "+_socket.remote_endpoint().address().to_string()+" port: "+ _socket.remote_endpoint().port() );
        }
    }
    else
        LOG( "Disconnect !!!" );
    _socket.close();
    SocketAry::iterator _it = find( sockAry.begin(),sockAry.end(),&_socket );
    
    if( _it != sockAry.end() )  sockAry.erase( _it );
}
开发者ID:LockeLin,项目名称:WebSocket_server,代码行数:23,代码来源:socket.cpp

示例12: resolver

	NetworkDevice(Stats &stats, const char *address)
	: Device(stats), socket(io_service)
	{
		stringstream portstr;
		portstr << SERVER_PORT;

		tcp::resolver resolver(io_service);
		tcp::resolver::query query(address, portstr.str());
		tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
		tcp::resolver::iterator end;

		boost::system::error_code error = boost::asio::error::host_not_found;
		while(error && endpoint_iterator != end)
		{
			socket.close();
			socket.connect(*endpoint_iterator++, error);
		}

		if(error)
			throw boost::system::system_error(error);

		mem_counter = 0;
	}
开发者ID:Eibriel,项目名称:blender-dfelinto,代码行数:23,代码来源:device_network.cpp

示例13: do_close

 void do_close() {
     clientSocket.close();
 };
开发者ID:tim94114,项目名称:scapi,代码行数:3,代码来源:TwoPartyComm.hpp

示例14: do_close

 void do_close()
 {
     socket_.close();
 }
开发者ID:mw-ding,项目名称:DMW-Chat,代码行数:4,代码来源:chat_client.cpp

示例15:

void
session::perform(tcp::socket& s, asio::yield_context) {
    s.close();
}
开发者ID:paulhilbert,项目名称:magellan,代码行数:4,代码来源:session.cpp


注:本文中的tcp::socket::close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。