Exceptions not passed correctly thru RCF (using Boost.Serialization)
-
09-06-2019 - |
Question
I use RCF with boost.serialization (why use RCF's copy when we already use the original?) It works OK, but when an exception is thrown in the server, it's not passed correctly to the client. Instead, I get an RCF::SerializationException quoting an archive_exception
saying "class name too long". When I change the protocol to BsText, the exceptions is "unregistered class". When I change the protocol to SfBinary, it works.
I've registered RemoteException on both server and client like this:
BOOST_CLASS_VERSION(RCF::RemoteException, 0)
BOOST_CLASS_EXPORT(RCF::RemoteException)
I even tried serializing and deserializing a boost::shared_ptr<RCF::RemoteException>
in the same test, and it works.
So how can I make RCF pass exceptions correctly without resorting to SF?
Solution
Here's a patch given by Jarl at CodeProject:
In RcfServer.cpp, before the line where RcfServer::handleSession() is defined (around line 792), insert the following code:
void serialize(SerializationProtocolOut & out, const RemoteException & e)
{
serialize(out, std::auto_ptr<RemoteException>(new RemoteException(e)));
}
And in Marshal.cpp, around line 37, replace this line:
ar & boost::serialization::make_nvp("Dummy", apt.get());
, with
T *pt = apt.get();
ar & boost::serialization::make_nvp("Dummy", pt);
OTHER TIPS
According to Jarl it works, check codeproject for a question and answer with sample code: