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

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

 



On 03/15/2011 11:51 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
> 

> +++ b/src/Makefile.am
> @@ -1202,6 +1202,7 @@ EXTRA_DIST += $(LIBVIRT_QEMU_SYMBOL_FILE)
>  noinst_LTLIBRARIES += libvirt-net-rpc.la
>  
>  libvirt_net_rpc_la_SOURCES = \
> +	rpc/virnetmessage.h rpc/virnetmessage.c \
>  	rpc/virnetprotocol.h rpc/virnetprotocol.c

Huh? There's no src/rpc in current libvirt.git.  This looks like 2/15 in
the v1 posting.  Did you forget to submit the original 1/15 as a
prerequisite patch?
http://www.redhat.com/archives/libvir-list/2010-December/msg00617.html

>  libvirt_net_rpc_la_CFLAGS = \
>  			$(AM_CFLAGS)
> diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c
> new file mode 100644
> index 0000000..4c226d2
> --- /dev/null
> +++ b/src/rpc/virnetmessage.c
> @@ -0,0 +1,365 @@
> +/*
> + * virnetmessage.h: basic RPC message encoding/decoding
> + *
> + * Copyright (C) 2010 Red Hat, Inc.

Welcome to 2011. :)

> +/*
> + * @msg: the outgoing message, whose header to encode
> + *
> + * Encodes the length word and header of the  message, setting the

Hmm, you still missed my spacing comment from
http://www.redhat.com/archives/libvir-list/2010-December/msg00657.html

s/the  message/the message/

> diff --git a/src/rpc/virnetmessage.h b/src/rpc/virnetmessage.h
> new file mode 100644
> index 0000000..9a92c0b
> --- /dev/null
> +++ b/src/rpc/virnetmessage.h
> @@ -0,0 +1,70 @@
> +/*
> + * virnetmessage.h: basic RPC message encoding/decoding
> + *
> + * Copyright (C) 2010 Red Hat, Inc.

2011

> +
> +struct _virNetMessage {
> +    char buffer[VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX];

Is it worth a comment warning that this struct should never be
stack-allocated?

> +void virNetMessageFree(virNetMessagePtr msg);

cfg.mk should list this as a free-like function.

> +
> +virNetMessagePtr virNetMessageQueueServe(virNetMessagePtr *queue);

It's worth adding attributes:

ATTRIBUTE_NONNULL(1)

> +void virNetMessageQueuePush(virNetMessagePtr *queue,
> +                            virNetMessagePtr msg);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)

> +
> +int virNetMessageEncodeHeader(virNetMessagePtr msg);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK

> +int virNetMessageDecodeLength(virNetMessagePtr msg);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK

> +int virNetMessageDecodeHeader(virNetMessagePtr msg);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK

> +
> +int virNetMessageEncodePayload(virNetMessagePtr msg,
> +                               xdrproc_t filter,
> +                               void *data);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK

> +int virNetMessageDecodePayload(virNetMessagePtr msg,
> +                               xdrproc_t filter,
> +                               void *data);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK

> +
> +int virNetMessageEncodePayloadRaw(virNetMessagePtr msg,
> +                                  const char *buf,
> +                                  size_t len);
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK

> +
> +void virNetMessageSaveError(virNetMessageErrorPtr rerr);
ATTRIBUTE_NONNULL(1)

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

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