|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r49482 - in trunk: boost/asio/impl libs/asio/test
From: chris_at_[hidden]
Date: 2008-10-29 08:49:06
Author: chris_kohlhoff
Date: 2008-10-29 08:49:05 EDT (Wed, 29 Oct 2008)
New Revision: 49482
URL: http://svn.boost.org/trac/boost/changeset/49482
Log:
Fix problem in read_until's match_condition handling when the delimiter
lies at the end of the data.
Text files modified:
trunk/boost/asio/impl/read_until.ipp | 69 +++++------
trunk/libs/asio/test/read_until.cpp | 237 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 267 insertions(+), 39 deletions(-)
Modified: trunk/boost/asio/impl/read_until.ipp
==============================================================================
--- trunk/boost/asio/impl/read_until.ipp (original)
+++ trunk/boost/asio/impl/read_until.ipp 2008-10-29 08:49:05 EDT (Wed, 29 Oct 2008)
@@ -278,19 +278,16 @@
// Look for a match.
std::pair<iterator, bool> result = match_condition(start, end);
- if (result.first != end)
+ if (result.second)
{
- if (result.second)
- {
- // Full match. We're done.
- ec = boost::system::error_code();
- return result.first - begin;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = result.first - begin;
- }
+ // Full match. We're done.
+ ec = boost::system::error_code();
+ return result.first - begin;
+ }
+ else if (result.first != end)
+ {
+ // Partial match. Next search needs to start from beginning of match.
+ next_search_start = result.first - begin;
}
else
{
@@ -858,20 +855,17 @@
// Look for a match.
std::pair<iterator, bool> result = match_condition_(start, end);
- if (result.first != end)
+ if (result.second)
{
- if (result.second)
- {
- // Full match. We're done.
- std::size_t bytes = result.first - begin;
- handler_(ec, bytes);
- return;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start_ = result.first - begin;
- }
+ // Full match. We're done.
+ std::size_t bytes = result.first - begin;
+ handler_(ec, bytes);
+ return;
+ }
+ else if (result.first != end)
+ {
+ // Partial match. Next search needs to start from beginning of match.
+ next_search_start_ = result.first - begin;
}
else
{
@@ -951,21 +945,18 @@
// Look for a match.
std::size_t next_search_start;
std::pair<iterator, bool> result = match_condition(begin, end);
- if (result.first != end)
+ if (result.second)
{
- if (result.second)
- {
- // Full match. We're done.
- boost::system::error_code ec;
- std::size_t bytes = result.first - begin;
- s.get_io_service().post(detail::bind_handler(handler, ec, bytes));
- return;
- }
- else
- {
- // Partial match. Next search needs to start from beginning of match.
- next_search_start = result.first - begin;
- }
+ // Full match. We're done.
+ boost::system::error_code ec;
+ std::size_t bytes = result.first - begin;
+ s.get_io_service().post(detail::bind_handler(handler, ec, bytes));
+ return;
+ }
+ else if (result.first != end)
+ {
+ // Partial match. Next search needs to start from beginning of match.
+ next_search_start = result.first - begin;
}
else
{
Modified: trunk/libs/asio/test/read_until.cpp
==============================================================================
--- trunk/libs/asio/test/read_until.cpp (original)
+++ trunk/libs/asio/test/read_until.cpp 2008-10-29 08:49:05 EDT (Wed, 29 Oct 2008)
@@ -121,52 +121,81 @@
boost::system::error_code ec;
s.reset(read_data, sizeof(read_data));
+ sb1.consume(sb1.size());
std::size_t length = boost::asio::read_until(s, sb1, 'Z');
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, 'Z');
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, 'Z');
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, 'Z', ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, 'Z', ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, 'Z', ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, 'Z', ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, 'Z', ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, 'Z', ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
+
+ s.reset(read_data, sizeof(read_data));
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, 'Y', ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, 'Y', ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, 'Y', ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
}
void test_string_read_until()
@@ -178,52 +207,81 @@
boost::system::error_code ec;
s.reset(read_data, sizeof(read_data));
+ sb1.consume(sb1.size());
std::size_t length = boost::asio::read_until(s, sb1, "XYZ");
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, "XYZ");
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, "XYZ");
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, "XYZ", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, "XYZ", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, "XYZ", ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, "XYZ", ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, "XYZ", ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, "XYZ", ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
+
+ s.reset(read_data, sizeof(read_data));
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, "WXY", ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, "WXY", ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, "WXY", ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
}
class match_char
@@ -262,52 +320,81 @@
boost::system::error_code ec;
s.reset(read_data, sizeof(read_data));
+ sb1.consume(sb1.size());
std::size_t length = boost::asio::read_until(s, sb1, match_char('Z'));
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, match_char('Z'));
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, match_char('Z'));
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, match_char('Z'), ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, match_char('Z'), ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb1.consume(sb1.size());
length = boost::asio::read_until(s, sb1, match_char('Z'), ec);
BOOST_CHECK(!ec);
BOOST_CHECK(length == 26);
s.reset(read_data, sizeof(read_data));
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, match_char('Z'), ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
s.reset(read_data, sizeof(read_data));
s.next_read_length(1);
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, match_char('Z'), ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
s.reset(read_data, sizeof(read_data));
s.next_read_length(10);
+ sb2.consume(sb2.size());
length = boost::asio::read_until(s, sb2, match_char('Z'), ec);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
+
+ s.reset(read_data, sizeof(read_data));
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, match_char('Y'), ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, match_char('Y'), ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ sb2.consume(sb2.size());
+ length = boost::asio::read_until(s, sb2, match_char('Y'), ec);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
}
void async_read_handler(
@@ -333,6 +420,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, 'Z',
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -347,6 +435,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, 'Z',
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -361,6 +450,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, 'Z',
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -374,6 +464,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, 'Z',
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -388,6 +479,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, 'Z',
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -402,6 +494,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, 'Z',
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -410,6 +503,50 @@
BOOST_CHECK(called);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
+
+ s.reset(read_data, sizeof(read_data));
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, 'Y',
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, 'Y',
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, 'Y',
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
}
void test_string_async_read_until()
@@ -426,6 +563,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, "XYZ",
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -440,6 +578,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, "XYZ",
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -454,6 +593,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, "XYZ",
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -467,6 +607,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, "XYZ",
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -481,6 +622,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, "XYZ",
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -495,6 +637,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, "XYZ",
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -503,6 +646,50 @@
BOOST_CHECK(called);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
+
+ s.reset(read_data, sizeof(read_data));
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, "WXY",
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, "WXY",
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, "WXY",
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
}
void test_match_condition_async_read_until()
@@ -519,6 +706,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, match_char('Z'),
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -533,6 +721,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, match_char('Z'),
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -547,6 +736,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb1.consume(sb1.size());
boost::asio::async_read_until(s, sb1, match_char('Z'),
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -560,6 +750,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, match_char('Z'),
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -574,6 +765,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, match_char('Z'),
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -588,6 +780,7 @@
ec = boost::system::error_code();
length = 0;
called = false;
+ sb2.consume(sb2.size());
boost::asio::async_read_until(s, sb2, match_char('Z'),
boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
boost::asio::placeholders::bytes_transferred, &length, &called));
@@ -596,6 +789,50 @@
BOOST_CHECK(called);
BOOST_CHECK(ec == boost::asio::error::not_found);
BOOST_CHECK(length == 0);
+
+ s.reset(read_data, sizeof(read_data));
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, match_char('Y'),
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(1);
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, match_char('Y'),
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
+
+ s.reset(read_data, sizeof(read_data));
+ s.next_read_length(10);
+ ec = boost::system::error_code();
+ length = 0;
+ called = false;
+ sb2.consume(sb2.size());
+ boost::asio::async_read_until(s, sb2, match_char('Y'),
+ boost::bind(async_read_handler, boost::asio::placeholders::error, &ec,
+ boost::asio::placeholders::bytes_transferred, &length, &called));
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(called);
+ BOOST_CHECK(!ec);
+ BOOST_CHECK(length == 25);
}
test_suite* init_unit_test_suite(int, char*[])
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk