1

my server runs following code:

boost::asio::streambuf streambuf;
std::istream istream(&streambuf);
boost::archive::xml_iarchive xml_iarchive(istream);
boost::asio::read_until(socket_, streambuf, '\n');

When the server is up and running I connect vie telnet from another machine. Immediately after connection is established, the connection is getting closed and the server crashes with following exception:

terminate called after throwing an instance of 'boost::archive::xml_archive_exception'
    what():  unrecognized XML syntax

Where is the failure at the code snippet above? It looks to me that the telnet session is sending a '\n' before I manually enter some XML string.

2
  • which line throws the exception? Commented Mar 6, 2013 at 16:17
  • boost::archive::xml_iarchive xml_iarchive(istream); Commented Mar 6, 2013 at 16:51

1 Answer 1

4

You didn't post a sscce, so I created one for you

#include <boost/asio.hpp>
#include <boost/archive/xml_iarchive.hpp>

int
main()
{
    try {
        boost::asio::streambuf streambuf;
        std::istream istream(&streambuf);
        boost::archive::xml_iarchive xml_iarchive(istream);
    } catch ( const std::exception& e ) {
        std::cerr << e.what() << std::endl;
    }
}

As expected, an exception is throw from line 10:

samm$ ./a.out
unrecognized XML syntax

This has nothing to do with Boost.Asio, you're trying to deserialize an empty buffer, which isn't valid XML. To solve this, delay the deserialization until after reading from the socket into the buffer

boost::asio::read_until(socket_, streambuf, '\n');
std::istream istream(&streambuf);
boost::archive::xml_iarchive xml_iarchive(istream);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.