Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99e9060

Browse files
committed
Multiple changes, latest snapshot, especially with the CSS to play nice with smaller screens.
1 parent3a49b0d commit99e9060

29 files changed

+447
-184
lines changed

‎_sources/hello_world_server.txt

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
"Hello world" HTTP server
55
***************************
66

7-
.. todo::
7+
Now that we've seen how we can deal with request and response objects from the
8+
client side, we'll see how we can then use the same abstractions on the server
9+
side. In this example we're going to create a simple HTTP Server in C++ using
10+
:mod:`cpp-netlib`.
811

9-
The text needs to show that we're building on knowledge gained
10-
from the HTTP client (hello world) example. Make sure there's
11-
more description than code.
12+
The Code
13+
========
1214

1315
The :mod:`cpp-netlib` provides the framework to develop embedded HTTP
1416
servers. For this example, the server is configured to return a
@@ -55,11 +57,44 @@ simple response to any HTTP request.
5557

5658
This is about a straightforward as server programming will get in C++.
5759

60+
Building the Server
61+
===================
62+
63+
Just like with the HTTP client, we can build this example by doing the following
64+
on the shell::
65+
66+
$ cd ~/cpp-netlib
67+
$ g++ -o hello_world_server \
68+
> libs/network/example/http/hello_world_server.cpp \
69+
> -I$BOOST_ROOT \
70+
> -I. \
71+
> -L$BOOST_ROOT/stage/lib \
72+
> -lboost_system \
73+
> -pthread
74+
75+
The first two arguments to the ``server`` constructor are the host and
76+
the port on which the server will listen. The third argument is the
77+
the handler object defined previously. This example can be run from
78+
a command line as follows:
79+
80+
::
81+
82+
shell$ ./hello_world_server 0.0.0.0 80
83+
84+
.. note:: If you're going to run the server on port 80, you may have to run it
85+
as an administrator.
86+
87+
Diving into the Code
88+
====================
89+
90+
Let's take a look at the code listing above in greater detail.
91+
5892
.. code-block:: c++
5993

6094
#include <boost/network/protocol/http/server.hpp>
6195

62-
This header contains all the code needed to develop an HTTP server.
96+
This header contains all the code needed to develop an HTTP server with
97+
:mod:`cpp-netlib`.
6398

6499
.. code-block:: c++
65100

@@ -76,7 +111,11 @@ This header contains all the code needed to develop an HTTP server.
76111

77112
``hello_world`` is a functor class which handles HTTP requests. All
78113
the operator does here is return an HTTP response with HTTP code 200
79-
and the body ``"Hello, World!"``.
114+
and the body ``"Hello, World!"``. There are a number of pre-defined stock
115+
replies differentiated by status code with configurable bodies.
116+
117+
All the supported enumeration values for the response status codes can be found
118+
in ``boost/network/protocol/http/impl/response.ipp``.
80119

81120
.. code-block:: c++
82121

@@ -86,10 +125,13 @@ and the body ``"Hello, World!"``.
86125

87126
The first two arguments to the ``server`` constructor are the host and
88127
the port on which the server will listen. The third argument is the
89-
the handler object defined previously. This example can be run from
90-
a command line as follows:
91-
92-
::
93-
94-
shell$ ./hello_world_server 0.0.0.0 80
128+
the handler object defined previously.
129+
130+
.. note:: In this example, the server is specifically made to be single-threaded.
131+
In a multi-threaded server, you would invoke the ``hello_world::run`` member
132+
method in a set of threads. In a multi-threaded environment you would also
133+
make sure that the handler does all the necessary synchronization for shared
134+
resources across threads. The handler is passed by reference to the server
135+
constructor and you should ensure that any calls to the ``operator()`` overload
136+
are thread-safe.
95137

‎_sources/http.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ request looks trivially simple:
4141

4242
using namespace boost::network;
4343
http::client client;
44-
http::request request("http://www.boost.org/");
45-
http::response response = client.get(request);
44+
http::client::request request("http://www.boost.org/");
45+
http::client::response response = client.get(request);
4646

4747
Accessing data from ``http::response`` is also done using directives.
4848
To get the response headers, we use the ``headers`` directive which
@@ -129,7 +129,7 @@ HTTP OK response (200).
129129
HTTP URI
130130
````````
131131

