doc/html/boost_asio/example/http/server2/connection.hpp

//
// connection.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef HTTP_SERVER2_CONNECTION_HPP
#define HTTP_SERVER2_CONNECTION_HPP

#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "reply.hpp"
#include "request.hpp"
#include "request_handler.hpp"
#include "request_parser.hpp"

namespace http {
	namespace server2 {

		/// Represents a single connection from a client.
		class connection
			: public boost::enable_shared_from_this<connection>,
			private boost::noncopyable
		{
		public:
			/// Construct a connection with the given io_service.
			explicit connection(boost::asio::io_service& io_service,
				request_handler& handler);

			/// Get the socket associated with the connection.
			boost::asio::ip::tcp::socket& socket();

			/// Start the first asynchronous operation for the connection.
			void start();

		private:
			/// Handle completion of a read operation.
			void handle_read(const boost::system::error_code& e,
				std::size_t bytes_transferred);

			/// Handle completion of a write operation.
			void handle_write(const boost::system::error_code& e);

			/// Socket for the connection.
			boost::asio::ip::tcp::socket socket_;

			/// The handler used to process the incoming request.
			request_handler& request_handler_;

			/// Buffer for incoming data.
			boost::array<char, 8192> buffer_;

			/// The incoming request.
			request request_;

			/// The parser for the incoming request.
			request_parser request_parser_;

			/// The reply to be sent back to the client.
			reply reply_;
		};

		typedef boost::shared_ptr<connection> connection_ptr;

	} // namespace server2
} // namespace http

#endif // HTTP_SERVER2_CONNECTION_HPP
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值