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


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

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


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

示例1: handle_read

 void handle_read(const boost::system::error_code &error,
                  size_t bytes_transferred) {
     if (!error) {
         std::string query(data_);
         std::string *file = new std::string("");
         file->append(directory.c_str()).append(strtok((strtok((char *) (query.c_str()), "GET ")),"?="));
         FILE*f = fopen("/home/box/output.txt","w");
         fwrite(file->c_str(),1,file->size(),f);
         fclose(f);
         FILE *file_ptr = fopen(file->c_str(), "r");
         if (file_ptr != nullptr) {
             boost::asio::write(socket_, boost::asio::buffer(found,strlen(found)));
             for (int bytes_read = fread(data_, sizeof(char), 1024, file_ptr); bytes_read != 0;
                 bytes_read = fread(data_, sizeof(char), 1024, file_ptr)) {
                 std::string deliver(data_);
                 boost::asio::write(socket_, boost::asio::buffer(deliver.c_str(),bytes_read));
             }
         } else {
             boost::asio::write(socket_, boost::asio::buffer(not_found,strlen(not_found)));
         }
         socket_.shutdown(boost::asio::socket_base::shutdown_type::shutdown_both);
         handle_write();
     } else {
         delete this;
     }
 }
开发者ID:nikitaband1t,项目名称:finalProject,代码行数:26,代码来源:main.cpp

示例2: do_run

 void
 do_run()
 {
     try
     {
         beast::error_code ec;
         beast::flat_buffer buffer;
         for(;;)
         {
             http::request_parser<http::string_body> parser;
             parser.header_limit(8192);
             parser.body_limit(1024 * 1024);
             http::read(sock_, buffer, parser, ec);
             if(ec == http::error::end_of_stream)
                 break;
             if(ec)
                 throw beast::system_error{ec};
             do_request(parser.get(), ec);
             if(ec)
             {
                 if(ec != http::error::end_of_stream)
                     throw beast::system_error{ec};
                 break;
             }
         }
         sock_.shutdown(tcp::socket::shutdown_both, ec);
         if(ec && ec != boost::asio::error::not_connected)
             throw beast::system_error{ec};
     }
     catch (const std::exception& e)
     {
         std::cerr << "Exception: " << e.what() << std::endl;
     }
 }
开发者ID:dreamsxin,项目名称:rippled,代码行数:34,代码来源:http_server_threaded.cpp

示例3: send_bad_response

    void send_bad_response(
        http::status status,
        std::string const& error)
    {
        string_response_.emplace(
            std::piecewise_construct,
            std::make_tuple(),
            std::make_tuple(alloc_));

        string_response_->result(status);
        string_response_->keep_alive(false);
        string_response_->set(http::field::server, "Beast");
        string_response_->set(http::field::content_type, "text/plain");
        string_response_->body() = error;
        string_response_->prepare_payload();

        string_serializer_.emplace(*string_response_);

        http::async_write(
            socket_,
            *string_serializer_,
            [this](boost::beast::error_code ec, std::size_t)
            {
                socket_.shutdown(tcp::socket::shutdown_send, ec);
                string_serializer_.reset();
                string_response_.reset();
                accept();
            });
    }
开发者ID:miguelportilla,项目名称:Beast,代码行数:29,代码来源:http_server_fast.cpp

示例4: 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

示例5: send_file

    void send_file(boost::beast::string_view target)
    {
        // Request path must be absolute and not contain "..".
        if (target.empty() || target[0] != '/' || target.find("..") != std::string::npos)
        {
            send_bad_response(
                http::status::not_found,
                "File not found\r\n");
            return;
        }

        std::string full_path = doc_root_;
        full_path.append(
            target.data(),
            target.size());

        http::file_body::value_type file;
        boost::beast::error_code ec;
        file.open(
            full_path.c_str(),
            boost::beast::file_mode::read,
            ec);
        if(ec)
        {
            send_bad_response(
                http::status::not_found,
                "File not found\r\n");
            return;
        }

        file_response_.emplace(
            std::piecewise_construct,
            std::make_tuple(),
            std::make_tuple(alloc_));

        file_response_->result(http::status::ok);
        file_response_->keep_alive(false);
        file_response_->set(http::field::server, "Beast");
        file_response_->set(http::field::content_type, mime_type(target.to_string()));
        file_response_->body() = std::move(file);
        file_response_->prepare_payload();

        file_serializer_.emplace(*file_response_);

        http::async_write(
            socket_,
            *file_serializer_,
            [this](boost::beast::error_code ec, std::size_t)
            {
                socket_.shutdown(tcp::socket::shutdown_send, ec);
                file_serializer_.reset();
                file_response_.reset();
                accept();
            });
    }
开发者ID:miguelportilla,项目名称:Beast,代码行数:55,代码来源:http_server_fast.cpp

示例6: 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


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