132-
Firstly,cpp-netlib provides a specialization and ``typedef`` for an
132+
:mod:`cpp-netlib` provides a specialization and ``typedef`` for an
133133
HTTP URI:
134134

135135
.. code-block:: c++

‎_sources/index.txt

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
.. :Authors: Glyn Matthews <glyn.matthews@gmail.com>
1414
.. Dean Michael Berris <mikhailberis@gmail.com>
15-
.. :Date:Sep 19, 2010
15+
.. :Date:Oct 9, 2010
1616
.. :Version: 0.7
1717
.. :Description: Complete user documentation, with examples, for the :mod:`cpp-netlib`.
1818
.. :Copyright: Copyright Glyn Matthews, Dean Michael Berris 2008-2010.
@@ -33,11 +33,62 @@ some point in the future be submitted for review into Boost. A
3333
presentation about :mod:`cpp-netlib` was given at `BoostCon 2010`_,
3434
for which the `slides`_ and the `paper`_ can be found on-line.
3535

36+
Sneak Peak
37+
==========
38+
39+
The :mod:`cpp-netlib` allows you to write semantically consistent code for
40+
making different kinds of higher level network applications.
41+
42+
The library allows for writing simple code like:
43+
44+
.. code-block:: c++
45+
46+
using namespace boost::network;
47+
using namespace boost::network::http;
48+
49+
client::request request_("http://www.boost.org/");
50+
request_ << header("Connection", "close");
51+
client client_;
52+
client::response response_ = client_.get(request);
53+
std::string body = body(response_);
54+
55+
For simple C++ HTTP client applications.
56+
57+
The :mod:`cpp-netlib` is being developed for eventual submission to Boost_.
58+
59+
Download
60+
========
61+
62+
You can download the latest releases of the library at:
63+
64+
http://github.com/mikhailberis/cpp-netlib/downloads
65+
66+
You can also get the latest developments from the Git_ repository at:
67+
68+
git://github.com/mikhailberis/cpp-netlib.git
69+
70+
You can find more information about the progress of the development by checking
71+
the GitHub_ project page at:
72+
73+
http://github.com/mikhailberis/cpp-netlib
74+
75+
Support
76+
=======
77+
78+
You can ask questions, join the discussion, and report issues to the developers
79+
mailing list by joining via:
80+
81+
https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel
82+
83+
You may also file issues on the Github_ issue tracker at:
84+
85+
http://github.com/mikhailberis/cpp-netlib/issues
86+
3687
Contents
3788
========
3889

3990
.. toctree::
40-
:maxdepth:1
91+
:maxdepth:2
4192

4293
whats_new.rst
4394
getting_started.rst
@@ -52,3 +103,6 @@ Contents
52103
.. _`BoostCon 2010`: http://www.boostcon.com/
53104
.. _`slides`: http://www.filetolink.com/b0e89d06
54105
.. _`paper`: http://github.com/downloads/mikhailberis/cpp-netlib-boostcon-paper/cpp-netlib.pdf
106+
.. _Git: http://git-scm.com/
107+
.. _GitHub: http://github.com/
108+

‎_sources/message.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ following common parts:
2424

2525
This division is purely logical -- in the underlying implementation,
2626
the message type can choose to have different means of storing the
27-
data,dependinn on the type used to tag the message. This section
27+
data,depending on the type used to tag the message. This section
2828
covers the `Message Concept`_ as well as the `basic_message`_
2929
implementation.
3030

@@ -39,6 +39,7 @@ properties of messages.
3939
**Legend**
4040

4141
:M: The message type.
42+
:H: A headers container type.
4243
:m,n: An instance of **M**.
4344
:S: A string type.
4445
:s,k,v: An instance of **S**.
@@ -58,20 +59,31 @@ properties of messages.
5859
+----------------------------+----------------------+-----------------------------------------+
5960
| ``destination(m);`` | unspecified | Retrieve the destination of ``m``. |
6061
+----------------------------+----------------------+-----------------------------------------+
61-
| ``headers(m);`` | ``Range<Pair<S,S>>`` | Get the range of headers of ``m``. |
62+
| ``headers(m);`` | unspecified | Get the range of headers of ``m``. The |
63+
| | | result should be convertible to ``H`` |
6264
+----------------------------+----------------------+-----------------------------------------+
6365
| ``body(m);`` | unspecified | Retrieve the body of ``m``. |
6466
+----------------------------+----------------------+-----------------------------------------+
6567
| ``m << source(s);`` | ``M &`` | Set the source of ``m``. |
6668
+----------------------------+----------------------+-----------------------------------------+
69+
| ``source(m,s);`` | ``M &`` | Set the source of ``m``. |
70+
+----------------------------+----------------------+-----------------------------------------+
6771
| ``m << destination(s);`` | ``M &`` | Set the destination of ``m``. |
6872
+----------------------------+----------------------+-----------------------------------------+
73+
| ``destination(m,s);`` | ``M &`` | Set the destination of ``m``. |
74+
+----------------------------+----------------------+-----------------------------------------+
6975
| ``m << header(k, v);`` | ``M &`` | Add a header to ``m``. |
7076
+----------------------------+----------------------+-----------------------------------------+
77+
| ``add_header(m, k, v);`` | ``M &`` | Add a header to ``m``. |
78+
+----------------------------+----------------------+-----------------------------------------+
7179
| ``m << remove_header(k);`` | ``M &`` | Remove a header from ``m``. |
7280
+----------------------------+----------------------+-----------------------------------------+
81+
| ``remove_header(m, k);`` | ``M &`` | Remove a header from ``m``. |
82+
+----------------------------+----------------------+-----------------------------------------+
7383
| ``m << body(s);`` | ``M &`` | Set the body of ``m``. |
7484
+----------------------------+----------------------+-----------------------------------------+
85+
| ``body(m,s);`` | ``M &`` | Set the body of ``m``. |
86+
+----------------------------+----------------------+-----------------------------------------+
7587

7688
Types that model the Message Concept are meant to encapsulate data
7789
that has a source, a destination, one or more named headers, and a

‎_static/cpp-netlib.css

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
@importurl(reset-fonts-grids.css);
22

3-
html,body {background:url(./background.jpg)}
4-
body {font:14px Helvetica, arial, sans-serif;color:black}
5-
#custom-doc {width:76.54em;*width:74.69em;min-width:995px;max-width:100em;margin:auto;text-align:left;padding-top:16px;margin-top:0}
3+
html,body {background-image:url(./background.jpg);background-repeat:no-repeat;background-position:right top;background-attachment:fixed}
4+
body {font:16px"Times New Roman", Lucida,serif;color:black}
5+
#custom-doc {width:80%;*width:720px;min-width:720px;max-width:960px;margin:auto;text-align:left;padding-top:16px;margin-top:0}
66
#hd {padding:4px012px0}
77
#bd {background:#C5D88A}
88
#ft {color:#C5D88A;font-size:90%;padding-bottom:2em}
99

