Commit df520795 authored by Lubomir Bulej's avatar Lubomir Bulej

Tweak byte buffer interface and update dependent files

parent dbf23307
......@@ -44,7 +44,7 @@ __to_buff_alloc_buffers (to_buff_struct * tobs, tldata * tld) {
static inline objtag_rec *
__buffer_ptr_objtag (buffer_t * restrict buffer, const size_t position) {
// Buffer should a command buffer containing object tagging records.
return (objtag_rec *) buffer_ptr_block (buffer, position, sizeof (objtag_rec));
return (objtag_rec *) buffer_block_at (buffer, position, sizeof (objtag_rec));
}
......
......@@ -24,7 +24,7 @@ send_data (int sockfd, buffer_t * restrict buffer) {
size_t position = 0;
while (position < end_position) {
size_t bytes_left = end_position - position;
const uint8_t * bytes = buffer_ptr_block (buffer, position, bytes_left);
const uint8_t * bytes = buffer_block_at (buffer, position, bytes_left);
ssize_t bytes_sent = send (sockfd, bytes, bytes_left, 0);
check_std_error (bytes_sent < 0, "error sending data to server");
......
......@@ -117,21 +117,21 @@ buffer_append_bytes (
void
buffer_put_jshort (buffer_t * restrict buffer, jshort value, size_t position) {
uint8_t * restrict dest = buffer_ptr_block (buffer, position, sizeof (jshort));
uint8_t * restrict dest = buffer_block_at (buffer, position, sizeof (jshort));
*((jshort *) dest) = htons (value);
}
void
buffer_put_jint (buffer_t * restrict buffer, jint value, size_t position) {
uint8_t * restrict dest = buffer_ptr_block (buffer, position, sizeof (jint));
uint8_t * restrict dest = buffer_block_at (buffer, position, sizeof (jint));
*((jint *) dest) = htonl (value);
}
void
buffer_put_jlong (buffer_t * restrict buffer, jlong value, size_t position) {
uint8_t * restrict dest = buffer_ptr_block (buffer, position, sizeof (jlong));
uint8_t * restrict dest = buffer_block_at (buffer, position, sizeof (jlong));
*((jlong *) dest) = htobe64 (value);
}
......@@ -154,7 +154,7 @@ buffer_append_utf8 (
void
buffer_drain_to (buffer_t * restrict src, buffer_t * restrict dst) {
size_t src_len = buffer_length (src);
uint8_t * src_bytes = buffer_ptr_block (src, 0, src_len);
uint8_t * src_bytes = buffer_block_at (src, 0, src_len);
buffer_append_bytes (dst, src_bytes, src_len);
buffer_clear (src);
}
......
......@@ -82,7 +82,7 @@ __buffer_remaining (const buffer_t * restrict buffer) {
/**
* Ensure that the given buffer has enough remaining scape to
* Ensure that the given buffer has enough remaining space to
* accomodate the given number of bytes. If necessary, the buffer
* is expanded to accomodate the requirement. Returns the new
* capacity of the buffer.
......@@ -90,9 +90,9 @@ __buffer_remaining (const buffer_t * restrict buffer) {
static size_t
__buffer_ensure_remaining (buffer_t * restrict buffer, const size_t bytes_needed) {
//
// If the buffer does not have enough space remaining to accomodate
// the space needed, double the buffer capacity until it can do so.
// Then copy the buffer and update the capacity.
// If the buffer does not have enough space, double the buffer capacity
// until it can accomodate the request. Then copy the buffer and update
// the capacity.
//
if (__buffer_remaining (buffer) < bytes_needed) {
size_t new_capacity = __calculate_capacity (
......@@ -129,9 +129,12 @@ __buffer_ptr (const buffer_t * restrict buffer) {
* Returns a pointer to a block of memory at the given position in the buffer.
* The block must be within the occupied part of the buffer and the block size
* must be greater than 0.
*
* NOTE: The caller should never store pointers to the buffer between
* operations that might enlarge the buffer.
*/
uint8_t *
buffer_ptr_block (const buffer_t * restrict buffer, size_t position, size_t size) {
buffer_block_at (const buffer_t * restrict buffer, size_t position, size_t size) {
assert (buffer != NULL);
assert (size > 0);
......
......@@ -36,7 +36,7 @@ buffer_clear (buffer_t * restrict buffer) {
buffer->position = 0;
}
uint8_t * buffer_ptr_block (
uint8_t * buffer_block_at (
const buffer_t * restrict buffer, size_t position, size_t size
);
......
......@@ -142,7 +142,7 @@ ot_tag_record (
static inline objtag_rec *
__buffer_ptr_objtag (buffer_t * restrict buffer, const size_t position) {
// Buffer should a command buffer containing object tagging records.
return (objtag_rec *) buffer_ptr_block (buffer, position, sizeof (objtag_rec));
return (objtag_rec *) buffer_block_at (buffer, position, sizeof (objtag_rec));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment