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 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,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
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]