1010
pre {
1111
font-family: Monaco, monospace;
12-
font-size:12px;
12+
font-size:14px;
1313
background:#333;
1414
background:-moz-linear-gradient(-90deg,#333,#22260%);
1515
background:-webkit-gradient(linear,0 top,0 bottom,from(#333),to(#222),color-stop(60%,#222));
1616
border-width:1px0;
1717
margin:1em0;
1818
padding:.3em.4em;
19-
overflow:hidden;
19+
overflow:auto;
2020
line-height:1.3em;
2121
color:#CCC;
2222
border-radius:3px;
@@ -29,14 +29,14 @@ pre {
2929
/*** links ***/
3030
a {text-decoration: none}
3131
aimg {border: none}
32-
a:link,a:visited {color:blue}
33-
#bda:link,#bda:visited {color:blue;text-decoration:underline}
32+
a:link,a:visited {color:#f60}
33+
#bda:link,#bda:visited {color:#f60;text-decoration:underline}
3434
#bd#sidebara:link,#bd#sidebara:visited {color:#333;text-decoration:none}
3535
a:hover {color:#000}
36-
#bda:hover {background-color:#E0FFB8;color:#234f32;text-decoration:none}
37-
#bd#sidebara:hover {color:#ffe761;background:none}
36+
#bda:hover {background-color:#FF9955;color:black;text-decoration:none}
37+
#bd#sidebara:hover {color:#FF9955;background:none}
3838
h2a,h3a,h4a {text-decoration:none!important}
39-
a.referenceem {color:blue;font-style:normal;font-weight:bold;}
39+
a.referenceem {color:#FF9955;font-style:normal;font-weight:bold;}
4040

4141
/*** sidebar ***/
4242
#sidebardiv.sphinxsidebarwrapper {font-size:92%;margin-right:14px}
@@ -72,8 +72,8 @@ background:none repeat scroll 0 0 #F0F7F0;
7272
/*** basic styles ***/
7373
dd {margin-left:15px}
7474
h1,h2,h3,h4 {margin-top:1em;font-weight:normal}
75-
h1 {font-size:218%;margin-top:0.6em;margin-bottom:.4em;line-height:1.1em}
76-
h2 {font-size:175%;margin-bottom:.6em;line-height:1.2em;color:#092e20}
75+
h1 {font-size:218%;font-weight:bold;margin-top:0.6em;margin-bottom:.4em;line-height:1.1em}
76+
h2 {font-size:175%;font-weight:bold;margin-bottom:.6em;line-height:1.2em;color:#092e20}
7777
h3 {font-size:150%;font-weight:bold;margin-bottom:.2em;color:#487858}
7878
h4 {font-size:125%;font-weight:bold;margin-top:1.5em;margin-bottom:3px}
7979
div.figure {text-align: center}
@@ -82,7 +82,7 @@ hr { color:#ccc; background-color:#ccc; height:1px; border:0}
8282
p,ul,dl {margin-top:.6em;color:#333}
8383
#yui-maindiv.yui-bimg {max-width:50em;margin-left: auto;margin-right: auto;display: block;margin-top:10px;margin-bottom:10px}
8484
caption {font-size:1em;font-weight:bold;margin-top:0.5em;margin-bottom:0.5em;margin-left:2px;text-align: center}
85-
blockquote {padding:01em;margin:1em0;font:125%/1.2em"Trebuchet MS",sans-serif;color:#234f32}
85+
blockquote {padding:01em;margin:1em0;font:"Times New Roman", serif;color:#234f32}
8686
strong {font-weight: bold}
8787
em {font-style: italic}
8888
ins {font-weight: bold;text-decoration: none}

‎directives.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<head>
88
<metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>
99

10-
<title>Directives &mdash;The C++ Network Library v0.7 documentation</title>
10+
<title>Directives &mdash;cpp-netlib v0.7 documentation</title>
1111
<linkrel="stylesheet"href="_static/cpp-netlib.css"type="text/css"/>
1212
<linkrel="stylesheet"href="_static/pygments.css"type="text/css"/>
1313
<scripttype="text/javascript">
@@ -22,17 +22,17 @@
2222
<scripttype="text/javascript"src="_static/jquery.js"></script>
2323
<scripttype="text/javascript"src="_static/underscore.js"></script>
2424
<scripttype="text/javascript"src="_static/doctools.js"></script>
25-
<linkrel="top"title="The C++ Network Library v0.7 documentation"href="index.html"/>
25+
<linkrel="top"title="cpp-netlib v0.7 documentation"href="index.html"/>
2626
<linkrel="up"title="Techniques"href="techniques.html"/>
2727
<linkrel="next"title="Static and dynamic polymorphism"href="polymorphism.html"/>
2828
<linkrel="prev"title="Tag metafunctions"href="tag_metafunctions.html"/>
2929
</head>
3030
<body>
3131

3232
<divclass="document">
33-
<divid="custom-doc"class="yui-t6">
33+
<divid="custom-doc"class="yui-t4">
3434
<divid="hd">
35-
<h1><ahref="index.html">The C++ Network Library v0.7 documentation</a></h1>
35+
<h1><ahref="index.html">cpp-netlib v0.7 documentation</a></h1>
3636
<divid="global-nav">
3737
<atitle="Home page"href="index.html">Home</a> |
3838
<atitle="Table of contents"href="contents.html">Table of contents</a> |
@@ -159,7 +159,7 @@ <h3>Browse</h3>
159159
<h3>You are here:</h3>
160160
<ul>
161161
<li>
162-
<ahref="index.html">The C++ Network Library v0.7 documentation</a>
162+
<ahref="index.html">cpp-netlib v0.7 documentation</a>
163163

164164
<ul><li><ahref="techniques.html">Techniques</a>
165165

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp