Skip to content

Commit 60cc0e1

Browse files
committed
Updated docs.
1 parent 91a45ce commit 60cc0e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1674
-1343
lines changed

_sources/directives.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Directives
22
==========
33

4-
The library also uses a technique for allowing message-passing
4+
The :mod:`cpp-netlib` uses a technique for allowing message-passing
55
semantics in a chainable fashion in the form of directives. The basic
66
concept for directives is, in a general sense, an encapsulated
77
transformation that can be applied to objects that abide by the

_sources/examples.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Examples
2+
========
3+
4+
The :mod:`cpp-netlib` is a practical library that is designed to aid
5+
the development of applications for that need to communicate using
6+
common networking protocols. The following set of examples describe a
7+
series of realistic examples that use the :mod:`cpp-netlib` for these
8+
kinds of application.
9+
10+
.. toctree::
11+
:maxdepth: 2
12+
13+
examples_http.rst
14+
examples_xmpp.rst

_sources/examples_http.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
HTTP examples
2+
=============
3+
4+
The HTTP component of the :mod:`cpp-netlib` contains a client and server.
5+
The examples that follow show how to use both for programs that can be
6+
embedded into larger applications.
7+
8+
.. toctree::
9+
:maxdepth: 2
10+
11+
http_client.rst
12+
hello_world_server.rst
13+
hello_world_client.rst

_sources/tutorials_xmpp.txt renamed to _sources/examples_xmpp.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
XMPP tutorials
2-
==============
1+
XMPP examples
2+
=============
33

44
.. toctree::
55
:maxdepth: 2

_sources/getting_started.txt

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
Getting started
55
*****************
66

7-
Installing an official release
8-
==============================
7+
Downloading an official release
8+
===============================
99

1010
All stable versions of :mod:`cpp-netlib` can be downloaded from Github:
11-
``http://github.com/cpp-netlib/cpp-netlib/downloads``. Each release
11+
http://github.com/cpp-netlib/cpp-netlib/downloads. Each release
1212
is available as gzipped (Using the command ``tar xzf
1313
cpp-netlib.tar.gz``) or bzipped (Using ``tar xjf cpp-netlib.tar.bz2``)
1414
tarball, or as a zipfile (``unzip cpp-netlib.zip``, or on Windows
1515
using a tool such as 7zip_).
1616

1717
.. _7zip: http://www.7-zip.org/
1818

19-
Installing a development version
20-
================================
19+
Downloading a development version
20+
=================================
2121

2222
The :mod:`cpp-netlib` uses Git_ for source control, so to use any
2323
development versions Git must be installed on your system.
@@ -36,7 +36,7 @@ Windows users need to use msysGit_, and to invoke the command above
3636
from a shell.
3737

3838
For fans of Subversion_, the same code can be checked out from
39-
`http://svn.github.com/mikhailberis/cpp-netlib.git`.
39+
http://svn.github.com/mikhailberis/cpp-netlib.git.
4040

4141
.. _Git: http://git-scm.com/
4242
.. _`Git documentation`: http://git-scm.com/documentation
@@ -46,14 +46,16 @@ For fans of Subversion_, the same code can be checked out from
4646
Getting Boost
4747
=============
4848

49-
:mod:`cpp-netlib` depends on Boost_. It should work for Boost 1.41.0 and
50-
above. If Boost is not installed on your system, the environment
49+
:mod:`cpp-netlib` depends on Boost_. It should work for any version
50+
of Boost above 1.41.0. If Boost is not installed on your system, the
51+
latest package can be found on the `Boost web-site`_. The environment
5152
variable ``BOOST_ROOT`` must be defined, which must be the full path
52-
name of the top directory of the Boost distribution. Although Boost is
53-
mostly header only, applications built using :mod:`cpp-netlib` still
54-
requires linking with `Boost.System`_.
53+
name of the top directory of the Boost distribution. Although Boost
54+
is mostly header only, applications built using :mod:`cpp-netlib`
55+
still requires linking with `Boost.System`_.
5556

