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

Commit2f2890f

Browse files
committed
Lots of debugging.
At this point in the development, I'm stuck as to why the asynchronousreads aren't returning data after writing the request down through thesockets. I may just be missing some crucial setting on the createdsockets to properly enable the asynchronous processing, or the HTTPrequest isn't well-formed, or there's some deadlock that I'm not seeing.I'll debug this after a few hours of sleep.Upped the version to 0.10.0a (a for the alpha) and hopefully this getsfunctional sooner than later.
1 parent64f4ef9 commit2f2890f

File tree

16 files changed

+112
-118
lines changed

16 files changed

+112
-118
lines changed

‎boost/network/constants.hpp‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct constants {
2525
staticcharconst *accept_encoding();
2626
staticcharconst *default_accept_encoding();
2727
staticcharconst *user_agent();
28+
staticcharconst *default_user_agent();
2829
staticcharconst *cpp_netlib_slash();
2930
staticcharquestion_mark_char();
3031
staticcharhash_char();
@@ -33,10 +34,6 @@ struct constants {
3334
staticcharconst *https();
3435
};
3536

36-
#ifdef BOOST_NETWORK_NO_LIB
37-
#include<boost/network/constants.ipp>
38-
#endif
39-
4037
}// namespace network
4138

4239
}// namespace boost

‎boost/network/constants.ipp‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/constants.hpp>
11+
#include<boost/network/version.hpp>
1112

1213
namespaceboost {namespacenetwork {
1314

1415
charconst *constants::crlf() {
15-
staticchar crlf_[] ={'\r','\n',0 };
16+
staticchar crlf_[] ="\r\n";
1617
return crlf_;
1718
}
1819

1920
charconst *constants::dot() {
20-
staticchar dot_[] ={'.',0 };
21+
staticchar dot_[] =".";
2122
return dot_;
2223
}
2324

2425
charconstants::dot_char() {return'.'; }
2526

2627
charconst *constants::http_slash() {
27-
staticchar http_slash_[] ={'H','T','T','P','/',0 };
28+
staticchar http_slash_[] ="HTTP/";
2829
return http_slash_;
2930
}
3031

@@ -103,16 +104,12 @@ char constants::hash_char() {
103104
}
104105

105106
charconst *constants::connection() {
106-
staticchar connection_[] = {
107-
'C','o','n','n','e','c','t','i','o','n',0
108-
};
107+
staticchar connection_[] ="Connection";
109108
return connection_;
110109
}
111110

112111
charconst *constants::close() {
113-
staticchar close_[] = {
114-
'C','l','o','s','e',0
115-
};
112+
staticchar close_[] ="close";
116113
return close_;
117114
}
118115

@@ -121,6 +118,11 @@ char const * constants::https() {
121118
return https_;
122119
}
123120

121+
charconst *constants::default_user_agent() {
122+
staticchar user_agent_[] ="cpp-netlib/" BOOST_NETLIB_VERSION;
123+
return user_agent_;
124+
}
125+
124126
}/* network*/
125127

126128
}/* boost*/

‎boost/network/message/message.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct message_pimpl;
2222
structmessage : message_base {
2323
// Nested types
2424
typedef iterator_range<
25-
shared_container_iterator<std::multimap<std::string, std::string> >>
25+
std::multimap<std::string, std::string>::const_iterator>
2626
headers_range;
2727

2828
// Constructors

‎boost/network/message/wrappers/headers.hpp‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)
66

7-
#ifndef__NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
8-
#define__NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
7+
#ifndefNETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
8+
#defineNETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__
99

1010
#include<map>
11-
#include<boost/shared_container_iterator.hpp>
12-
#include<boost/range/iterator_range.hpp>
13-
#include<boost/range/functions.hpp>
14-
#include<boost/network/message/message_base.hpp>
1511

