Add examples, reformat some code, for boost-format package.

This commit is contained in:
chris_kohlhoff 2005-11-04 08:08:15 +00:00
parent 14dc249aa8
commit 34c33d4ba2
25 changed files with 163 additions and 44 deletions

View File

@ -0,0 +1,14 @@
subproject libs/asio/example/echo ;
template asio_echo_example
: <lib>../../../thread/build/boost_thread
: <include>$(BOOST_ROOT)
<threading>multi
;
exe async_tcp_echo_server : <template>asio_echo_example async_tcp_echo_server.cpp ;
exe async_udp_echo_server : <template>asio_echo_example async_udp_echo_server.cpp ;
exe blocking_tcp_echo_client : <template>asio_echo_example blocking_tcp_echo_client.cpp ;
exe blocking_tcp_echo_server : <template>asio_echo_example blocking_tcp_echo_server.cpp ;
exe blocking_udp_echo_client : <template>asio_echo_example blocking_udp_echo_client.cpp ;
exe blocking_udp_echo_server : <template>asio_echo_example blocking_udp_echo_server.cpp ;

View File

@ -0,0 +1,17 @@
subproject libs/asio/example/http/server ;
exe http_server
: <lib>../../../../thread/build/boost_thread
<lib>../../../../date_time/build/boost_date_time
connection.cpp
connection_manager.cpp
mime_types.cpp
posix_main.cpp
reply.cpp
request_handler.cpp
request_parser.cpp
server.cpp
win_main.cpp
: <include>$(BOOST_ROOT)
<threading>multi
;

View File

@ -1,6 +1,6 @@
#include "connection.hpp"
#include <vector>
#include "boost/bind.hpp"
#include <boost/bind.hpp>
#include "connection_manager.hpp"
#include "request_handler.hpp"
@ -24,7 +24,8 @@ void connection::start()
{
asio::async_read(socket_, asio::buffer(buffer_),
boost::bind(&connection::handle_read, shared_from_this(),
asio::placeholders::error, asio::placeholders::bytes_transferred));
asio::placeholders::error,
asio::placeholders::bytes_transferred));
}
void connection::stop()
@ -59,7 +60,8 @@ void connection::handle_read(const asio::error& e,
{
asio::async_read(socket_, asio::buffer(buffer_),
boost::bind(&connection::handle_read, shared_from_this(),
asio::placeholders::error, asio::placeholders::bytes_transferred));
asio::placeholders::error,
asio::placeholders::bytes_transferred));
}
}
else if (e != asio::error::operation_aborted)

View File

@ -1,11 +1,11 @@
#ifndef HTTP_CONNECTION_HPP
#define HTTP_CONNECTION_HPP
#include "asio.hpp"
#include "boost/array.hpp"
#include "boost/noncopyable.hpp"
#include "boost/shared_ptr.hpp"
#include "boost/enable_shared_from_this.hpp"
#include <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"

View File

@ -1,6 +1,6 @@
#include "connection_manager.hpp"
#include <algorithm>
#include "boost/bind.hpp"
#include <boost/bind.hpp>
namespace http {
namespace server {

View File

@ -2,7 +2,7 @@
#define HTTP_CONNECTION_MANAGER_HPP
#include <set>
#include "boost/noncopyable.hpp"
#include <boost/noncopyable.hpp>
#include "connection.hpp"
namespace http {

View File

@ -1,11 +1,14 @@
#include <iostream>
#include <string>
#include <asio.hpp>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include "server.hpp"
#if !defined(_WIN32)
#include <pthread.h>
#include <signal.h>
#include <string>
#include "asio.hpp"
#include "boost/bind.hpp"
#include "boost/lexical_cast.hpp"
#include "server.hpp"
int main(int argc, char* argv[])
{
@ -58,3 +61,5 @@ int main(int argc, char* argv[])
return 0;
}
#endif // !defined(_WIN32)

View File

@ -1,5 +1,5 @@
#include "reply.hpp"
#include "boost/lexical_cast.hpp"
#include <boost/lexical_cast.hpp>
namespace http {
namespace server {

View File

@ -3,7 +3,7 @@
#include <string>
#include <vector>
#include "asio.hpp"
#include <asio.hpp>
#include "header.hpp"
namespace http {

View File

@ -2,7 +2,7 @@
#include <fstream>
#include <sstream>
#include <string>
#include "boost/lexical_cast.hpp"
#include <boost/lexical_cast.hpp>
#include "mime_types.hpp"
#include "reply.hpp"
#include "request.hpp"

View File

@ -2,7 +2,7 @@
#define HTTP_REQUEST_HANDLER_HPP
#include <string>
#include "boost/noncopyable.hpp"
#include <boost/noncopyable.hpp>
namespace http {
namespace server {

View File

@ -1,8 +1,8 @@
#ifndef HTTP_REQUEST_PARSER_HPP
#define HTTP_REQUEST_PARSER_HPP
#include "boost/logic/tribool.hpp"
#include "boost/tuple/tuple.hpp"
#include <boost/logic/tribool.hpp>
#include <boost/tuple/tuple.hpp>
namespace http {
namespace server {

View File

@ -1,5 +1,5 @@
#include "server.hpp"
#include "boost/bind.hpp"
#include <boost/bind.hpp>
namespace http {
namespace server {
@ -19,13 +19,14 @@ server::server(short port, const std::string& doc_root)
acceptor_.bind(endpoint);
acceptor_.listen();
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this, asio::placeholders::error));
boost::bind(&server::handle_accept, this,
asio::placeholders::error));
}
void server::run()
{
// The asio::demuxer::run() call will block until all asynchronous operations
// have finished. While the server is running, there is always at least one
// The demuxer::run() call will block until all asynchronous operations have
// finished. While the server is running, there is always at least one
// asynchronous operation outstanding: the asynchronous accept call waiting
// for new incoming connections.
demuxer_.run();
@ -46,20 +47,22 @@ void server::handle_accept(const asio::error& e)
new_connection_.reset(new connection(demuxer_,
connection_manager_, request_handler_));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this, asio::placeholders::error));
boost::bind(&server::handle_accept, this,
asio::placeholders::error));
}
else if (e == asio::error::connection_aborted)
{
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&server::handle_accept, this, asio::placeholders::error));
boost::bind(&server::handle_accept, this,
asio::placeholders::error));
}
}
void server::handle_stop()
{
// The server is stopped by cancelling all outstanding asynchronous
// operations. Once all operations have finished the asio::demuxer::run() call
// will exit.
// operations. Once all operations have finished the demuxer::run() call will
// exit.
acceptor_.close();
connection_manager_.stop_all();
}

View File

@ -1,9 +1,9 @@
#ifndef HTTP_SERVER_HPP
#define HTTP_SERVER_HPP
#include "asio.hpp"
#include <asio.hpp>
#include <string>
#include "boost/noncopyable.hpp"
#include <boost/noncopyable.hpp>
#include "connection.hpp"
#include "connection_manager.hpp"
#include "request_handler.hpp"

View File

@ -1,11 +1,13 @@
#include <iostream>
#include <string>
#include "asio.hpp"
#include "boost/bind.hpp"
#include "boost/function.hpp"
#include "boost/lexical_cast.hpp"
#include <asio.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/lexical_cast.hpp>
#include "server.hpp"
#if defined(_WIN32)
boost::function0<void> console_ctrl_function;
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
@ -57,3 +59,5 @@ int main(int argc, char* argv[])
return 0;
}
#endif // defined(_WIN32)

View File

@ -0,0 +1,7 @@
subproject libs/asio/example/iostreams ;
exe daytime_client
: daytime_client.cpp
: <include>$(BOOST_ROOT)
<threading>multi
;

View File

@ -0,0 +1,13 @@
subproject libs/asio/example/multicast ;
exe receiver
: receiver.cpp
: <include>$(BOOST_ROOT)
<threading>multi
;
exe sender
: sender.cpp
: <include>$(BOOST_ROOT)
<threading>multi
;

View File

@ -18,12 +18,14 @@ public:
socket_.bind(asio::ipv4::udp::endpoint(multicast_port));
// Join the multicast group.
socket_.set_option(asio::ipv4::multicast::add_membership(multicast_addr));
socket_.set_option(
asio::ipv4::multicast::add_membership(multicast_addr));
socket_.async_receive_from(
asio::buffer(data_, max_length), 0, sender_endpoint_,
boost::bind(&receiver::handle_receive_from, this,
asio::placeholders::error, asio::placeholders::bytes_transferred));
asio::placeholders::error,
asio::placeholders::bytes_transferred));
}
void handle_receive_from(const asio::error& error, size_t bytes_recvd)
@ -36,7 +38,8 @@ public:
socket_.async_receive_from(
asio::buffer(data_, max_length), 0, sender_endpoint_,
boost::bind(&receiver::handle_receive_from, this,
asio::placeholders::error, asio::placeholders::bytes_transferred));
asio::placeholders::error,
asio::placeholders::bytes_transferred));
}
}

View File

@ -24,7 +24,8 @@ public:
asio::ipv4::udp::endpoint target(multicast_port, multicast_addr);
socket_.async_send_to(
asio::buffer(message_.data(), message_.length()), 0, target,
boost::bind(&sender::handle_send_to, this, asio::placeholders::error));
boost::bind(&sender::handle_send_to, this,
asio::placeholders::error));
}
void handle_send_to(const asio::error& error)

View File

@ -0,0 +1,17 @@
subproject libs/asio/example/ssl ;
exe client
: client.cpp
: <include>$(BOOST_ROOT)
<threading>multi
<find-library>ssl
<find-library>crypto
;
exe server
: server.cpp
: <include>$(BOOST_ROOT)
<threading>multi
<find-library>ssl
<find-library>crypto
;

View File

@ -0,0 +1,12 @@
subproject libs/asio/example/timeouts ;
template asio_timeouts_example
: <lib>../../../thread/build/boost_thread
: <include>$(BOOST_ROOT)
<threading>multi
;
exe accept_timeout : <template>asio_timeouts_example accept_timeout.cpp ;
exe connect_timeout : <template>asio_timeouts_example connect_timeout.cpp ;
exe datagram_receive_timeout : <template>asio_timeouts_example datagram_receive_timeout.cpp ;
exe stream_receive_timeout : <template>asio_timeouts_example stream_receive_timeout.cpp ;

View File

@ -0,0 +1,20 @@
subproject libs/asio/example/tutorial ;
template asio_tutorial
: <lib>../../../thread/build/boost_thread
: <include>$(BOOST_ROOT)
<threading>multi
;
exe timer1 : <template>asio_tutorial timer1/timer.cpp ;
exe timer2 : <template>asio_tutorial timer2/timer.cpp ;
exe timer3 : <template>asio_tutorial timer3/timer.cpp ;
exe timer4 : <template>asio_tutorial timer4/timer.cpp ;
exe timer5 : <template>asio_tutorial timer5/timer.cpp ;
exe daytime1_client : <template>asio_tutorial daytime1/client.cpp ;
exe daytime2_server : <template>asio_tutorial daytime2/server.cpp ;
exe daytime3_server : <template>asio_tutorial daytime3/server.cpp ;
exe daytime4_client : <template>asio_tutorial daytime4/client.cpp ;
exe daytime5_server : <template>asio_tutorial daytime5/server.cpp ;
exe daytime6_server : <template>asio_tutorial daytime6/server.cpp ;
exe daytime7_server : <template>asio_tutorial daytime7/server.cpp ;

View File

@ -19,7 +19,7 @@ run deadline_timer_service_test.cpp ;
run deadline_timer_test.cpp ;
run default_error_handler_test.cpp ;
run demuxer_service_test.cpp ;
run demuxer_test.cpp ;
run demuxer_test.cpp <lib>../../thread/build/boost_thread ;
run error_handler_test.cpp ;
run error_test.cpp ;
run fixed_buffer_test.cpp ;
@ -36,7 +36,7 @@ run ipv4/udp_test.cpp ;
run is_read_buffered_test.cpp ;
run is_write_buffered_test.cpp ;
run locking_dispatcher_service_test.cpp ;
run locking_dispatcher_test.cpp ;
run locking_dispatcher_test.cpp <lib>../../thread/build/boost_thread ;
run null_error_handler_test.cpp ;
run placeholders_test.cpp ;
run read_test.cpp ;
@ -47,7 +47,6 @@ run socket_base_test.cpp ;
run socket_option_test.cpp ;
run stream_socket_service_test.cpp ;
run stream_socket_test.cpp ;
run thread_test.cpp ;
run time_traits_test.cpp ;
run wrapped_handler_test.cpp ;
run write_test.cpp ;

View File

@ -83,7 +83,8 @@ private:
void is_read_buffered_test()
{
BOOST_CHECK(!asio::is_read_buffered<asio::stream_socket>::value);
BOOST_CHECK(!asio::is_read_buffered<
asio::stream_socket>::value);
BOOST_CHECK(!!asio::is_read_buffered<
asio::buffered_read_stream<asio::stream_socket> >::value);

View File

@ -83,7 +83,8 @@ private:
void is_write_buffered_test()
{
BOOST_CHECK(!asio::is_write_buffered<asio::stream_socket>::value);
BOOST_CHECK(!asio::is_write_buffered<
asio::stream_socket>::value);
BOOST_CHECK(!asio::is_write_buffered<
asio::buffered_read_stream<asio::stream_socket> >::value);