Boost の例 ( http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/timeouts/blocking_tcp_client.cpp )のコードに基づいて、関数 read_expect() を次のように作成しました。
std::string TcpClient::read_expect(const boost::regex & expected,
boost::posix_time::time_duration timeout)
{
// Set a deadline for the asynchronous operation. Since this function uses
// a composed operation (async_read_until), the deadline applies to the
// entire operation, rather than individual reads from the socket.
deadline_.expires_from_now(timeout);
// Set up the variable that receives the result of the asynchronous
// operation. The error code is set to would_block to signal that the
// operation is incomplete. Asio guarantees that its asynchronous
// operations will never fail with would_block, so any other value in
// ec indicates completion.
boost::system::error_code ec = boost::asio::error::would_block;
// Start the asynchronous operation itself. The boost::lambda function
// object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda.
boost::asio::async_read_until(socket_, input_buffer_, expected, var(ec) = _1);
// Block until the asynchronous operation has completed.
do
{
io_service_.run_one();
}
while (ec == boost::asio::error::would_block);
if (ec)
{
throw boost::system::system_error(ec);
}
// take the whole response
std::string result;
std::string line;
std::istream is(&input_buffer_);
while (is)
{
std::getline(is, line);
result += line;
}
return result;
}
これは、正規表現で使用すると正常に機能します
boost::regex(".*#ss#([^#]+)#.*")
、しかし、正規表現を次のように変更すると、奇妙な動作が発生します
boost::regex(".*#ss#(<Stats>[^#]+</Stats>)#.*")
、結果としてタイムアウトが発生せず、スレッドが async_read_until() 呼び出しでハングします。おそらく、これは正規表現では見られないばかげたエラーであり、最初のバージョンを使用できましたが、なぜこれが起こっているのかを本当に知りたいです.
洞察をありがとう、マーリーン