Selaa lähdekoodia

format all code

tanghai 15 vuotta sitten
vanhempi
commit
f6369b2221

+ 11 - 7
src/experimental/boost_asio_test.cc

@@ -9,7 +9,7 @@ class printer
 public:
 public:
 	printer(boost::asio::io_service& io) :
 	printer(boost::asio::io_service& io) :
 		strand_(io), timer1_(io, boost::posix_time::seconds(1)), timer2_(io,
 		strand_(io), timer1_(io, boost::posix_time::seconds(1)), timer2_(io,
-		        boost::posix_time::seconds(1)), count_(0)
+				boost::posix_time::seconds(1)), count_(0)
 	{
 	{
 		timer1_.async_wait(strand_.wrap(boost::bind(&printer::print1, this)));
 		timer1_.async_wait(strand_.wrap(boost::bind(&printer::print1, this)));
 		timer2_.async_wait(strand_.wrap(boost::bind(&printer::print2, this)));
 		timer2_.async_wait(strand_.wrap(boost::bind(&printer::print2, this)));
@@ -22,25 +22,29 @@ public:
 
 
 	void print1()
 	void print1()
 	{
 	{
-		if(count_ < 10)
+		if (count_ < 10)
 		{
 		{
 			std::cout << "Timer 1: " << count_ << "\n";
 			std::cout << "Timer 1: " << count_ << "\n";
 			++count_;
 			++count_;
 
 
-			timer1_.expires_at(timer1_.expires_at() + boost::posix_time::seconds(1));
-			timer1_.async_wait(strand_.wrap(boost::bind(&printer::print1, this)));
+			timer1_.expires_at(timer1_.expires_at()
+					+ boost::posix_time::seconds(1));
+			timer1_.async_wait(
+					strand_.wrap(boost::bind(&printer::print1, this)));
 		}
 		}
 	}
 	}
 
 
 	void print2()
 	void print2()
 	{
 	{
-		if(count_ < 10)
+		if (count_ < 10)
 		{
 		{
 			std::cout << "Timer 2: " << count_ << "\n";
 			std::cout << "Timer 2: " << count_ << "\n";
 			++count_;
 			++count_;
 
 
-			timer2_.expires_at(timer2_.expires_at() + boost::posix_time::seconds(1));
-			timer2_.async_wait(strand_.wrap(boost::bind(&printer::print2, this)));
+			timer2_.expires_at(timer2_.expires_at()
+					+ boost::posix_time::seconds(1));
+			timer2_.async_wait(
+					strand_.wrap(boost::bind(&printer::print2, this)));
 		}
 		}
 	}
 	}
 
 

+ 21 - 22
src/experimental/boost_function_test.cc

@@ -7,32 +7,31 @@
 #include <gflags/gflags.h>
 #include <gflags/gflags.h>
 #include <glog/logging.h>
 #include <glog/logging.h>
 
 
-namespace hainan
+namespace hainan {
+class BoostTest: public testing::Test
 {
 {
-	class BoostTest: public testing::Test
+	void SetUp()
 	{
 	{
-		void SetUp()
-		{
-			a = 6;
-		}
-	protected:
-		int a;
-		boost::function<int(int)> func;
-	public:
-		int Max(int a, int b)
-		{
-			LOG(INFO) << a << " " << b;
-			return a > b? a : b;
-		}
-	};
-
-	TEST_F(BoostTest, Test1)
+		a = 6;
+	}
+protected:
+	int a;
+	boost::function<int(int)> func;
+public:
+	int Max(int a, int b)
 	{
 	{
-		int x = 5;
-		func = boost::bind(&BoostTest::Max, this, _1, x);
-		int b = func(a);
-		LOG(INFO) << b;
+		LOG(INFO) << a << " " << b;
+		return a > b? a : b;
 	}
 	}
+};
+
+TEST_F(BoostTest, Test1)
+{
+	int x = 5;
+	func = boost::bind(&BoostTest::Max, this, _1, x);
+	int b = func(a);
+	LOG(INFO) << b;
+}
 }
 }
 
 
 int main(int argc, char* argv[])
 int main(int argc, char* argv[])

+ 42 - 32
src/experimental/chat/chat_message.cc

@@ -23,12 +23,14 @@ typedef std::deque<chat_message> chat_message_queue;
 class chat_client
 class chat_client
 {
 {
 public:
 public:
-	chat_client(boost::asio::io_service& io_service, tcp::resolver::iterator endpoint_iterator) :
+	chat_client(boost::asio::io_service& io_service,
+			tcp::resolver::iterator endpoint_iterator) :
 		io_service_(io_service), socket_(io_service)
 		io_service_(io_service), socket_(io_service)
 	{
 	{
 		tcp::endpoint endpoint = *endpoint_iterator;
 		tcp::endpoint endpoint = *endpoint_iterator;
-		socket_.async_connect(endpoint, boost::bind(&chat_client::handle_connect, this,
-		        boost::asio::placeholders::error, ++endpoint_iterator));
+		socket_.async_connect(endpoint, boost::bind(
+				&chat_client::handle_connect, this,
+				boost::asio::placeholders::error, ++endpoint_iterator));
 	}
 	}
 
 
 	void write(const chat_message& msg)
 	void write(const chat_message& msg)
@@ -44,30 +46,33 @@ public:
 private:
 private:
 
 
 	void handle_connect(const boost::system::error_code& error,
 	void handle_connect(const boost::system::error_code& error,
-	        tcp::resolver::iterator endpoint_iterator)
+			tcp::resolver::iterator endpoint_iterator)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
-			boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(),
-			        chat_message::header_length), boost::bind(&chat_client::handle_read_header,
-			        this, boost::asio::placeholders::error));
+			boost::asio::async_read(socket_, boost::asio::buffer(
+					read_msg_.data(), chat_message::header_length),
+					boost::bind(&chat_client::handle_read_header, this,
+							boost::asio::placeholders::error));
 		}
 		}
