On stream completion it is neccessary to send back a message with an empty payload. The message header was not being filled out correctly, since we were not writing any payload. Add a method for encoding an empty payload which updates the message headers correctly. * src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add a virNetMessageEncodePayloadEmpty method * src/rpc/virnetserverprogram.c: Write empty payload on stream completion --- src/rpc/virnetmessage.c | 25 +++++++++++++++++++++++++ src/rpc/virnetmessage.h | 2 ++ src/rpc/virnetserverprogram.c | 5 ++++- 3 files changed, 31 insertions(+), 1 deletions(-) diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 62cdbc3..a7a25b1 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -334,6 +334,31 @@ error: } +int virNetMessageEncodePayloadEmpty(virNetMessagePtr msg) +{ + XDR xdr; + unsigned int msglen; + + /* Re-encode the length word. */ + VIR_DEBUG("Encode length as %zu", msg->bufferOffset); + xdrmem_create(&xdr, msg->buffer, VIR_NET_MESSAGE_HEADER_XDR_LEN, XDR_ENCODE); + msglen = msg->bufferOffset; + if (!xdr_u_int(&xdr, &msglen)) { + virNetError(VIR_ERR_RPC, "%s", _("Unable to encode message length")); + goto error; + } + xdr_destroy(&xdr); + + msg->bufferLength = msg->bufferOffset; + msg->bufferOffset = 0; + return 0; + +error: + xdr_destroy(&xdr); + return -1; +} + + void virNetMessageSaveError(virNetMessageErrorPtr rerr) { /* This func may be called several times & the first diff --git a/src/rpc/virnetmessage.h b/src/rpc/virnetmessage.h index 9215112..2aae3f6 100644 --- a/src/rpc/virnetmessage.h +++ b/src/rpc/virnetmessage.h @@ -78,6 +78,8 @@ int virNetMessageEncodePayloadRaw(virNetMessagePtr msg, const char *buf, size_t len) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +int virNetMessageEncodePayloadEmpty(virNetMessagePtr msg) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; void virNetMessageSaveError(virNetMessageErrorPtr rerr) ATTRIBUTE_NONNULL(1); diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 0d1577a..4afed64 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -433,8 +433,11 @@ int virNetServerProgramSendStreamData(virNetServerProgramPtr prog, if (virNetMessageEncodePayloadRaw(msg, data, len) < 0) return -1; - VIR_DEBUG("Total %zu", msg->bufferOffset); + } else { + if (virNetMessageEncodePayloadEmpty(msg) < 0) + return -1; } + VIR_DEBUG("Total %zu", msg->bufferOffset); return virNetServerClientSendMessage(client, msg); } -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list