Re: [PATCH 02/10] Provide a simple object for encoding/decoding RPC messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 24, 2011 at 01:00:29PM +0800, Daniel Veillard wrote:
> On Thu, Jun 23, 2011 at 04:19:37PM -0600, Eric Blake wrote:
> > On 06/22/2011 09:33 AM, Daniel P. Berrange wrote:
> > > This provides a new struct that contains a buffer for the RPC
> > > message header+payload, as well as a decoded copy of the message
> > > header. There is an API for applying a XDR encoding & decoding
> > > of the message headers and payloads. There are also APIs for
> > > maintaining a simple FIFO queue of message instances.
> > > 
> > > Expected usage scenarios are:
> > > 
> > > To send a message
> > > 
> > >    msg = virNetMessageNew()
> > > 
> > >    ...fill in msg->header fields..
> > >    virNetMessageEncodeHeader(msg)
> > >    ...loook at msg->header fields to determine payload filter
> > >    virNetMessageEncodePayload(msg, xdrfilter, data)
> > >    ...send msg->bufferLength worth of data from buffer
> > > 
> > > To receive a message
> > > 
> > >    msg = virNetMessageNew()
> > >    ...read VIR_NET_MESSAGE_LEN_MAX of data into buffer
> > >    virNetMessageDecodeLength(msg)
> > >    ...read msg->bufferLength-msg->bufferOffset of data into buffer
> > >    virNetMessageDecodeHeader(msg)
> > >    ...look at msg->header fields to determine payload filter
> > >    virNetMessageDecodePayload(msg, xdrfilter, data)
> > >    ...run payload processor
> > 
> [...]
> > > +void virNetMessageSaveError(virNetMessageErrorPtr rerr)
> > > +{
> > > +    /* This func may be called several times & the first
> > > +     * error is the one we want because we don't want
> > > +     * cleanup code overwriting the first one.
> > > +     */
> > > +    if (rerr->code != VIR_ERR_OK)
> > > +        return;
> > > +
> > > +    virErrorPtr verr = virGetLastError();
> > > +    if (verr) {
> > > +        rerr->code = verr->code;
> > > +        rerr->domain = verr->domain;
> > > +        rerr->message = verr->message ? malloc(sizeof(char*)) : NULL;
> > 
> > Should we really be using raw malloc here, or is it any better to use
> > VIR_ALLOC?  (Several times in this function).
> 
>   I would rather use VIR_ALLOC everywhere if possible too,

This bit of code is just copied from existing code in daemon/dispatch.c
and I didn't notice it wasn't using VIR_ALLOC. I'll update it though we
do intentionally ignore OOM and do our best to carry on returning an
RPC error message to the client.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]