summaryrefslogtreecommitdiff
path: root/httpd.cpp
blob: 5de9948f823988a4c9c5829e510cf4ec9b4f010b (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
#include "httpd.h"

#include <boost/bind.hpp>

#include <iostream>

HTTPConnection::HTTPConnection(boost::asio::io_service& io_service) : socket(io_service) {
}

void HTTPConnection::handle_write(const boost::system::error_code& error, size_t bytes_transferred) {
}

HTTPConnection::pointer HTTPConnection::create(boost::asio::io_service& io_service) {
	return pointer(new HTTPConnection(io_service));
}

void HTTPConnection::start() {
	std::cout << "kake" << std::endl;
}

HTTPServer::HTTPServer(boost::asio::io_service& io_service) : acceptor_(io_service, tcp::endpoint(tcp::v4(), 8000)) {
	start_accept();
}

void HTTPServer::start_accept() {
	HTTPConnection::pointer new_connection = HTTPConnection::create(acceptor_.io_service());
	acceptor_.async_accept(new_connection->socket, boost::bind(&HTTPServer::handle_accept, this, new_connection, boost::asio::placeholders::error));
}

void HTTPServer::handle_accept(HTTPConnection::pointer new_connection, const boost::system::error_code& error) {
	if(!error) {
		new_connection->start();
		start_accept();
	}
}