Discussion:
[omniORB] Calculating the message size of a response
Floris Bruynooghe
2010-01-05 03:19:57 UTC
Permalink
Hi

When the giopMaxMsgSize is exceeded the server code never knows this
and the client code just gets a COMM_FAILURE instead of a more
meaningful error.

Is it somehow possible to calculate the size of a message before
sending it on the server side? Basically perform the marshalling
(from within python) and check the result so you could decide to raise
a custom exception which is more specific. (Bonus points for then
being able to send this already marshalled data instead of having to
repeat that)

Thanks
Floris
--
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
Duncan Grisby
2010-01-05 23:05:41 UTC
Permalink
Post by Floris Bruynooghe
When the giopMaxMsgSize is exceeded the server code never knows this
and the client code just gets a COMM_FAILURE instead of a more
meaningful error.
Yes. That's because in most cases, the server has started sending the
data before it knows it is going to be too big. Once it has started
sending the reply, it can't send a more meaningful exception.
Post by Floris Bruynooghe
Is it somehow possible to calculate the size of a message before
sending it on the server side? Basically perform the marshalling
(from within python) and check the result so you could decide to raise
a custom exception which is more specific. (Bonus points for then
being able to send this already marshalled data instead of having to
repeat that)
Well, you can use the omniORB.cdrMarshal function to marshal the data
into a string. There's no way to then send that as the reply, so you
would end up doing the marshalling work twice, and you'd have to hold
the whole marshalled data in memory rather than streaming it over the
network.

At a C++ level, there is a cdrCountingStream class that you can use to
work out how big data will be without storing the marshalled form. That
isn't currently exposed to Python code, but I suppose you could add
something similar to the cdrMarshal function that did it. The other
limitation is that you can't use it if you are using valuetypes, since
the valuetype chunked encoding size is dependent on the buffering of the
data.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Floris Bruynooghe
2010-01-06 04:42:00 UTC
Permalink
Post by Duncan Grisby
Post by Floris Bruynooghe
Is it somehow possible to calculate the size of a message before
sending it on the server side? Basically perform the marshalling
(from within python) and check the result so you could decide to raise
a custom exception which is more specific. (Bonus points for then
being able to send this already marshalled data instead of having to
repeat that)
Well, you can use the omniORB.cdrMarshal function to marshal the data
into a string. There's no way to then send that as the reply, so you
would end up doing the marshalling work twice, and you'd have to hold
the whole marshalled data in memory rather than streaming it over the
network.
At a C++ level, there is a cdrCountingStream class that you can use to
work out how big data will be without storing the marshalled form. That
isn't currently exposed to Python code, but I suppose you could add
something similar to the cdrMarshal function that did it. The other
limitation is that you can't use it if you are using valuetypes, since
the valuetype chunked encoding size is dependent on the buffering of the
data.
Thanks for the quick and clear answer, I should be able to create
something useful out of this.

Regards
Floris
--
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
Loading...