in source/secure_tunneling.c [472:497]
bool secure_tunneling_send_data_call(struct aws_websocket *websocket, struct aws_byte_buf *out_buf, void *user_data) {
UNUSED(websocket);
struct data_tunnel_pair *pair = user_data;
size_t space_available = out_buf->capacity - out_buf->len;
if ((pair->length_prefix_written == false) && (space_available >= PAYLOAD_BYTE_LENGTH_PREFIX)) {
if (aws_byte_buf_write_be16(out_buf, (int16_t)pair->buf.len) == false) {
AWS_LOGF_ERROR(AWS_LS_IOTDEVICE_SECURE_TUNNELING, "Failure writing buffer length prefix to out_buf");
return false;
}
pair->length_prefix_written = true;
space_available = out_buf->capacity - out_buf->len;
}
if (pair->length_prefix_written == true) {
size_t bytes_max = pair->cur.len;
size_t amount_to_send = bytes_max < space_available ? bytes_max : space_available;
struct aws_byte_cursor send_cursor = aws_byte_cursor_advance(&pair->cur, amount_to_send);
if (send_cursor.len) {
if (aws_byte_buf_write_from_whole_cursor(out_buf, send_cursor) == false) {
AWS_LOGF_ERROR(AWS_LS_IOTDEVICE_SECURE_TUNNELING, "Failure writing data to out_buf");
return false;
}
}
}
return true;
}