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

Commit57e59f9

Browse files
committed
Merge pull request#9 from susnux/fix-doc-0.11.2
Fixed documentation for 0.11.2, thisfixescpp-netlib/cpp-netlib#581
2 parents0ed7f05 +c0d3350 commit57e59f9

File tree

4 files changed

+102
-131
lines changed

4 files changed

+102
-131
lines changed

‎0.11.2/_sources/examples/http/hello_world_server.txt

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ simple response to any HTTP request.
1919
.. code-block:: c++
2020

2121
#include <boost/network/protocol/http/server.hpp>
22-
#include <string>
2322
#include <iostream>
2423

2524
namespace http = boost::network::http;
@@ -28,16 +27,19 @@ simple response to any HTTP request.
2827
typedef http::server<hello_world> server;
2928

3029
struct hello_world {
31-
void operator() (server::request const &request,
32-
server::response &response) {
33-
std::string ip = source(request);
34-
response = server::response::stock_reply(
35-
server::response::ok, std::string("Hello, ") + ip + "!");
30+
void operator()(server::request const &request, server::response &response) {
31+
server::string_type ip = source(request);
32+
unsigned int port = request.source_port;
33+
std::ostringstream data;
34+
data << "Hello, " << ip << ':' << port << '!';
35+
response = server::response::stock_reply(server::response::ok, data.str());
36+
}
37+
void log(const server::string_type& message) {
38+
std::cerr << "ERROR: " << message << std::endl;
3639
}
3740
};
3841

39-
int
40-
main(int argc, char * argv[]) {
42+
int main(int argc, char *argv[]) {
4143

4244
if (argc != 3) {
4345
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
@@ -46,7 +48,8 @@ simple response to any HTTP request.
4648

4749
try {
4850
hello_world handler;
49-
server server_(argv[1], argv[2], handler);
51+
server::options options(handler);
52+
server server_(options.address(argv[1]).port(argv[2]));
5053
server_.run();
5154
}
5255
catch (std::exception &e) {
@@ -100,34 +103,39 @@ This header contains all the code needed to develop an HTTP server with
100103
typedef http::server<hello_world> server;
101104

102105
struct hello_world {
103-
void operator () (server::request const &request,
104-
server::response &response) {
105-
std::string ip = source(request);
106-
response = server::response::stock_reply(
107-
server::response::ok, std::string("Hello, ") + ip + "!");
106+
void operator()(server::request const &request, server::response &response) {
107+
server::string_type ip = source(request);
108+
unsigned int port = request.source_port;
109+
std::ostringstream data;
110+
data << "Hello, " << ip << ':' << port << '!';
111+
response = server::response::stock_reply(server::response::ok, data.str());
112+
}
113+
void log(const server::string_type& message) {
114+
std::cerr << "ERROR: " << message << std::endl;
108115
}
109116
};
110117

111-
``hello_world`` is a functor class which handles HTTP requests. All
112-
the operator does here is return an HTTP response with HTTP code 200
113-
and the body ``"Hello, <ip>!"``. The ``<ip>`` in this case would be
114-
the IP address of the client that made the request.
118+
``hello_world`` is a functor class which handles HTTP requests.
119+
Allthe operator does here is return an HTTP response with HTTP code 200
120+
and the body ``"Hello, <ip>:<port>!"``. The ``<ip>`` in this case would be
121+
the IP address of the client that made the request and ``<port>`` the clients port.
115122

116123
There are a number of pre-defined stock replies differentiated by
117124
status code with configurable bodies.
118-
119125
All the supported enumeration values for the response status codes can be found
120126
in ``boost/network/protocol/http/impl/response.ipp``.
121127

122128
.. code-block:: c++
123129

124130
hello_world handler;
125-
server server_(argv[1], argv[2], handler);
131+
server::options options(handler);
132+
server server_(options.address(argv[1]).port(argv[2]));
126133
server_.run();
127134

128-
The first two arguments to the ``server`` constructor are the host and
129-
the port on which the server will listen. The third argument is the
130-
the handler object defined previously.
135+
The ``server`` constructor requires an object of the ``options`` class,
136+
this object stores all needed options, especially the host and
137+
the port on which the server will listen.
138+
The ``options`` constructor's single argument is the handler object defined previously.
131139

132140
.. note:: In this example, the server is specifically made to be single-threaded.
133141
In a multi-threaded server, you would invoke the ``hello_world::run`` member

‎0.11.2/_sources/examples/http/twitter_search.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The code
6464
`rapidjson`_, a header-only library that is released under
6565
the `MIT License`_.
6666

67-
.. _`rapidjson`:http://code.google.com/p/rapidjson/
67+
.. _`rapidjson`:https://github.com/miloyip/rapidjson
6868
.. _`MIT License`: http://www.opensource.org/licenses/mit-license.php
6969

7070
Building and running ``twitter_search``

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp