Hello,
We have been facing an issue with the TCF Streams service and I am
wondering if it is either an error in the documentation
documentation or an error in the implementation of the service in
the "C" agent.
In the TCF Streams documentation, we can see:
C • <token> • Streams • write • <string: stream ID> • <int: size> • <string: data> •
stream ID
- ID of stream that will receive the data.
size
- Number of bytes to write. Length of
data must match
the size.
data
- BASE64 encoded bytes that will be written
to the stream.
In case your client does not support ZeroCopy and thus sends BASE64
encoded data; I understand that size represents the size of the data
buffer when it is encoded encoded (which is twice the size of the
binary buffer). I have two issues with this:
1 - When you want to write a TCF streams proxy; it is usually not
possible to get the size of the encoded data after the data has been
sent (after you have done the
json_write_binary_start/json_write_binary_data/json_write_binary_end
sequence) and this is too late. It would mean you have to first
encode the data in a buffer and then send this data; this is not
very handy.
2 - If we do really need to transfer the size of the BASE64 encoded
data; then there is a bug in streamsservice.c, int
virtual_stream_write() function.
The code:
if (data != NULL) {
WriteRequest * r = (WriteRequest
*)loc_alloc_zero(sizeof(WriteRequest));
list_init(&r->link_client);
r->client = client;
r->data = "">
r->size = size - offs;
strlcpy(r->token, token, sizeof(r->token));
list_add_last(&r->link_client,
&client->write_requests);
}
should be replaced with:
if (data != NULL) {
WriteRequest * r = (WriteRequest
*)loc_alloc_zero(sizeof(WriteRequest));
list_init(&r->link_client);
r->client = client;
r->data = "">
r->size = data_pos;
strlcpy(r->token, token, sizeof(r->token));
list_add_last(&r->link_client,
&client->write_requests);
}
Note that we must also move the definition of data_pos to do this.
If we don't do this, the size we return (r->size) is too big (it
represents the size of the BASE64 encoded data instead of the size
of the buffer we have read).
Is the TCF documentation correct or should we replace "Length of data
must match the size." with something like "size must
represent the size of the binary version of data buffer."?
In any case, I think we should do the fix in streamsservice.c since
it will work in all cases.
Thanks,
Didier
--
Didier Brachet, Principal Technologist, Wind River
direct (33) 297.427.286 fax (33) 297.424.550
|