buffer\datum questions

Nikos Mavrogiannopoulos nmav at gnutls.org
Thu Aug 2 10:10:11 CEST 2012


On Thu, Aug 2, 2012 at 9:54 AM, Olya <olyasib12 at gmail.com> wrote:

>>> _gnutls_buffer_pop_prefix (gnutls_buffer_st * buf, size_t * data_size, int check) ?
>> It reads a 32-bit integer from the buffer and checks whether the
>> remaining data length are less than that.
> So how exactly "int check" is used - boolean indicator whether to perform remainder
> length check or not?

Just a boolean.

> Or it's the length value against which the remainder will be checked?
> Are there similar functions for 16 bits? 8 bits? etc.

No. But we can make this more general if you need it.

>>> 2) Do I have to pre-allocate memory for the datum, copy my data to datum, call
>>> _replace() and deallocate datum? Could you give simple example of _replace() usage?
>> The replace, will copy the datum you provide (already allocated) to the buffer.
> So the expected call sequence is:
>  _gnutls_set_datum (&dat, data, data_size);

Use set_datum() only if you want to copy(duplicate) the data you have
into the datum. Otherwise just assign the values (datum->data,
datum->size) to the needed one.

>  _gnutls_buffer_replace_data (&buffer, &dat);
>  _gnutls_free_datum (&dat);

No need to call free_datum(). buffer_replace() takes the array you
provided and it will be deinitialized when you clear the buffer.

>> If you want to re-use a buffer. I.e. you appended some data, sent it
>> to the peer, and want to use a new buffer. Instead of initializing a
>> new one you reset that one.
> So instead of _replace_data() I can call _reset() and _append()?

replace_data() doesn't do any data copy. So if the data size is large
it may be more efficient.

regards,
Nikos




More information about the Gnutls-devel mailing list