-		else if(endpoint_iterator != tcp::resolver::iterator())
+		else if (endpoint_iterator != tcp::resolver::iterator())
 		{
 		{
 			socket_.close();
 			socket_.close();
 			tcp::endpoint endpoint = *endpoint_iterator;
 			tcp::endpoint endpoint = *endpoint_iterator;
-			socket_.async_connect(endpoint, boost::bind(&chat_client::handle_connect, this,
-			        boost::asio::placeholders::error, ++endpoint_iterator));
+			socket_.async_connect(endpoint, boost::bind(
+					&chat_client::handle_connect, this,
+					boost::asio::placeholders::error, ++endpoint_iterator));
 		}
 		}
 	}
 	}
 
 
 	void handle_read_header(const boost::system::error_code& error)
 	void handle_read_header(const boost::system::error_code& error)
 	{
 	{
-		if(!error && read_msg_.decode_header())
+		if (!error && read_msg_.decode_header())
 		{
 		{
-			boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.body(),
-			        read_msg_.body_length()), boost::bind(&chat_client::handle_read_body, this,
-			        boost::asio::placeholders::error));
+			boost::asio::async_read(socket_, boost::asio::buffer(
+					read_msg_.body(), read_msg_.body_length()), boost::bind(
+					&chat_client::handle_read_body, this,
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -77,13 +82,14 @@ private:
 
 
 	void handle_read_body(const boost::system::error_code& error)
 	void handle_read_body(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			std::cout.write(read_msg_.body(), read_msg_.body_length());
 			std::cout.write(read_msg_.body(), read_msg_.body_length());
 			std::cout << "\n";
 			std::cout << "\n";
-			boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(),
-			        chat_message::header_length), boost::bind(&chat_client::handle_read_header,
-			        this, boost::asio::placeholders::error));
+			boost::asio::async_read(socket_, boost::asio::buffer(
+					read_msg_.data(), chat_message::header_length),
+					boost::bind(&chat_client::handle_read_header, this,
+							boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -95,24 +101,27 @@ private:
 	{
 	{
 		bool write_in_progress = !write_msgs_.empty();
 		bool write_in_progress = !write_msgs_.empty();
 		write_msgs_.push_back(msg);
 		write_msgs_.push_back(msg);
-		if(!write_in_progress)
+		if (!write_in_progress)
 		{
 		{
-			boost::asio::async_write(socket_, boost::asio::buffer(write_msgs_.front().data(),
-			        write_msgs_.front().length()), boost::bind(&chat_client::handle_write, this,
-			        boost::asio::placeholders::error));
+			boost::asio::async_write(socket_, boost::asio::buffer(
+					write_msgs_.front().data(), write_msgs_.front().length()),
+					boost::bind(&chat_client::handle_write, this,
+							boost::asio::placeholders::error));
 		}
 		}
 	}
 	}
 
 
 	void handle_write(const boost::system::error_code& error)
 	void handle_write(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			write_msgs_.pop_front();
 			write_msgs_.pop_front();
-			if(!write_msgs_.empty())
+			if (!write_msgs_.empty())
 			{
 			{
-				boost::asio::async_write(socket_, boost::asio::buffer(write_msgs_.front().data(),
-				        write_msgs_.front().length()), boost::bind(&chat_client::handle_write,
-				        this, boost::asio::placeholders::error));
+				boost::asio::async_write(socket_, boost::asio::buffer(
+						write_msgs_.front().data(),
+						write_msgs_.front().length()), boost::bind(
+						&chat_client::handle_write, this,
+						boost::asio::placeholders::error));
 			}
 			}
 		}
 		}
 		else
 		else
@@ -137,7 +146,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 3)
+		if (argc != 3)
 		{
 		{
 			std::cerr << "Usage: chat_client <host> <port>\n";
 			std::cerr << "Usage: chat_client <host> <port>\n";
 			return 1;
 			return 1;
@@ -151,10 +160,11 @@ int main(int argc, char* argv[])
 
 
 		chat_client c(io_service, iterator);
 		chat_client c(io_service, iterator);
 
 
-		boost::thread t(boost::bind(&boost::asio::io_service::run, &io_service));
+		boost::thread
+				t(boost::bind(&boost::asio::io_service::run, &io_service));
 
 
 		char line[chat_message::max_body_length + 1];
 		char line[chat_message::max_body_length + 1];
-		while(std::cin.getline(line, chat_message::max_body_length + 1))
+		while (std::cin.getline(line, chat_message::max_body_length + 1))
 		{
 		{
 			using namespace std;
 			using namespace std;
 			// For strlen and memcpy.
 			// For strlen and memcpy.
@@ -168,7 +178,7 @@ int main(int argc, char* argv[])
 		c.close();
 		c.close();
 		t.join();
 		t.join();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 3 - 3
src/experimental/chat/chat_message.h

@@ -27,7 +27,7 @@ public:
 		max_body_length = 512
 		max_body_length = 512
 	};
 	};
 
 
-	chat_message():
+	chat_message() :
 		body_length_(0)
 		body_length_(0)
 	{
 	{
 	}
 	}
@@ -65,7 +65,7 @@ public:
 	void body_length(size_t length)
 	void body_length(size_t length)
 	{
 	{
 		body_length_ = length;
 		body_length_ = length;
-		if(body_length_ > max_body_length)
+		if (body_length_ > max_body_length)
 			body_length_ = max_body_length;
 			body_length_ = max_body_length;
 	}
 	}
 
 
@@ -76,7 +76,7 @@ public:
 		char header[header_length + 1] = "";
 		char header[header_length + 1] = "";
 		strncat(header, data_, header_length);
 		strncat(header, data_, header_length);
 		body_length_ = atoi(header);
 		body_length_ = atoi(header);
-		if(body_length_ > max_body_length)
+		if (body_length_ > max_body_length)
 		{
 		{
 			body_length_ = 0;
 			body_length_ = 0;
 			return false;
 			return false;

+ 37 - 37
src/experimental/chat/chat_server.cc

@@ -48,7 +48,7 @@ public:
 	{
 	{
 		participants_.insert(participant);
 		participants_.insert(participant);
 		std::for_each(recent_msgs_.begin(), recent_msgs_.end(), boost::bind(
 		std::for_each(recent_msgs_.begin(), recent_msgs_.end(), boost::bind(
-		        &chat_participant::deliver, participant, _1));
+				&chat_participant::deliver, participant, _1));
 	}
 	}
 
 
 	void leave(chat_participant_ptr participant)
 	void leave(chat_participant_ptr participant)
@@ -59,11 +59,11 @@ public:
 	void deliver(const chat_message& msg)
 	void deliver(const chat_message& msg)
 	{
 	{
 		recent_msgs_.push_back(msg);
 		recent_msgs_.push_back(msg);
-		while(recent_msgs_.size() > max_recent_msgs)
+		while (recent_msgs_.size() > max_recent_msgs)
 			recent_msgs_.pop_front();
 			recent_msgs_.pop_front();
 
 
 		std::for_each(participants_.begin(), participants_.end(), boost::bind(
 		std::for_each(participants_.begin(), participants_.end(), boost::bind(
-		        &chat_participant::deliver, _1, boost::ref(msg)));
+				&chat_participant::deliver, _1, boost::ref(msg)));
 	}
 	}
 
 
 private:
 private:
@@ -78,7 +78,7 @@ private:
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------
 
 
 class chat_session: public chat_participant,
 class chat_session: public chat_participant,
-        public boost::enable_shared_from_this<chat_session>
+		public boost::enable_shared_from_this<chat_session>
 {
 {
 public:
 public:
 	chat_session(boost::asio::io_service& io_service, chat_room& room) :
 	chat_session(boost::asio::io_service& io_service, chat_room& room) :
@@ -95,33 +95,33 @@ public:
 	{
 	{
 		room_.join(shared_from_this());
 		room_.join(shared_from_this());
 		boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(),
 		boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(),
-		        chat_message::header_length), boost::bind(
-		        &chat_session::handle_read_header, shared_from_this(),
-		        boost::asio::placeholders::error));
+				chat_message::header_length), boost::bind(
+				&chat_session::handle_read_header, shared_from_this(),
+				boost::asio::placeholders::error));
 	}
 	}
 
 
 	void deliver(const chat_message& msg)
 	void deliver(const chat_message& msg)
 	{
 	{
 		bool write_in_progress = !write_msgs_.empty();
 		bool write_in_progress = !write_msgs_.empty();
 		write_msgs_.push_back(msg);
 		write_msgs_.push_back(msg);
-		if(!write_in_progress)
+		if (!write_in_progress)
 		{
 		{
 			boost::asio::async_write(socket_, boost::asio::buffer(
 			boost::asio::async_write(socket_, boost::asio::buffer(
-			        write_msgs_.front().data(), write_msgs_.front().length()),
-			        boost::bind(&chat_session::handle_write,
-			                shared_from_this(),
-			                boost::asio::placeholders::error));
+					write_msgs_.front().data(), write_msgs_.front().length()),
+					boost::bind(&chat_session::handle_write,
+							shared_from_this(),
+							boost::asio::placeholders::error));
 		}
 		}
 	}
 	}
 
 
 	void handle_read_header(const boost::system::error_code& error)
 	void handle_read_header(const boost::system::error_code& error)
 	{
 	{
-		if(!error && read_msg_.decode_header())
+		if (!error && read_msg_.decode_header())
 		{
 		{
 			boost::asio::async_read(socket_, boost::asio::buffer(
 			boost::asio::async_read(socket_, boost::asio::buffer(
-			        read_msg_.body(), read_msg_.body_length()), boost::bind(
-			        &chat_session::handle_read_body, shared_from_this(),
-			        boost::asio::placeholders::error));
+					read_msg_.body(), read_msg_.body_length()), boost::bind(
+					&chat_session::handle_read_body, shared_from_this(),
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -131,14 +131,14 @@ public:
 
 
 	void handle_read_body(const boost::system::error_code& error)
 	void handle_read_body(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			room_.deliver(read_msg_);
 			room_.deliver(read_msg_);
 			boost::asio::async_read(socket_, boost::asio::buffer(
 			boost::asio::async_read(socket_, boost::asio::buffer(
-			        read_msg_.data(), chat_message::header_length),
-			        boost::bind(&chat_session::handle_read_header,
-			                shared_from_this(),
-			                boost::asio::placeholders::error));
+					read_msg_.data(), chat_message::header_length),
+					boost::bind(&chat_session::handle_read_header,
+							shared_from_this(),
+							boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -148,16 +148,16 @@ public:
 
 
 	void handle_write(const boost::system::error_code& error)
 	void handle_write(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			write_msgs_.pop_front();
 			write_msgs_.pop_front();
-			if(!write_msgs_.empty())
+			if (!write_msgs_.empty())
 			{
 			{
 				boost::asio::async_write(socket_, boost::asio::buffer(
 				boost::asio::async_write(socket_, boost::asio::buffer(
-				        write_msgs_.front().data(),
-				        write_msgs_.front().length()), boost::bind(
-				        &chat_session::handle_write, shared_from_this(),
-				        boost::asio::placeholders::error));
+						write_msgs_.front().data(),
+						write_msgs_.front().length()), boost::bind(
+						&chat_session::handle_write, shared_from_this(),
+						boost::asio::placeholders::error));
 			}
 			}
 		}
 		}
 		else
 		else
@@ -181,25 +181,25 @@ class chat_server
 {
 {
 public:
 public:
 	chat_server(boost::asio::io_service& io_service,
 	chat_server(boost::asio::io_service& io_service,
-	        const tcp::endpoint& endpoint) :
+			const tcp::endpoint& endpoint) :
 		io_service_(io_service), acceptor_(io_service, endpoint)
 		io_service_(io_service), acceptor_(io_service, endpoint)
 	{
 	{
 		chat_session_ptr new_session(new chat_session(io_service_, room_));
 		chat_session_ptr new_session(new chat_session(io_service_, room_));
 		acceptor_.async_accept(new_session->socket(), boost::bind(
 		acceptor_.async_accept(new_session->socket(), boost::bind(
-		        &chat_server::handle_accept, this, new_session,
-		        boost::asio::placeholders::error));
+				&chat_server::handle_accept, this, new_session,
+				boost::asio::placeholders::error));
 	}
 	}
 
 
 	void handle_accept(chat_session_ptr session,
 	void handle_accept(chat_session_ptr session,
-	        const boost::system::error_code& error)
+			const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			session->start();
 			session->start();
 			chat_session_ptr new_session(new chat_session(io_service_, room_));
 			chat_session_ptr new_session(new chat_session(io_service_, room_));
 			acceptor_.async_accept(new_session->socket(), boost::bind(
 			acceptor_.async_accept(new_session->socket(), boost::bind(
-			        &chat_server::handle_accept, this, new_session,
-			        boost::asio::placeholders::error));
+					&chat_server::handle_accept, this, new_session,
+					boost::asio::placeholders::error));
 		}
 		}
 	}
 	}
 
 
@@ -218,7 +218,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc < 2)
+		if (argc < 2)
 		{
 		{
 			std::cerr << "Usage: chat_server <port> [<port> ...]\n";
 			std::cerr << "Usage: chat_server <port> [<port> ...]\n";
 			return 1;
 			return 1;
@@ -227,7 +227,7 @@ int main(int argc, char* argv[])
 		boost::asio::io_service io_service;
 		boost::asio::io_service io_service;
 
 
 		chat_server_list servers;
 		chat_server_list servers;
-		for(int i = 1; i < argc; ++i)
+		for (int i = 1; i < argc; ++i)
 		{
 		{
 			using namespace std;
 			using namespace std;
 			// For atoi.
 			// For atoi.
@@ -238,7 +238,7 @@ int main(int argc, char* argv[])
 
 
 		io_service.run();
 		io_service.run();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 47 - 47
src/experimental/chat/posix_chat_client.cc

@@ -25,58 +25,58 @@ class posix_chat_client
 {
 {
 public:
 public:
 	posix_chat_client(boost::asio::io_service& io_service,
 	posix_chat_client(boost::asio::io_service& io_service,
-	        tcp::resolver::iterator endpoint_iterator) :
+			tcp::resolver::iterator endpoint_iterator) :
 		socket_(io_service), input_(io_service, ::dup(STDIN_FILENO)), output_(
 		socket_(io_service), input_(io_service, ::dup(STDIN_FILENO)), output_(
-		        io_service, ::dup(STDOUT_FILENO)), input_buffer_(
-		        chat_message::max_body_length)
+				io_service, ::dup(STDOUT_FILENO)), input_buffer_(
+				chat_message::max_body_length)
 	{
 	{
 		// Try connecting to the first endpoint.
 		// Try connecting to the first endpoint.
 		tcp::endpoint endpoint = *endpoint_iterator;
 		tcp::endpoint endpoint = *endpoint_iterator;
 		socket_.async_connect(endpoint, boost::bind(
 		socket_.async_connect(endpoint, boost::bind(
-		        &posix_chat_client::handle_connect, this,
-		        boost::asio::placeholders::error, ++endpoint_iterator));
+				&posix_chat_client::handle_connect, this,
+				boost::asio::placeholders::error, ++endpoint_iterator));
 	}
 	}
 
 
 private:
 private:
 
 
 	void handle_connect(const boost::system::error_code& error,
 	void handle_connect(const boost::system::error_code& error,
-	        tcp::resolver::iterator endpoint_iterator)
+			tcp::resolver::iterator endpoint_iterator)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			// Read the fixed-length header of the next message from the server.
 			// Read the fixed-length header of the next message from the server.
 			boost::asio::async_read(socket_, boost::asio::buffer(
 			boost::asio::async_read(socket_, boost::asio::buffer(
-			        read_msg_.data(), chat_message::header_length),
-			        boost::bind(&posix_chat_client::handle_read_header, this,
-			                boost::asio::placeholders::error));
+					read_msg_.data(), chat_message::header_length),
+					boost::bind(&posix_chat_client::handle_read_header, this,
+							boost::asio::placeholders::error));
 
 
 
 
 			// Read a line of input entered by the user.
 			// Read a line of input entered by the user.
 			boost::asio::async_read_until(input_, input_buffer_, '\n',
 			boost::asio::async_read_until(input_, input_buffer_, '\n',
-			        boost::bind(&posix_chat_client::handle_read_input, this,
-			                boost::asio::placeholders::error,
-			                boost::asio::placeholders::bytes_transferred));
+					boost::bind(&posix_chat_client::handle_read_input, this,
+							boost::asio::placeholders::error,
+							boost::asio::placeholders::bytes_transferred));
 		}
 		}
-		else if(endpoint_iterator != tcp::resolver::iterator())
+		else if (endpoint_iterator != tcp::resolver::iterator())
 		{
 		{
 			// That endpoint didn't work, try the next one.
 			// That endpoint didn't work, try the next one.
 			socket_.close();
 			socket_.close();
 			tcp::endpoint endpoint = *endpoint_iterator;
 			tcp::endpoint endpoint = *endpoint_iterator;
 			socket_.async_connect(endpoint, boost::bind(
 			socket_.async_connect(endpoint, boost::bind(
-			        &posix_chat_client::handle_connect, this,
-			        boost::asio::placeholders::error, ++endpoint_iterator));
+					&posix_chat_client::handle_connect, this,
+					boost::asio::placeholders::error, ++endpoint_iterator));
 		}
 		}
 	}
 	}
 
 
 	void handle_read_header(const boost::system::error_code& error)
 	void handle_read_header(const boost::system::error_code& error)
 	{
 	{
-		if(!error && read_msg_.decode_header())
+		if (!error && read_msg_.decode_header())
 		{
 		{
 			// Read the variable-length body of the message from the server.
 			// Read the variable-length body of the message from the server.
 			boost::asio::async_read(socket_, boost::asio::buffer(
 			boost::asio::async_read(socket_, boost::asio::buffer(
-			        read_msg_.body(), read_msg_.body_length()), boost::bind(
-			        &posix_chat_client::handle_read_body, this,
-			        boost::asio::placeholders::error));
+					read_msg_.body(), read_msg_.body_length()), boost::bind(
+					&posix_chat_client::handle_read_body, this,
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -86,18 +86,18 @@ private:
 
 
 	void handle_read_body(const boost::system::error_code& error)
 	void handle_read_body(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			// Write out the message we just received, terminated by a newline.
 			// Write out the message we just received, terminated by a newline.
-			static char eol[] = { '\n' };
+			static char eol[] =
+			{'\n'};
 			boost::array<boost::asio::const_buffer, 2> buffers =
 			boost::array<boost::asio::const_buffer, 2> buffers =
-			        {
-			                { boost::asio::buffer(read_msg_.body(),
-			                        read_msg_.body_length()),
-			                        boost::asio::buffer(eol) } };
+			{
+			{boost::asio::buffer(read_msg_.body(), read_msg_.body_length()),
+					boost::asio::buffer(eol)}};
 			boost::asio::async_write(output_, buffers, boost::bind(
 			boost::asio::async_write(output_, buffers, boost::bind(
-			        &posix_chat_client::handle_write_output, this,
-			        boost::asio::placeholders::error));
+					&posix_chat_client::handle_write_output, this,
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -107,13 +107,13 @@ private:
 
 
 	void handle_write_output(const boost::system::error_code& error)
 	void handle_write_output(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			// Read the fixed-length header of the next message from the server.
 			// Read the fixed-length header of the next message from the server.
 			boost::asio::async_read(socket_, boost::asio::buffer(
 			boost::asio::async_read(socket_, boost::asio::buffer(
-			        read_msg_.data(), chat_message::header_length),
-			        boost::bind(&posix_chat_client::handle_read_header, this,
-			                boost::asio::placeholders::error));
+					read_msg_.data(), chat_message::header_length),
+					boost::bind(&posix_chat_client::handle_read_header, this,
+							boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -122,9 +122,9 @@ private:
 	}
 	}
 
 
 	void handle_read_input(const boost::system::error_code& error,
 	void handle_read_input(const boost::system::error_code& error,
-	        std::size_t length)
+			std::size_t length)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			// Write the message (minus the newline) to the server.
 			// Write the message (minus the newline) to the server.
 			write_msg_.body_length(length - 1);
 			write_msg_.body_length(length - 1);
@@ -132,20 +132,20 @@ private:
 			input_buffer_.consume(1); // Remove newline from input.
 			input_buffer_.consume(1); // Remove newline from input.
 			write_msg_.encode_header();
 			write_msg_.encode_header();
 			boost::asio::async_write(socket_, boost::asio::buffer(
 			boost::asio::async_write(socket_, boost::asio::buffer(
-			        write_msg_.data(), write_msg_.length()), boost::bind(
-			        &posix_chat_client::handle_write, this,
-			        boost::asio::placeholders::error));
+					write_msg_.data(), write_msg_.length()), boost::bind(
+					&posix_chat_client::handle_write, this,
+					boost::asio::placeholders::error));
 		}
 		}
-		else if(error == boost::asio::error::not_found)
+		else if (error == boost::asio::error::not_found)
 		{
 		{
 			// Didn't get a newline. Send whatever we have.
 			// Didn't get a newline. Send whatever we have.
 			write_msg_.body_length(input_buffer_.size());
 			write_msg_.body_length(input_buffer_.size());
 			input_buffer_.sgetn(write_msg_.body(), input_buffer_.size());
 			input_buffer_.sgetn(write_msg_.body(), input_buffer_.size());
 			write_msg_.encode_header();
 			write_msg_.encode_header();
 			boost::asio::async_write(socket_, boost::asio::buffer(
 			boost::asio::async_write(socket_, boost::asio::buffer(
-			        write_msg_.data(), write_msg_.length()), boost::bind(
-			        &posix_chat_client::handle_write, this,
-			        boost::asio::placeholders::error));
+					write_msg_.data(), write_msg_.length()), boost::bind(
+					&posix_chat_client::handle_write, this,
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -155,13 +155,13 @@ private:
 
 
 	void handle_write(const boost::system::error_code& error)
 	void handle_write(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			// Read a line of input entered by the user.
 			// Read a line of input entered by the user.
 			boost::asio::async_read_until(input_, input_buffer_, '\n',
 			boost::asio::async_read_until(input_, input_buffer_, '\n',
-			        boost::bind(&posix_chat_client::handle_read_input, this,
-			                boost::asio::placeholders::error,
-			                boost::asio::placeholders::bytes_transferred));
+					boost::bind(&posix_chat_client::handle_read_input, this,
+							boost::asio::placeholders::error,
+							boost::asio::placeholders::bytes_transferred));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -190,7 +190,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 3)
+		if (argc != 3)
 		{
 		{
 			std::cerr << "Usage: posix_chat_client <host> <port>\n";
 			std::cerr << "Usage: posix_chat_client <host> <port>\n";
 			return 1;
 			return 1;
@@ -206,7 +206,7 @@ int main(int argc, char* argv[])
 
 
 		io_service.run();
 		io_service.run();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 20 - 20
src/experimental/echo/async_tcp_echo_server.cc

@@ -31,19 +31,19 @@ public:
 	void start()
 	void start()
 	{
 	{
 		socket_.async_read_some(boost::asio::buffer(data_, max_length),
 		socket_.async_read_some(boost::asio::buffer(data_, max_length),
-		        boost::bind(&session::handle_read, this,
-		                boost::asio::placeholders::error,
-		                boost::asio::placeholders::bytes_transferred));
+				boost::bind(&session::handle_read, this,
+						boost::asio::placeholders::error,
+						boost::asio::placeholders::bytes_transferred));
 	}
 	}
 
 
 	void handle_read(const boost::system::error_code& error,
 	void handle_read(const boost::system::error_code& error,
-	        size_t bytes_transferred)
+			size_t bytes_transferred)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			boost::asio::async_write(socket_, boost::asio::buffer(data_,
 			boost::asio::async_write(socket_, boost::asio::buffer(data_,
-			        bytes_transferred), boost::bind(&session::handle_write,
-			        this, boost::asio::placeholders::error));
+					bytes_transferred), boost::bind(&session::handle_write,
+					this, boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -53,12 +53,12 @@ public:
 
 
 	void handle_write(const boost::system::error_code& error)
 	void handle_write(const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			socket_.async_read_some(boost::asio::buffer(data_, max_length),
 			socket_.async_read_some(boost::asio::buffer(data_, max_length),
-			        boost::bind(&session::handle_read, this,
-			                boost::asio::placeholders::error,
-			                boost::asio::placeholders::bytes_transferred));
+					boost::bind(&session::handle_read, this,
+							boost::asio::placeholders::error,
+							boost::asio::placeholders::bytes_transferred));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -80,24 +80,24 @@ class server
 public:
 public:
 	server(boost::asio::io_service& io_service, short port) :
 	server(boost::asio::io_service& io_service, short port) :
 		io_service_(io_service), acceptor_(io_service, tcp::endpoint(tcp::v4(),
 		io_service_(io_service), acceptor_(io_service, tcp::endpoint(tcp::v4(),
-		        port))
+				port))
 	{
 	{
 		session* new_session = new session(io_service_);
 		session* new_session = new session(io_service_);
 		acceptor_.async_accept(new_session->socket(), boost::bind(
 		acceptor_.async_accept(new_session->socket(), boost::bind(
-		        &server::handle_accept, this, new_session,
-		        boost::asio::placeholders::error));
+				&server::handle_accept, this, new_session,
+				boost::asio::placeholders::error));
 	}
 	}
 
 
 	void handle_accept(session* new_session,
 	void handle_accept(session* new_session,
-	        const boost::system::error_code& error)
+			const boost::system::error_code& error)
 	{
 	{
-		if(!error)
+		if (!error)
 		{
 		{
 			new_session->start();
 			new_session->start();
 			new_session = new session(io_service_);
 			new_session = new session(io_service_);
 			acceptor_.async_accept(new_session->socket(), boost::bind(
 			acceptor_.async_accept(new_session->socket(), boost::bind(
-			        &server::handle_accept, this, new_session,
-			        boost::asio::placeholders::error));
+					&server::handle_accept, this, new_session,
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -114,7 +114,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 2)
+		if (argc != 2)
 		{
 		{
 			std::cerr << "Usage: async_tcp_echo_server <port>\n";
 			std::cerr << "Usage: async_tcp_echo_server <port>\n";
 			return 1;
 			return 1;
@@ -128,7 +128,7 @@ int main(int argc, char* argv[])
 
 
 		io_service.run();
 		io_service.run();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 17 - 17
src/experimental/echo/async_udp_echo_server.cc

@@ -20,39 +20,39 @@ class server
 public:
 public:
 	server(boost::asio::io_service& io_service, short port) :
 	server(boost::asio::io_service& io_service, short port) :
 		io_service_(io_service), socket_(io_service, udp::endpoint(udp::v4(),
 		io_service_(io_service), socket_(io_service, udp::endpoint(udp::v4(),
-		        port))
+				port))
 	{
 	{
 		socket_.async_receive_from(boost::asio::buffer(data_, max_length),
 		socket_.async_receive_from(boost::asio::buffer(data_, max_length),
-		        sender_endpoint_, boost::bind(&server::handle_receive_from,
-		                this, boost::asio::placeholders::error,
-		                boost::asio::placeholders::bytes_transferred));
+				sender_endpoint_, boost::bind(&server::handle_receive_from,
+						this, boost::asio::placeholders::error,
+						boost::asio::placeholders::bytes_transferred));
 	}
 	}
 
 
 	void handle_receive_from(const boost::system::error_code& error,
 	void handle_receive_from(const boost::system::error_code& error,
-	        size_t bytes_recvd)
+			size_t bytes_recvd)
 	{
 	{
-		if(!error && bytes_recvd > 0)
+		if (!error && bytes_recvd > 0)
 		{
 		{
 			socket_.async_send_to(boost::asio::buffer(data_, bytes_recvd),
 			socket_.async_send_to(boost::asio::buffer(data_, bytes_recvd),
-			        sender_endpoint_, boost::bind(&server::handle_send_to,
-			                this, boost::asio::placeholders::error,
-			                boost::asio::placeholders::bytes_transferred));
+					sender_endpoint_, boost::bind(&server::handle_send_to,
+							this, boost::asio::placeholders::error,
+							boost::asio::placeholders::bytes_transferred));
 		}
 		}
 		else
 		else
 		{
 		{
 			socket_.async_receive_from(boost::asio::buffer(data_, max_length),
 			socket_.async_receive_from(boost::asio::buffer(data_, max_length),
-			        sender_endpoint_, boost::bind(&server::handle_receive_from,
-			                this, boost::asio::placeholders::error,
-			                boost::asio::placeholders::bytes_transferred));
+					sender_endpoint_, boost::bind(&server::handle_receive_from,
+							this, boost::asio::placeholders::error,
+							boost::asio::placeholders::bytes_transferred));
 		}
 		}
 	}
 	}
 
 
 	void handle_send_to(const boost::system::error_code& /*error*/, size_t /*bytes_sent*/)
 	void handle_send_to(const boost::system::error_code& /*error*/, size_t /*bytes_sent*/)
 	{
 	{
 		socket_.async_receive_from(boost::asio::buffer(data_, max_length),
 		socket_.async_receive_from(boost::asio::buffer(data_, max_length),
-		        sender_endpoint_, boost::bind(&server::handle_receive_from,
-		                this, boost::asio::placeholders::error,
-		                boost::asio::placeholders::bytes_transferred));
+				sender_endpoint_, boost::bind(&server::handle_receive_from,
+						this, boost::asio::placeholders::error,
+						boost::asio::placeholders::bytes_transferred));
 	}
 	}
 
 
 private:
 private:
@@ -70,7 +70,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 2)
+		if (argc != 2)
 		{
 		{
 			std::cerr << "Usage: async_udp_echo_server <port>\n";
 			std::cerr << "Usage: async_udp_echo_server <port>\n";
 			return 1;
 			return 1;
@@ -84,7 +84,7 @@ int main(int argc, char* argv[])
 
 
 		io_service.run();
 		io_service.run();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 3 - 3
src/experimental/echo/blocking_tcp_echo_client.cc

@@ -24,7 +24,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 3)
+		if (argc != 3)
 		{
 		{
 			std::cerr << "Usage: blocking_tcp_echo_client <host> <port>\n";
 			std::cerr << "Usage: blocking_tcp_echo_client <host> <port>\n";
 			return 1;
 			return 1;
@@ -49,12 +49,12 @@ int main(int argc, char* argv[])
 
 
 		char reply[max_length];
 		char reply[max_length];
 		size_t reply_length = boost::asio::read(s, boost::asio::buffer(reply,
 		size_t reply_length = boost::asio::read(s, boost::asio::buffer(reply,
-		        request_length));
+				request_length));
 		std::cout << "Reply is: ";
 		std::cout << "Reply is: ";
 		std::cout.write(reply, reply_length);
 		std::cout.write(reply, reply_length);
 		std::cout << "\n";
 		std::cout << "\n";
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 7 - 7
src/experimental/echo/blocking_tcp_echo_server.cc

@@ -25,21 +25,21 @@ void session(socket_ptr sock)
 {
 {
 	try
 	try
 	{
 	{
-		for(;;)
+		for (;;)
 		{
 		{
 			char data[max_length];
 			char data[max_length];
 
 
 			boost::system::error_code error;
 			boost::system::error_code error;
 			size_t length = sock->read_some(boost::asio::buffer(data), error);
 			size_t length = sock->read_some(boost::asio::buffer(data), error);
-			if(error == boost::asio::error::eof)
+			if (error == boost::asio::error::eof)
 				break; // Connection closed cleanly by peer.
 				break; // Connection closed cleanly by peer.
-			else if(error)
+			else if (error)
 				throw boost::system::system_error(error); // Some other error.
 				throw boost::system::system_error(error); // Some other error.
 
 
 			boost::asio::write(*sock, boost::asio::buffer(data, length));
 			boost::asio::write(*sock, boost::asio::buffer(data, length));
 		}
 		}
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception in thread: " << e.what() << "\n";
 		std::cerr << "Exception in thread: " << e.what() << "\n";
 	}
 	}
@@ -48,7 +48,7 @@ void session(socket_ptr sock)
 void server(boost::asio::io_service& io_service, short port)
 void server(boost::asio::io_service& io_service, short port)
 {
 {
 	tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
 	tcp::acceptor a(io_service, tcp::endpoint(tcp::v4(), port));
-	for(;;)
+	for (;;)
 	{
 	{
 		socket_ptr sock(new tcp::socket(io_service));
 		socket_ptr sock(new tcp::socket(io_service));
 		a.accept(*sock);
 		a.accept(*sock);
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 2)
+		if (argc != 2)
 		{
 		{
 			std::cerr << "Usage: blocking_tcp_echo_server <port>\n";
 			std::cerr << "Usage: blocking_tcp_echo_server <port>\n";
 			return 1;
 			return 1;
@@ -72,7 +72,7 @@ int main(int argc, char* argv[])
 		// For atoi.
 		// For atoi.
 		server(io_service, atoi(argv[1]));
 		server(io_service, atoi(argv[1]));
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
 	}
 	}

+ 35 - 35
src/experimental/http_client/async_client.cc

@@ -21,7 +21,7 @@ class client
 {
 {
 public:
 public:
 	client(boost::asio::io_service& io_service, const std::string& server,
 	client(boost::asio::io_service& io_service, const std::string& server,
-	        const std::string& path) :
+			const std::string& path) :
 		resolver_(io_service), socket_(io_service)
 		resolver_(io_service), socket_(io_service)
 	{
 	{
 		// Form the request. We specify the "Connection: close" header so that the
 		// Form the request. We specify the "Connection: close" header so that the
@@ -38,22 +38,22 @@ public:
 		// into a list of endpoints.
 		// into a list of endpoints.
 		tcp::resolver::query query(server, "http");
 		tcp::resolver::query query(server, "http");
 		resolver_.async_resolve(query, boost::bind(&client::handle_resolve,
 		resolver_.async_resolve(query, boost::bind(&client::handle_resolve,
-		        this, boost::asio::placeholders::error,
-		        boost::asio::placeholders::iterator));
+				this, boost::asio::placeholders::error,
+				boost::asio::placeholders::iterator));
 	}
 	}
 
 
 private:
 private:
 	void handle_resolve(const boost::system::error_code& err,
 	void handle_resolve(const boost::system::error_code& err,
-	        tcp::resolver::iterator endpoint_iterator)
+			tcp::resolver::iterator endpoint_iterator)
 	{
 	{
-		if(!err)
+		if (!err)
 		{
 		{
 			// Attempt a connection to the first endpoint in the list. Each endpoint
 			// Attempt a connection to the first endpoint in the list. Each endpoint
 			// will be tried until we successfully establish a connection.
 			// will be tried until we successfully establish a connection.
 			tcp::endpoint endpoint = *endpoint_iterator;
 			tcp::endpoint endpoint = *endpoint_iterator;
 			socket_.async_connect(endpoint, boost::bind(
 			socket_.async_connect(endpoint, boost::bind(
-			        &client::handle_connect, this,
-			        boost::asio::placeholders::error, ++endpoint_iterator));
+					&client::handle_connect, this,
+					boost::asio::placeholders::error, ++endpoint_iterator));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -62,23 +62,23 @@ private:
 	}
 	}
 
 
 	void handle_connect(const boost::system::error_code& err,
 	void handle_connect(const boost::system::error_code& err,
-	        tcp::resolver::iterator endpoint_iterator)
+			tcp::resolver::iterator endpoint_iterator)
 	{
 	{
-		if(!err)
+		if (!err)
 		{
 		{
 			// The connection was successful. Send the request.
 			// The connection was successful. Send the request.
 			boost::asio::async_write(socket_, request_, boost::bind(
 			boost::asio::async_write(socket_, request_, boost::bind(
-			        &client::handle_write_request, this,
-			        boost::asio::placeholders::error));
+					&client::handle_write_request, this,
+					boost::asio::placeholders::error));
 		}
 		}
-		else if(endpoint_iterator != tcp::resolver::iterator())
+		else if (endpoint_iterator != tcp::resolver::iterator())
 		{
 		{
 			// The connection failed. Try the next endpoint in the list.
 			// The connection failed. Try the next endpoint in the list.
 			socket_.close();
 			socket_.close();
 			tcp::endpoint endpoint = *endpoint_iterator;
 			tcp::endpoint endpoint = *endpoint_iterator;
 			socket_.async_connect(endpoint, boost::bind(
 			socket_.async_connect(endpoint, boost::bind(
-			        &client::handle_connect, this,
-			        boost::asio::placeholders::error, ++endpoint_iterator));
+					&client::handle_connect, this,
+					boost::asio::placeholders::error, ++endpoint_iterator));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -88,12 +88,12 @@ private:
 
 
 	void handle_write_request(const boost::system::error_code& err)
 	void handle_write_request(const boost::system::error_code& err)
 	{
 	{
-		if(!err)
+		if (!err)
 		{
 		{
 			// Read the response status line.
 			// Read the response status line.
 			boost::asio::async_read_until(socket_, response_, "\r\n",
 			boost::asio::async_read_until(socket_, response_, "\r\n",
-			        boost::bind(&client::handle_read_status_line, this,
-			                boost::asio::placeholders::error));
+					boost::bind(&client::handle_read_status_line, this,
+							boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -103,7 +103,7 @@ private:
 
 
 	void handle_read_status_line(const boost::system::error_code& err)
 	void handle_read_status_line(const boost::system::error_code& err)
 	{
 	{
-		if(!err)
+		if (!err)
 		{
 		{
 			// Check that response is OK.
 			// Check that response is OK.
 			std::istream response_stream(&response_);
 			std::istream response_stream(&response_);
@@ -113,12 +113,12 @@ private:
 			response_stream >> status_code;
 			response_stream >> status_code;
 			std::string status_message;
 			std::string status_message;
 			std::getline(response_stream, status_message);
 			std::getline(response_stream, status_message);
-			if(!response_stream || http_version.substr(0, 5) != "HTTP/")
+			if (!response_stream || http_version.substr(0, 5) != "HTTP/")
 			{
 			{
 				std::cout << "Invalid response\n";
 				std::cout << "Invalid response\n";
 				return;
 				return;
 			}
 			}
-			if(status_code != 200)
+			if (status_code != 200)
 			{
 			{
 				std::cout << "Response returned with status code ";
 				std::cout << "Response returned with status code ";
 				std::cout << status_code << "\n";
 				std::cout << status_code << "\n";
@@ -128,8 +128,8 @@ private:
 
 
 			// Read the response headers, which are terminated by a blank line.
 			// Read the response headers, which are terminated by a blank line.
 			boost::asio::async_read_until(socket_, response_, "\r\n\r\n",
 			boost::asio::async_read_until(socket_, response_, "\r\n\r\n",
-			        boost::bind(&client::handle_read_headers, this,
-			                boost::asio::placeholders::error));
+					boost::bind(&client::handle_read_headers, this,
+							boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -139,26 +139,26 @@ private:
 
 
 	void handle_read_headers(const boost::system::error_code& err)
 	void handle_read_headers(const boost::system::error_code& err)
 	{
 	{
-		if(!err)
+		if (!err)
 		{
 		{
 			// Process the response headers.
 			// Process the response headers.
 			std::istream response_stream(&response_);
 			std::istream response_stream(&response_);
 			std::string header;
 			std::string header;
-			while(std::getline(response_stream, header) && header != "\r")
+			while (std::getline(response_stream, header) && header != "\r")
 				std::cout << header << "\n";
 				std::cout << header << "\n";
 			std::cout << "\n";
 			std::cout << "\n";
 
 
 
 
 			// Write whatever content we already have to output.
 			// Write whatever content we already have to output.
-			if(response_.size() > 0)
+			if (response_.size() > 0)
 				std::cout << &response_;
 				std::cout << &response_;
 
 
 
 
 			// Start reading remaining data until EOF.
 			// Start reading remaining data until EOF.
 			boost::asio::async_read(socket_, response_,
 			boost::asio::async_read(socket_, response_,
-			        boost::asio::transfer_at_least(1), boost::bind(
-			                &client::handle_read_content, this,
-			                boost::asio::placeholders::error));
+					boost::asio::transfer_at_least(1), boost::bind(
+							&client::handle_read_content, this,
+							boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
@@ -168,7 +168,7 @@ private:
 
 
 	void handle_read_content(const boost::system::error_code& err)
 	void handle_read_content(const boost::system::error_code& err)
 	{
 	{
-		if(!err)
+		if (!err)
 		{
 		{
 			// Write all of the data that has been read so far.
 			// Write all of the data that has been read so far.
 			std::cout << &response_;
 			std::cout << &response_;
@@ -176,11 +176,11 @@ private:
 
 
 			// Continue reading remaining data until EOF.
 			// Continue reading remaining data until EOF.
 			boost::asio::async_read(socket_, response_,
 			boost::asio::async_read(socket_, response_,
-			        boost::asio::transfer_at_least(1), boost::bind(
-			                &client::handle_read_content, this,
-			                boost::asio::placeholders::error));
+					boost::asio::transfer_at_least(1), boost::bind(
+							&client::handle_read_content, this,
+							boost::asio::placeholders::error));
 		}
 		}
-		else if(err != boost::asio::error::eof)
+		else if (err != boost::asio::error::eof)
 		{
 		{
 			std::cout << "Error: " << err << "\n";
 			std::cout << "Error: " << err << "\n";
 		}
 		}
@@ -196,7 +196,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 3)
+		if (argc != 3)
 		{
 		{
 			std::cout << "Usage: async_client <server> <path>\n";
 			std::cout << "Usage: async_client <server> <path>\n";
 			std::cout << "Example:\n";
 			std::cout << "Example:\n";
@@ -208,7 +208,7 @@ int main(int argc, char* argv[])
 		client c(io_service, argv[1], argv[2]);
 		client c(io_service, argv[1], argv[2]);
 		io_service.run();
 		io_service.run();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cout << "Exception: " << e.what() << "\n";
 		std::cout << "Exception: " << e.what() << "\n";
 	}
 	}

+ 12 - 12
src/experimental/http_client/sync_client.cc

@@ -20,7 +20,7 @@ int main(int argc, char* argv[])
 {
 {
 	try
 	try
 	{
 	{
-		if(argc != 3)
+		if (argc != 3)
 		{
 		{
 			std::cout << "Usage: sync_client <server> <path>\n";
 			std::cout << "Usage: sync_client <server> <path>\n";
 			std::cout << "Example:\n";
 			std::cout << "Example:\n";
@@ -41,12 +41,12 @@ int main(int argc, char* argv[])
 		// Try each endpoint until we successfully establish a connection.
 		// Try each endpoint until we successfully establish a connection.
 		tcp::socket socket(io_service);
 		tcp::socket socket(io_service);
 		boost::system::error_code error = boost::asio::error::host_not_found;
 		boost::system::error_code error = boost::asio::error::host_not_found;
-		while(error && endpoint_iterator != end)
+		while (error && endpoint_iterator != end)
 		{
 		{
 			socket.close();
 			socket.close();
 			socket.connect(*endpoint_iterator++, error);
 			socket.connect(*endpoint_iterator++, error);
 		}
 		}
-		if(error)
+		if (error)
 			throw boost::system::system_error(error);
 			throw boost::system::system_error(error);
 
 
 
 
@@ -78,15 +78,15 @@ int main(int argc, char* argv[])
 		response_stream >> status_code;
 		response_stream >> status_code;
 		std::string status_message;
 		std::string status_message;
 		std::getline(response_stream, status_message);
 		std::getline(response_stream, status_message);
-		if(!response_stream || http_version.substr(0, 5) != "HTTP/")
+		if (!response_stream || http_version.substr(0, 5) != "HTTP/")
 		{
 		{
 			std::cout << "Invalid response\n";
 			std::cout << "Invalid response\n";
 			return 1;
 			return 1;
 		}
 		}
-		if(status_code != 200)
+		if (status_code != 200)
 		{
 		{
 			std::cout << "Response returned with status code " << status_code
 			std::cout << "Response returned with status code " << status_code
-			        << "\n";
+					<< "\n";
 			return 1;
 			return 1;
 		}
 		}
 
 
@@ -96,24 +96,24 @@ int main(int argc, char* argv[])
 
 
 		// Process the response headers.
 		// Process the response headers.
 		std::string header;
 		std::string header;
-		while(std::getline(response_stream, header) && header != "\r")
+		while (std::getline(response_stream, header) && header != "\r")
 			std::cout << header << "\n";
 			std::cout << header << "\n";
 		std::cout << "\n";
 		std::cout << "\n";
 
 
 
 
 		// Write whatever content we already have to output.
 		// Write whatever content we already have to output.
-		if(response.size() > 0)
+		if (response.size() > 0)
 			std::cout << &response;
 			std::cout << &response;
 
 
 
 
 		// Read until EOF, writing data to output as we go.
 		// Read until EOF, writing data to output as we go.
-		while(boost::asio::read(socket, response,
-		        boost::asio::transfer_at_least(1), error))
+		while (boost::asio::read(socket, response,
+				boost::asio::transfer_at_least(1), error))
 			std::cout << &response;
 			std::cout << &response;
-		if(error != boost::asio::error::eof)
+		if (error != boost::asio::error::eof)
 			throw boost::system::system_error(error);
 			throw boost::system::system_error(error);
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cout << "Exception: " << e.what() << "\n";
 		std::cout << "Exception: " << e.what() << "\n";
 	}
 	}

+ 21 - 21
src/experimental/http_server/connection.cc

@@ -17,9 +17,9 @@
 namespace http_server {
 namespace http_server {
 
 
 connection::connection(boost::asio::io_service& io_service,
 connection::connection(boost::asio::io_service& io_service,
-        connection_manager& manager, request_handler& handler) :
+		connection_manager& manager, request_handler& handler) :
 	socket_(io_service), connection_manager_(manager),
 	socket_(io_service), connection_manager_(manager),
-	        request_handler_(handler)
+			request_handler_(handler)
 {
 {
 }
 }
 
 
@@ -31,9 +31,9 @@ boost::asio::ip::tcp::socket& connection::socket()
 void connection::start()
 void connection::start()
 {
 {
 	socket_.async_read_some(boost::asio::buffer(buffer_), boost::bind(
 	socket_.async_read_some(boost::asio::buffer(buffer_), boost::bind(
-	        &connection::handle_read, shared_from_this(),
-	        boost::asio::placeholders::error,
-	        boost::asio::placeholders::bytes_transferred));
+			&connection::handle_read, shared_from_this(),
+			boost::asio::placeholders::error,
+			boost::asio::placeholders::bytes_transferred));
 }
 }
 
 
 void connection::stop()
 void connection::stop()
@@ -42,37 +42,37 @@ void connection::stop()
 }
 }
 
 
 void connection::handle_read(const boost::system::error_code& e,
 void connection::handle_read(const boost::system::error_code& e,
-        std::size_t bytes_transferred)
+		std::size_t bytes_transferred)
 {
 {
-	if(!e)
+	if (!e)
 	{
 	{
 		boost::tribool result;
 		boost::tribool result;
 		boost::tie(result, boost::tuples::ignore) = request_parser_.parse(
 		boost::tie(result, boost::tuples::ignore) = request_parser_.parse(
-		        request_, buffer_.data(), buffer_.data() + bytes_transferred);
+				request_, buffer_.data(), buffer_.data() + bytes_transferred);
 
 
-		if(result)
+		if (result)
 		{
 		{
 			request_handler_.handle_request(request_, reply_);
 			request_handler_.handle_request(request_, reply_);
 			boost::asio::async_write(socket_, reply_.to_buffers(), boost::bind(
 			boost::asio::async_write(socket_, reply_.to_buffers(), boost::bind(
-			        &connection::handle_write, shared_from_this(),
-			        boost::asio::placeholders::error));
+					&connection::handle_write, shared_from_this(),
+					boost::asio::placeholders::error));
 		}
 		}
-		else if(!result)
+		else if (!result)
 		{
 		{
 			reply_ = reply::stock_reply(reply::bad_request);
 			reply_ = reply::stock_reply(reply::bad_request);
 			boost::asio::async_write(socket_, reply_.to_buffers(), boost::bind(
 			boost::asio::async_write(socket_, reply_.to_buffers(), boost::bind(
-			        &connection::handle_write, shared_from_this(),
-			        boost::asio::placeholders::error));
+					&connection::handle_write, shared_from_this(),
+					boost::asio::placeholders::error));
 		}
 		}
 		else
 		else
 		{
 		{
 			socket_.async_read_some(boost::asio::buffer(buffer_), boost::bind(
 			socket_.async_read_some(boost::asio::buffer(buffer_), boost::bind(
-			        &connection::handle_read, shared_from_this(),
-			        boost::asio::placeholders::error,
-			        boost::asio::placeholders::bytes_transferred));
+					&connection::handle_read, shared_from_this(),
+					boost::asio::placeholders::error,
+					boost::asio::placeholders::bytes_transferred));
 		}
 		}
 	}
 	}
-	else if(e != boost::asio::error::operation_aborted)
+	else if (e != boost::asio::error::operation_aborted)
 	{
 	{
 		connection_manager_.stop(shared_from_this());
 		connection_manager_.stop(shared_from_this());
 	}
 	}
@@ -80,15 +80,15 @@ void connection::handle_read(const boost::system::error_code& e,
 
 
 void connection::handle_write(const boost::system::error_code& e)
 void connection::handle_write(const boost::system::error_code& e)
 {
 {
-	if(!e)
+	if (!e)
 	{
 	{
 		// Initiate graceful connection closure.
 		// Initiate graceful connection closure.
 		boost::system::error_code ignored_ec;
 		boost::system::error_code ignored_ec;
 		socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both,
 		socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both,
-		        ignored_ec);
+				ignored_ec);
 	}
 	}
 
 
-	if(e != boost::asio::error::operation_aborted)
+	if (e != boost::asio::error::operation_aborted)
 	{
 	{
 		connection_manager_.stop(shared_from_this());
 		connection_manager_.stop(shared_from_this());
 	}
 	}

+ 1 - 1
src/experimental/http_server/connection_manager.cc

@@ -29,7 +29,7 @@ void connection_manager::stop(connection_ptr c)
 void connection_manager::stop_all()
 void connection_manager::stop_all()
 {
 {
 	std::for_each(connections_.begin(), connections_.end(), boost::bind(
 	std::for_each(connections_.begin(), connections_.end(), boost::bind(
-	        &connection::stop, _1));
+			&connection::stop, _1));
 	connections_.clear();
 	connections_.clear();
 }
 }
 
 

+ 10 - 5
src/experimental/http_server/mime_types.cc

@@ -17,16 +17,21 @@ struct mapping
 {
 {
 	const char* extension;
 	const char* extension;
 	const char* mime_type;
 	const char* mime_type;
-} mappings[] = { { "gif", "image/gif" }, { "htm", "text/html" }, { "html",
-        "text/html" }, { "jpg", "image/jpeg" }, { "png", "image/png" },
-        { 0, 0 } // Marks end of list.
+} mappings[] =
+{
+	{"gif", "image/gif"},
+	{"htm", "text/html"},
+	{"html", "text/html"},
+	{"jpg", "image/jpeg"},
+	{"png", "image/png"},
+	{0, 0} // Marks end of list.
 };
 };
 
 
 std::string extension_to_type(const std::string& extension)
 std::string extension_to_type(const std::string& extension)
 {
 {
-	for(mapping* m = mappings; m->extension; ++m)
+	for (mapping* m = mappings; m->extension; ++m)
 	{
 	{
-		if(m->extension == extension)
+		if (m->extension == extension)
 		{
 		{
 			return m->mime_type;
 			return m->mime_type;
 		}
 		}

+ 2 - 2
src/experimental/http_server/posix_main.cc

@@ -23,7 +23,7 @@ int main(int argc, char* argv[])
 	try
 	try
 	{
 	{
 		// Check command line arguments.
 		// Check command line arguments.
-		if(argc != 4)
+		if (argc != 4)
 		{
 		{
 			std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
 			std::cerr << "Usage: http_server <address> <port> <doc_root>\n";
 			std::cerr << "  For IPv4, try:\n";
 			std::cerr << "  For IPv4, try:\n";
@@ -64,7 +64,7 @@ int main(int argc, char* argv[])
 		s.stop();
 		s.stop();
 		t.join();
 		t.join();
 	}
 	}
-	catch(std::exception& e)
+	catch (std::exception& e)
 	{
 	{
 		std::cerr << "exception: " << e.what() << "\n";
 		std::cerr << "exception: " << e.what() << "\n";
 	}
 	}

+ 10 - 8
src/experimental/http_server/reply.cc

@@ -29,14 +29,14 @@ const std::string unauthorized = "HTTP/1.0 401 Unauthorized\r\n";
 const std::string forbidden = "HTTP/1.0 403 Forbidden\r\n";
 const std::string forbidden = "HTTP/1.0 403 Forbidden\r\n";
 const std::string not_found = "HTTP/1.0 404 Not Found\r\n";
 const std::string not_found = "HTTP/1.0 404 Not Found\r\n";
 const std::string internal_server_error =
 const std::string internal_server_error =
-        "HTTP/1.0 500 Internal Server Error\r\n";
+		"HTTP/1.0 500 Internal Server Error\r\n";
 const std::string not_implemented = "HTTP/1.0 501 Not Implemented\r\n";
 const std::string not_implemented = "HTTP/1.0 501 Not Implemented\r\n";
 const std::string bad_gateway = "HTTP/1.0 502 Bad Gateway\r\n";
 const std::string bad_gateway = "HTTP/1.0 502 Bad Gateway\r\n";
 const std::string service_unavailable = "HTTP/1.0 503 Service Unavailable\r\n";
 const std::string service_unavailable = "HTTP/1.0 503 Service Unavailable\r\n";
 
 
 boost::asio::const_buffer to_buffer(reply::status_type status)
 boost::asio::const_buffer to_buffer(reply::status_type status)
 {
 {
-	switch(status)
+	switch (status)
 	{
 	{
 		case reply::ok:
 		case reply::ok:
 			return boost::asio::buffer(ok);
 			return boost::asio::buffer(ok);
@@ -79,21 +79,23 @@ boost::asio::const_buffer to_buffer(reply::status_type status)
 
 
 namespace misc_strings {
 namespace misc_strings {
 
 
-const char name_value_separator[] = { ':', ' ' };
-const char crlf[] = { '\r', '\n' };
+const char name_value_separator[] =
+{':', ' '};
+const char crlf[] =
+{'\r', '\n'};
 
 
 } // namespace misc_strings
 } // namespace misc_strings
 
 
 std::vector<boost::asio::const_buffer> reply::to_buffers()
 std::vector<boost::asio::const_buffer> reply::to_buffers()
 {
 {
-	std::vector < boost::asio::const_buffer > buffers;
+	std::vector<boost::asio::const_buffer> buffers;
 	buffers.push_back(status_strings::to_buffer(status));
 	buffers.push_back(status_strings::to_buffer(status));
-	for(std::size_t i = 0; i < headers.size(); ++i)
+	for (std::size_t i = 0; i < headers.size(); ++i)
 	{
 	{
 		header& h = headers[i];
 		header& h = headers[i];
 		buffers.push_back(boost::asio::buffer(h.name));
 		buffers.push_back(boost::asio::buffer(h.name));
 		buffers.push_back(boost::asio::buffer(
 		buffers.push_back(boost::asio::buffer(
-		        misc_strings::name_value_separator));
+				misc_strings::name_value_separator));
 		buffers.push_back(boost::asio::buffer(h.value));
 		buffers.push_back(boost::asio::buffer(h.value));
 		buffers.push_back(boost::asio::buffer(misc_strings::crlf));
 		buffers.push_back(boost::asio::buffer(misc_strings::crlf));
 	}
 	}
@@ -168,7 +170,7 @@ const char service_unavailable[] = "<html>"
 
 
 std::string to_string(reply::status_type status)
 std::string to_string(reply::status_type status)
 {
 {
-	switch(status)
+	switch (status)
 	{
 	{
 		case reply::ok:
 		case reply::ok:
 			return ok;
 			return ok;

+ 12 - 12
src/experimental/http_server/request_handler.cc

@@ -28,22 +28,22 @@ void request_handler::handle_request(const request& req, reply& rep)
 {
 {
 	// Decode url to path.
 	// Decode url to path.
 	std::string request_path;
 	std::string request_path;
-	if(!url_decode(req.uri, request_path))
+	if (!url_decode(req.uri, request_path))
 	{
 	{
 		rep = reply::stock_reply(reply::bad_request);
 		rep = reply::stock_reply(reply::bad_request);
 		return;
 		return;
 	}
 	}
 
 
 	// Request path must be absolute and not contain "..".
 	// Request path must be absolute and not contain "..".
-	if(request_path.empty() || request_path[0] != '/'
-	        || request_path.find("..") != std::string::npos)
+	if (request_path.empty() || request_path[0] != '/' || request_path.find(
+			"..") != std::string::npos)
 	{
 	{
 		rep = reply::stock_reply(reply::bad_request);
 		rep = reply::stock_reply(reply::bad_request);
 		return;
 		return;
 	}
 	}
 
 
 	// If path ends in slash (i.e. is a directory) then add "index.html".
 	// If path ends in slash (i.e. is a directory) then add "index.html".
-	if(request_path[request_path.size() - 1] == '/')
+	if (request_path[request_path.size() - 1] == '/')
 	{
 	{
 		request_path += "index.html";
 		request_path += "index.html";
 	}
 	}
@@ -52,7 +52,7 @@ void request_handler::handle_request(const request& req, reply& rep)
 	std::size_t last_slash_pos = request_path.find_last_of("/");
 	std::size_t last_slash_pos = request_path.find_last_of("/");
 	std::size_t last_dot_pos = request_path.find_last_of(".");
 	std::size_t last_dot_pos = request_path.find_last_of(".");
 	std::string extension;
 	std::string extension;
-	if(last_dot_pos != std::string::npos && last_dot_pos > last_slash_pos)
+	if (last_dot_pos != std::string::npos && last_dot_pos > last_slash_pos)
 	{
 	{
 		extension = request_path.substr(last_dot_pos + 1);
 		extension = request_path.substr(last_dot_pos + 1);
 	}
 	}
@@ -60,7 +60,7 @@ void request_handler::handle_request(const request& req, reply& rep)
 	// Open the file to send back.
 	// Open the file to send back.
 	std::string full_path = doc_root_ + request_path;
 	std::string full_path = doc_root_ + request_path;
 	std::ifstream is(full_path.c_str(), std::ios::in | std::ios::binary);
 	std::ifstream is(full_path.c_str(), std::ios::in | std::ios::binary);
-	if(!is)
+	if (!is)
 	{
 	{
 		rep = reply::stock_reply(reply::not_found);
 		rep = reply::stock_reply(reply::not_found);
 		return;
 		return;
@@ -69,7 +69,7 @@ void request_handler::handle_request(const request& req, reply& rep)
 	// Fill out the reply to be sent to the client.
 	// Fill out the reply to be sent to the client.
 	rep.status = reply::ok;
 	rep.status = reply::ok;
 	char buf[512];
 	char buf[512];
-	while(is.read(buf, sizeof(buf)).gcount() > 0)
+	while (is.read(buf, sizeof(buf)).gcount() > 0)
 		rep.content.append(buf, is.gcount());
 		rep.content.append(buf, is.gcount());
 	rep.headers.resize(2);
 	rep.headers.resize(2);
 	rep.headers[0].name = "Content-Length";
 	rep.headers[0].name = "Content-Length";
@@ -82,15 +82,15 @@ bool request_handler::url_decode(const std::string& in, std::string& out)
 {
 {
 	out.clear();
 	out.clear();
 	out.reserve(in.size());
 	out.reserve(in.size());
-	for(std::size_t i = 0; i < in.size(); ++i)
+	for (std::size_t i = 0; i < in.size(); ++i)
 	{
 	{
-		if(in[i] == '%')
+		if (in[i] == '%')
 		{
 		{
-			if(i + 3 <= in.size())
+			if (i + 3 <= in.size())
 			{
 			{
 				int value = 0;
 				int value = 0;
 				std::istringstream is(in.substr(i + 1, 2));
 				std::istringstream is(in.substr(i + 1, 2));
-				if(is >> std::hex >> value)
+				if (is >> std::hex >> value)
 				{
 				{
 					out += static_cast<char> (value);
 					out += static_cast<char> (value);
 					i += 2;
 					i += 2;
@@ -105,7 +105,7 @@ bool request_handler::url_decode(const std::string& in, std::string& out)
 				return false;
 				return false;
 			}
 			}
 		}
 		}
-		else if(in[i] == '+')
+		else if (in[i] == '+')
 		{
 		{
 			out += ' ';
 			out += ' ';
 		}
 		}

+ 36 - 36
src/experimental/http_server/request_parser.cc

@@ -25,10 +25,10 @@ void request_parser::reset()
 
 
 boost::tribool request_parser::consume(request& req, char input)
 boost::tribool request_parser::consume(request& req, char input)
 {
 {
-	switch(state_)
+	switch (state_)
 	{
 	{
 		case method_start:
 		case method_start:
-			if(!is_char(input) || is_ctl(input) || is_tspecial(input))
+			if (!is_char(input) || is_ctl(input) || is_tspecial(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -39,12 +39,12 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case method:
 		case method:
-			if(input == ' ')
+			if (input == ' ')
 			{
 			{
 				state_ = uri;
 				state_ = uri;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(!is_char(input) || is_ctl(input) || is_tspecial(input))
+			else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -54,7 +54,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case uri_start:
 		case uri_start:
-			if(is_ctl(input))
+			if (is_ctl(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -65,12 +65,12 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case uri:
 		case uri:
-			if(input == ' ')
+			if (input == ' ')
 			{
 			{
 				state_ = http_version_h;
 				state_ = http_version_h;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(is_ctl(input))
+			else if (is_ctl(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -80,7 +80,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case http_version_h:
 		case http_version_h:
-			if(input == 'H')
+			if (input == 'H')
 			{
 			{
 				state_ = http_version_t_1;
 				state_ = http_version_t_1;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -90,7 +90,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_t_1:
 		case http_version_t_1:
-			if(input == 'T')
+			if (input == 'T')
 			{
 			{
 				state_ = http_version_t_2;
 				state_ = http_version_t_2;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -100,7 +100,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_t_2:
 		case http_version_t_2:
-			if(input == 'T')
+			if (input == 'T')
 			{
 			{
 				state_ = http_version_p;
 				state_ = http_version_p;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -110,7 +110,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_p:
 		case http_version_p:
-			if(input == 'P')
+			if (input == 'P')
 			{
 			{
 				state_ = http_version_slash;
 				state_ = http_version_slash;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -120,7 +120,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_slash:
 		case http_version_slash:
-			if(input == '/')
+			if (input == '/')
 			{
 			{
 				req.http_version_major = 0;
 				req.http_version_major = 0;
 				req.http_version_minor = 0;
 				req.http_version_minor = 0;
@@ -132,10 +132,10 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_major_start:
 		case http_version_major_start:
-			if(is_digit(input))
+			if (is_digit(input))
 			{
 			{
 				req.http_version_major = req.http_version_major * 10 + input
 				req.http_version_major = req.http_version_major * 10 + input
-				        - '0';
+						- '0';
 				state_ = http_version_major;
 				state_ = http_version_major;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
@@ -144,15 +144,15 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_major:
 		case http_version_major:
-			if(input == '.')
+			if (input == '.')
 			{
 			{
 				state_ = http_version_minor_start;
 				state_ = http_version_minor_start;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(is_digit(input))
+			else if (is_digit(input))
 			{
 			{
 				req.http_version_major = req.http_version_major * 10 + input
 				req.http_version_major = req.http_version_major * 10 + input
-				        - '0';
+						- '0';
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 			else
 			else
@@ -160,10 +160,10 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_minor_start:
 		case http_version_minor_start:
-			if(is_digit(input))
+			if (is_digit(input))
 			{
 			{
 				req.http_version_minor = req.http_version_minor * 10 + input
 				req.http_version_minor = req.http_version_minor * 10 + input
-				        - '0';
+						- '0';
 				state_ = http_version_minor;
 				state_ = http_version_minor;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
@@ -172,15 +172,15 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case http_version_minor:
 		case http_version_minor:
-			if(input == '\r')
+			if (input == '\r')
 			{
 			{
 				state_ = expecting_newline_1;
 				state_ = expecting_newline_1;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(is_digit(input))
+			else if (is_digit(input))
 			{
 			{
 				req.http_version_minor = req.http_version_minor * 10 + input
 				req.http_version_minor = req.http_version_minor * 10 + input
-				        - '0';
+						- '0';
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 			else
 			else
@@ -188,7 +188,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case expecting_newline_1:
 		case expecting_newline_1:
-			if(input == '\n')
+			if (input == '\n')
 			{
 			{
 				state_ = header_line_start;
 				state_ = header_line_start;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -198,17 +198,17 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case header_line_start:
 		case header_line_start:
-			if(input == '\r')
+			if (input == '\r')
 			{
 			{
 				state_ = expecting_newline_3;
 				state_ = expecting_newline_3;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(!req.headers.empty() && (input == ' ' || input == '\t'))
+			else if (!req.headers.empty() && (input == ' ' || input == '\t'))
 			{
 			{
 				state_ = header_lws;
 				state_ = header_lws;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(!is_char(input) || is_ctl(input) || is_tspecial(input))
+			else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -220,16 +220,16 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case header_lws:
 		case header_lws:
-			if(input == '\r')
+			if (input == '\r')
 			{
 			{
 				state_ = expecting_newline_2;
 				state_ = expecting_newline_2;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(input == ' ' || input == '\t')
+			else if (input == ' ' || input == '\t')
 			{
 			{
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(is_ctl(input))
+			else if (is_ctl(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -240,12 +240,12 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case header_name:
 		case header_name:
-			if(input == ':')
+			if (input == ':')
 			{
 			{
 				state_ = space_before_header_value;
 				state_ = space_before_header_value;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(!is_char(input) || is_ctl(input) || is_tspecial(input))
+			else if (!is_char(input) || is_ctl(input) || is_tspecial(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -255,7 +255,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case space_before_header_value:
 		case space_before_header_value:
-			if(input == ' ')
+			if (input == ' ')
 			{
 			{
 				state_ = header_value;
 				state_ = header_value;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -265,12 +265,12 @@ boost::tribool request_parser::consume(request& req, char input)
 				return false;
 				return false;
 			}
 			}
 		case header_value:
 		case header_value:
-			if(input == '\r')
+			if (input == '\r')
 			{
 			{
 				state_ = expecting_newline_2;
 				state_ = expecting_newline_2;
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
-			else if(is_ctl(input))
+			else if (is_ctl(input))
 			{
 			{
 				return false;
 				return false;
 			}
 			}
@@ -280,7 +280,7 @@ boost::tribool request_parser::consume(request& req, char input)
 				return boost::indeterminate;
 				return boost::indeterminate;
 			}
 			}
 		case expecting_newline_2:
 		case expecting_newline_2:
-			if(input == '\n')
+			if (input == '\n')
 			{
 			{
 				state_ = header_line_start;
 				state_ = header_line_start;
 				return boost::indeterminate;
 				return boost::indeterminate;
@@ -308,7 +308,7 @@ bool request_parser::is_ctl(int c)
 
 
 bool request_parser::is_tspecial(int c)
 bool request_parser::is_tspecial(int c)
 {
 {
-	switch(c)
+	switch (c)
 	{
 	{
 		case '(':
 		case '(':
 		case ')':
 		case ')':

+ 7 - 7
src/experimental/http_server/server.cc

@@ -14,10 +14,10 @@
 namespace http_server {
 namespace http_server {
 
 
 server::server(const std::string& address, const std::string& port,
 server::server(const std::string& address, const std::string& port,
-        const std::string& doc_root) :
+		const std::string& doc_root) :
 	io_service_(), acceptor_(io_service_), connection_manager_(),
 	io_service_(), acceptor_(io_service_), connection_manager_(),
-	        new_connection_(new connection(io_service_, connection_manager_,
-	                request_handler_)), request_handler_(doc_root)
+			new_connection_(new connection(io_service_, connection_manager_,
+					request_handler_)), request_handler_(doc_root)
 {
 {
 	// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
 	// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
 	boost::asio::ip::tcp::resolver resolver(io_service_);
 	boost::asio::ip::tcp::resolver resolver(io_service_);
@@ -28,7 +28,7 @@ server::server(const std::string& address, const std::string& port,
 	acceptor_.bind(endpoint);
 	acceptor_.bind(endpoint);
 	acceptor_.listen();
 	acceptor_.listen();
 	acceptor_.async_accept(new_connection_->socket(), boost::bind(
 	acceptor_.async_accept(new_connection_->socket(), boost::bind(
-	        &server::handle_accept, this, boost::asio::placeholders::error));
+			&server::handle_accept, this, boost::asio::placeholders::error));
 }
 }
 
 
 void server::run()
 void server::run()
@@ -49,13 +49,13 @@ void server::stop()
 
 
 void server::handle_accept(const boost::system::error_code& e)
 void server::handle_accept(const boost::system::error_code& e)
 {
 {
-	if(!e)
+	if (!e)
 	{
 	{
 		connection_manager_.start(new_connection_);
 		connection_manager_.start(new_connection_);
 		new_connection_.reset(new connection(io_service_, connection_manager_,
 		new_connection_.reset(new connection(io_service_, connection_manager_,
-		        request_handler_));
+				request_handler_));
 		acceptor_.async_accept(new_connection_->socket(), boost::bind(
 		acceptor_.async_accept(new_connection_->socket(), boost::bind(
-		        &server::handle_accept, this, boost::asio::placeholders::error));
+				&server::handle_accept, this, boost::asio::placeholders::error));
 	}
 	}
 }
 }
 
 

+ 1 - 1
src/thread/thread_pool.cc

@@ -14,7 +14,7 @@ ThreadPool::~ThreadPool()
 void ThreadPool::Start()
 void ThreadPool::Start()
 {
 {
 	running = true;
 	running = true;
-	for(int i = 0; i < num; ++i)
+	for (int i = 0; i < num; ++i)
 	{
 	{
 		thread_ptr t(new thread(bind(&ThreadPool::Runner, this)));
 		thread_ptr t(new thread(bind(&ThreadPool::Runner, this)));
 		threads.push_back(t);
 		threads.push_back(t);

+ 2 - 2
src/thread/thread_pool.h

@@ -25,7 +25,7 @@ private:
 	condition_variable cond;
 	condition_variable cond;
 	condition_variable done;
 	condition_variable done;
 	list<thread_ptr> threads;
 	list<thread_ptr> threads;
-	list< function<void (void)> > tasks;
+	list<function<void(void)> > tasks;
 
 
 	void Runner();
 	void Runner();
 public:
 public:
@@ -34,7 +34,7 @@ public:
 	void Start();
 	void Start();
 	void Stop();
 	void Stop();
 	void SetNum(int n);
 	void SetNum(int n);
-	bool PushTask(function<void (void)> task);
+	bool PushTask(function<void(void)> task);
 };
 };
 } // namespace hainan
 } // namespace hainan
 #endif  // THREAD_THREAD_POOL_H
 #endif  // THREAD_THREAD_POOL_H

+ 5 - 4
src/thread/thread_pool_test.cc

@@ -20,7 +20,8 @@ class ThreadPoolTest: public testing::Test
 protected:
 protected:
 	ThreadPool thread_pool;
 	ThreadPool thread_pool;
 public:
 public:
-	ThreadPoolTest() : thread_pool()
+	ThreadPoolTest() :
+		thread_pool()
 	{
 	{
 	}
 	}
 	void Max(int a, int b, int* z)
 	void Max(int a, int b, int* z)
@@ -34,13 +35,13 @@ TEST_F(ThreadPoolTest, Test1)
 	vector<int> x(100, 8);
 	vector<int> x(100, 8);
 	vector<int> y(100, 9);
 	vector<int> y(100, 9);
 	vector<int> z(100, 0);
 	vector<int> z(100, 0);
-	for(int i = 0; i < 100; ++i)
+	for (int i = 0; i < 100; ++i)
 	{
 	{
 		thread_pool.PushTask(
 		thread_pool.PushTask(
-		        bind(&ThreadPoolTest::Max, this, x[i], y[i], &z[i]));
+				bind(&ThreadPoolTest::Max, this, x[i], y[i], &z[i]));
 	}
 	}
 	thread_pool.Stop();
 	thread_pool.Stop();
-	for(int i = 0; i < 100; ++i)
+	for (int i = 0; i < 100; ++i)
 	{
 	{
 		ASSERT_EQ(9, z[i])<< "i = " << i;
 		ASSERT_EQ(9, z[i])<< "i = " << i;
 	}
 	}