summaryrefslogtreecommitdiff
path: root/httpd.h
blob: f9c09301e5cea99990a3c09a8eb581e8e662cfc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef HTTPD_H
#define HTTPD_H

#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>

using boost::asio::ip::tcp;

class HTTPConnection : public boost::enable_shared_from_this<HTTPConnection> {
	friend class HTTPServer;

	private:
		HTTPConnection(boost::asio::io_service& io_service);
		void handle_write(const boost::system::error_code& error, size_t bytes_transferred);
		void handle_read(const boost::system::error_code& error, size_t bytes_transferred);
		tcp::socket socket;
		boost::asio::streambuf buf;

	public:
		typedef boost::shared_ptr<HTTPConnection> pointer;

		static pointer create(boost::asio::io_service& io_service);
		void start();
};

class HTTPServer {
	private:
		void start_accept();
		void handle_accept(HTTPConnection::pointer new_connection, const boost::system::error_code& error);

		tcp::acceptor acceptor_;

	public:
		HTTPServer(boost::asio::io_service& io_service, const tcp::endpoint& endpoint);
};

#endif