add switch_buffer_peek()
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16696 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
6da81efaa5
commit
1f8c1112d6
|
@ -101,6 +101,14 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_inuse(_In_ switch_buffer_t *buffer);
|
||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(switch_size_t) switch_buffer_read(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen);
|
SWITCH_DECLARE(switch_size_t) switch_buffer_read(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen);
|
||||||
|
|
||||||
|
/*! \brief Read data from a switch_buffer_t up to the ammount of datalen if it is available, without removing read data from buffer.
|
||||||
|
* \param buffer any buffer of type switch_buffer_t
|
||||||
|
* \param data pointer to the read data to be returned
|
||||||
|
* \param datalen amount of data to be returned
|
||||||
|
* \return int ammount of data actually read
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(switch_size_t) switch_buffer_peek(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen);
|
||||||
|
|
||||||
/*! \brief Read data endlessly from a switch_buffer_t
|
/*! \brief Read data endlessly from a switch_buffer_t
|
||||||
* \param buffer any buffer of type switch_buffer_t
|
* \param buffer any buffer of type switch_buffer_t
|
||||||
* \param data pointer to the read data to be returned
|
* \param data pointer to the read data to be returned
|
||||||
|
|
|
@ -206,6 +206,24 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_read(switch_buffer_t *buffer, void *
|
||||||
return reading;
|
return reading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_size_t) switch_buffer_peek(switch_buffer_t *buffer, void *data, switch_size_t datalen)
|
||||||
|
{
|
||||||
|
switch_size_t reading = 0;
|
||||||
|
|
||||||
|
if (buffer->used < 1) {
|
||||||
|
buffer->used = 0;
|
||||||
|
return 0;
|
||||||
|
} else if (buffer->used >= datalen) {
|
||||||
|
reading = datalen;
|
||||||
|
} else {
|
||||||
|
reading = buffer->used;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(data, buffer->head, reading);
|
||||||
|
|
||||||
|
return reading;
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
|
SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen)
|
||||||
{
|
{
|
||||||
switch_size_t freespace, actual_freespace;
|
switch_size_t freespace, actual_freespace;
|
||||||
|
|
Loading…
Reference in New Issue