1612
namespaceboost {namespacenetwork {
1713

14+
structmessage_base;
15+
1816
/** headers wrapper for messages.
1917
*
2018
* This exposes an interface similar to a map, indexable
@@ -25,21 +23,10 @@ namespace boost { namespace network {
2523
*/
2624
structheaders_wrapper {
2725
typedef std::multimap<std::string, std::string> container_type;
28-
typedef shared_container_iterator<container_type> iterator;
29-
typedef iterator_range<iterator> range_type;
30-
3126
explicitheaders_wrapper(message_baseconst & message);
32-
range_typeoperator[] (std::stringconst & key)const;
33-
operatorrange_type ()const;
3427
operatorcontainer_type ()const;
35-
container_type::size_typecount()const;
36-
container_type::size_typecount(std::stringconst &key)const;
37-
iteratorbegin()const;
38-
iteratorend()const;
3928
private:
40-
voidinit_cache_all()const;
4129
message_baseconst & message_;
42-
mutable shared_ptr<container_type> cache_;
4330
};
4431

4532
/// Factory method to create the right wrapper object
@@ -52,8 +39,4 @@ headers(message_base const & message_) {
5239

5340
}// namespace boost
5441

55-
#ifdef BOOST_NETWORK_NO_LIB
56-
#include<boost/network/message/wrappers/headers.ipp>
57-
#endif
58-
5942
#endif// __NETWORK_MESSAGE_WRAPPERS_HEADERS_HPP__

‎boost/network/message/wrappers/headers.ipp‎

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/message/wrappers/headers.hpp>
11+
#include<boost/network/message/message_base.hpp>
1112
#include<boost/function.hpp>
1213

1314
namespaceboost {namespacenetwork {
@@ -16,45 +17,6 @@ headers_wrapper::headers_wrapper(message_base const & message)
1617
: message_(message)
1718
{}
1819

19-
headers_wrapper::range_type headers_wrapper::operator[] (std::stringconst & key)const {
20-
this->init_cache_all();
21-
std::pair<container_type::iterator, container_type::iterator> p =
22-
cache_->equal_range(key);
23-
returnboost::make_iterator_range(
24-
boost::make_shared_container_iterator(
25-
p.first, cache_),
26-
boost::make_shared_container_iterator(
27-
p.second, cache_));
28-
}
29-
30-
headers_wrapper::container_type::size_type
31-
headers_wrapper::count(std::stringconst & key)const {
32-
this->init_cache_all();
33-
return cache_->size();
34-
}
35-
36-
headers_wrapper::iteratorheaders_wrapper::begin()const {
37-
this->init_cache_all();
38-
container_type::iterator begin = cache_->begin();
39-
returnmake_shared_container_iterator(begin, cache_);
40-
}
41-
42-
headers_wrapper::iteratorheaders_wrapper::end()const {
43-
this->init_cache_all();
44-
container_type::iterator end = cache_->end();
45-
returnmake_shared_container_iterator(end, cache_);
46-
};
47-
48-
headers_wrapper::operatorheaders_wrapper::range_type ()const {
49-
this->init_cache_all();
50-
returnmake_shared_container_range(cache_);
51-
};
52-
53-
headers_wrapper::operatorheaders_wrapper::container_type ()const {
54-
this->init_cache_all();
55-
return *cache_;
56-
}
57-
5820
template<classMap>
5921
structkv_inserter {
6022
kv_inserter(Map & m)
@@ -66,14 +28,11 @@ struct kv_inserter {
6628
Map & m_;
6729
};
6830

69-
voidheaders_wrapper::init_cache_all()const {
70-
if (!cache_.get()) {
71-
cache_.reset(new (std::nothrow) container_type);
72-
if (!cache_.get())
73-
BOOST_THROW_EXCEPTION(std::runtime_error(
74-
"Cannot allocate cache multimap for headers wrapper."));
75-
message_.get_headers(kv_inserter<container_type>(*cache_));
76-
}
31+
headers_wrapper::operatorheaders_wrapper::container_type ()const {
32+
container_type tmp;
33+
kv_inserter<container_type>inserter(tmp);
34+
message_.get_headers(inserter);
35+
return tmp;
7736
}
7837

7938
}/* network*/

‎boost/network/protocol/http/algorithms/linearize.hpp‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace boost { namespace network { namespace http {
6363
, accept_mime =consts::default_accept_mime()
6464
, accept_encoding =consts::accept_encoding()
6565
, default_accept_encoding =consts::default_accept_encoding()
66+
, default_user_agent =consts::default_user_agent()
67+
, user_agent =consts::user_agent()
6668
, crlf =consts::crlf()
6769
, host_const =consts::host()
6870
, connection =consts::connection()
@@ -124,11 +126,12 @@ namespace boost { namespace network { namespace http {
124126
boost::copy(default_accept_encoding, oi);
125127
boost::copy(crlf, oi);
126128
}
127-
typedef headers_wrapper::range_type headers_range;
128-
typedeftypename range_iterator<headers_range>::type headers_iterator;
129-
headers_range request_headers =boost::network::headers(request);
129+
typedef headers_wrapper::container_type headers_container;
130+
typedefheaders_container::const_iterator headers_iterator;
131+
headers_containerconst & request_headers =boost::network::headers(request);
130132
headers_iterator iterator =boost::begin(request_headers),
131133
end =boost::end(request_headers);
134+
bool has_user_agent =false;
132135
for (; iterator != end; ++iterator) {
133136
string_type header_name =name(*iterator),
134137
header_value =value(*iterator);
@@ -137,6 +140,15 @@ namespace boost { namespace network { namespace http {
137140
*oi =consts::space_char();
138141
boost::copy(header_value, oi);
139142
boost::copy(crlf, oi);
143+
boost::to_lower(header_name);
144+
has_user_agent = has_user_agent || header_name =="user-agent";
145+
}
146+
if (!has_user_agent) {
147+
boost::copy(user_agent, oi);
148+
*oi =consts::colon_char();
149+
*oi =consts::space_char();
150+
boost::copy(default_user_agent, oi);
151+
boost::copy(crlf, oi);
140152
}
141153
boost::copy(crlf, oi);
142154
boost::iterator_range<std::string::const_iterator> body_data =

‎boost/network/protocol/http/client/connection/async_normal.ipp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
163163
if (!ec) {
164164
BOOST_NETWORK_MESSAGE("connected successfully");
165165
BOOST_ASSERT(connection_delegate_.get() !=0);
166+
BOOST_NETWORK_MESSAGE("scheduling write...");
166167
connection_delegate_->write(command_streambuf,
167168
request_strand_.wrap(
168169
boost::bind(
@@ -203,7 +204,9 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
203204
body_callback_function_type callback,
204205
boost::system::error_codeconst & ec,
205206
std::size_t bytes_transferred) {
207+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::handle_sent_request(...)");
206208
if (!ec) {
209+
BOOST_NETWORK_MESSAGE("request sent successfuly; scheduling partial read...");
207210
connection_delegate_->read_some(
208211
boost::asio::mutable_buffers_1(this->part.c_array(),
209212
this->part.size()),
@@ -214,16 +217,20 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
214217
placeholders::error,
215218
placeholders::bytes_transferred)));
216219
}else {
220+
BOOST_NETWORK_MESSAGE("request sent unsuccessfully; setting errors");
217221
set_errors(ec);
218222
}
219223
}
220224

221225
voidhandle_received_data(state_t state,bool get_body, body_callback_function_type callback, boost::system::error_codeconst & ec, std::size_t bytes_transferred) {
226+
BOOST_NETWORK_MESSAGE("http_async_connection_pimpl::handle_received_data(...)");
222227
if (!ec || ec == boost::asio::error::eof) {
228+
BOOST_NETWORK_MESSAGE("processing data chunk, no error encountered so far...");
223229
logic::tribool parsed_ok;
224230
size_t remainder;
225231
switch(state) {
226232
case version:
233+
BOOST_NETWORK_MESSAGE("parsing version...");
227234
parsed_ok =
228235
this->parse_version(request_strand_.wrap(
229236
boost::bind(
@@ -235,6 +242,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
235242
bytes_transferred);
236243
if (!parsed_ok ||indeterminate(parsed_ok))return;
237244
case status:
245+
BOOST_NETWORK_MESSAGE("parsing status...");
238246
parsed_ok =
239247
this->parse_status(request_strand_.wrap(
240248
boost::bind(
@@ -246,6 +254,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
246254
bytes_transferred);
247255
if (!parsed_ok ||indeterminate(parsed_ok))return;
248256
case status_message:
257+
BOOST_NETWORK_MESSAGE("parsing status message...");
249258
parsed_ok =
250259
this->parse_status_message(
251260
request_strand_.wrap(
@@ -260,6 +269,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
260269
);
261270
if (!parsed_ok ||indeterminate(parsed_ok))return;
262271
case headers:
272+
BOOST_NETWORK_MESSAGE("parsing headers...");
263273
// In the following, remainder is the number of bytes that remain
264274
// in the buffer. We need this in the body processing to make sure
265275
// that the data remaining in the buffer is dealt with before
@@ -280,6 +290,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
280290
if (!parsed_ok ||indeterminate(parsed_ok))return;
281291

282292
if (!get_body) {
293+
BOOST_NETWORK_MESSAGE("not getting body...");
283294
// We short-circuit here because the user does not
284295
// want to get the body (in the case of a HEAD
285296
// request).
@@ -288,10 +299,12 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
288299
this->source_promise.set_value("");
289300
this->part.assign('\0');
290301
this->response_parser_.reset();
302+
BOOST_NETWORK_MESSAGE("processing done.");
291303
return;
292304
}
293305

294306
if (callback) {
307+
BOOST_NETWORK_MESSAGE("callback provided, processing body...");
295308
// Here we deal with the spill-over data from the
296309
// headers processing. This means the headers data
297310
// has already been parsed appropriately and we're
@@ -323,6 +336,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
323336
placeholders::error,
324337
placeholders::bytes_transferred)));
325338
}else {
339+
BOOST_NETWORK_MESSAGE("no callback provided, appending to body...");
326340
// Here we handle the body data ourself and append to an
327341
// ever-growing string buffer.
328342
this->parse_body(
@@ -338,12 +352,15 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
338352
}
339353
return;
340354
case body:
355+
BOOST_NETWORK_MESSAGE("parsing body...");
341356
if (ec == boost::asio::error::eof) {
357+
BOOST_NETWORK_MESSAGE("end of the line.");
342358
// Here we're handling the case when the connection has been
343359
// closed from the server side, or at least that the end of file
344360
// has been reached while reading the socket. This signals the end
345361
// of the body processing chain.
346362
if (callback) {
363+
BOOST_NETWORK_MESSAGE("callback provided, invoking callback...");
347364
buffer_type::const_iterator begin =
348365
this->part.begin(),
349366
end = begin;
@@ -354,6 +371,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
354371
// it appropriately.
355372
callback(make_iterator_range(begin, end), ec);
356373
}else {
374+
BOOST_NETWORK_MESSAGE("no callback provided, appending to body...");
357375
std::string body_string;
358376
std::swap(body_string,this->partial_parsed);
359377
body_string.append(
@@ -368,9 +386,11 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
368386
this->part.assign('\0');
369387
this->response_parser_.reset();
370388
}else {
389+
BOOST_NETWORK_MESSAGE("connection still active...");
371390
// This means the connection has not been closed yet and we want to get more
372391
// data.
373392
if (callback) {
393+
BOOST_NETWORK_MESSAGE("callback provided, invoking callback...");
374394
// Here we have a body_handler callback. Let's invoke the
375395
// callback from here and make sure we're getting more data
376396
// right after.
@@ -392,6 +412,7 @@ struct http_async_connection_pimpl : boost::enable_shared_from_this<http_async_c
392412
placeholders::error,
393413
placeholders::bytes_transferred)));
394414
}else {
415+
BOOST_NETWORK_MESSAGE("no callback provided, appending to body...");
395416
// Here we don't have a body callback. Let's
396417
// make sure that we deal with the remainder
397418
// from the headers part in case we do have data

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp