summaryrefslogtreecommitdiff
path: root/httpd.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-12-27 02:47:56 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-12-27 02:47:56 +0100
commit9f78196611d8065f63ae4a81297723663d222ebe (patch)
treeb70e94f4f581db1298d86d3a44b3a2e2851c076d /httpd.cpp
parent6e376f69305dabe59362bb80051e4265c6409fe3 (diff)
Added a simple HTTP service which doesn't yet do anything useful.
Diffstat (limited to 'httpd.cpp')
-rw-r--r--httpd.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/httpd.cpp b/httpd.cpp
new file mode 100644
index 0000000..5de9948
--- /dev/null
+++ b/httpd.cpp
@@ -0,0 +1,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();
+ }
+}