5657
.. _Boost: http://www.boost.org/doc/libs/release/more/getting_started/index.html
58+
.. _`Boost web-site`: http://www.boost.org/users/download/
5759
.. _`Boost.System`: http://www.boost.org/libs/system/index.html
5860

5961
Getting CMake
@@ -63,12 +65,35 @@ The :mod:`cpp-netlib` uses CMake_.
6365

6466
.. _CMake: http://www.cmake.org/
6567

68+
Open a command line in the :mod:`cpp-netlib` home directory.
69+
``cmake`` requires the code to be built out of source, so you need to
70+
create a separate directory.
71+
6672
Instructions for Windows Users
6773
==============================
6874

75+
76+
6977
Instructions for Linux Users
7078
============================
7179

80+
Invoke ``cmake`` in the build directory, this generates a Makefile.
81+
Then, invoke ``make`` to build everything (unit tests and examples).
82+
To run the tests, invoke ``make test``.
83+
84+
::
85+
86+
shell$ make
87+
shell$ make test
88+
89+
Running the Unit Tests
90+
======================
91+
92+
All unit tests are located in the ``libs/network/test`` directory. To
93+
run the full suite of unit tests, invoke ``ctest`` from the build
94+
directory.
95+
7296
Building and Running the Examples
7397
=================================
7498

99+
Examples are located in the ``libs/network/examples`` subdirectory.

_sources/hello_world_client.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
"Hello world" HTTP client
55
***************************
66

7+
::
78

9+
./hello_world_client http://127.0.0.1/

_sources/hello_world_server.txt

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,86 @@
44
"Hello world" HTTP server
55
***************************
66

7-
:mod:`cpp-netlib` provides the framework to develop embedded HTTP
8-
servers. This example
7+
The :mod:`cpp-netlib` provides the framework to develop embedded HTTP
8+
servers. For this example, the server is configured to return a
9+
simple response to any HTTP request.
10+
11+
.. code-block:: c++
12+
13+
#include <boost/network/protocol/http/server.hpp>
14+
#include <iostream>
15+
16+
namespace http = boost::network::http;
17+
18+
struct hello_world;
19+
typedef http::server<hello_world> server;
20+
21+
struct hello_world {
22+
void operator() (server::request const &request,
23+
server::response &response) {
24+
response = server::response::stock_reply(
25+
server::response::ok, "Hello, World!");
26+
}
27+
};
28+
29+
int
30+
main(int argc, char * argv[]) {
31+
32+
if (argc != 3) {
33+
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
34+
return 1;
35+
}
36+
37+
try {
38+
hello_world handler;
39+
server server_(argv[1], argv[2], handler);
40+
server_.run();
41+
}
42+
catch (std::exception &e) {
43+
std::cerr << e.what() << std::endl;
44+
return 1;
45+
}
46+
47+
return 0;
48+
}
49+
50+
This is about a straightforward as server programming will get in C++.
51+
52+
.. code-block:: c++
53+
54+
#include <boost/network/protocol/http/server.hpp>
55+
56+
This header contains all the code needed to develop an HTTP server.
57+
58+
.. code-block:: c++
59+
60+
struct hello_world;
61+
typedef http::server<hello_world> server;
62+
63+
struct hello_world {
64+
void operator () (server::request const &request,
65+
server::response &response) {
66+
response = server::response::stock_reply(
67+
server::response::ok, "Hello, World!");
68+
}
69+
};
70+
71+
``hello_world`` is a functor class which handles HTTP requests. All
72+
the operator does here is return an HTTP response with HTTP code 200
73+
and the body ``"Hello, World!"``.
74+
75+
.. code-block:: c++
76+
77+
hello_world handler;
78+
server server_(argv[1], argv[2], handler);
79+
server_.run();
80+
81+
The first two arguments to the ``server`` constructor are the host and
82+
the port on which the server will listen. The third argument is the
83+
the handler object defined previously. This example can be run from
84+
a command line as follows:
85+
86+
::
87+
88+
shell$ ./hello_world_server 0.0.0.0 80
89+

0 commit comments

Comments
 (0)