Skip to content

Commit 280603c

Browse files
author
vatsalkeshav
committed
xds module : trying to fix frame timing mismatch in regression test 106
1 parent 883121a commit 280603c

3 files changed

Lines changed: 29 additions & 25 deletions

File tree

src/rust/src/libccxr_exports/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub unsafe fn write_back_to_common_timing_ctx(
275275
/// # Safety
276276
///
277277
/// All the static variables should be initialized and in valid state.
278-
unsafe fn apply_timing_info() {
278+
pub(crate) unsafe fn apply_timing_info() {
279279
let Ok(mut timing_info) = GLOBAL_TIMING_INFO.write() else {
280280
// RwLock is poisoned, skip updating
281281
return;

src/rust/src/xds/handlers.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -763,13 +763,13 @@ pub unsafe fn xds_do_current_and_future(
763763

764764
// Extract program name from payload (bytes 2 to payload_length - 2)
765765
let name_end = (ctx.cur_xds_payload_length - 1) as usize;
766-
let name_bytes: Vec<u8> = payload[2..name_end]
767-
.iter()
768-
.copied()
769-
.filter(|&b| b != 0)
770-
.collect();
766+
let name_slice = &payload[2..name_end];
767+
let name_bytes = match name_slice.iter().position(|&b| b == 0) {
768+
Some(pos) => &name_slice[..pos],
769+
None => name_slice,
770+
};
771771

772-
let xds_program_name = String::from_utf8_lossy(&name_bytes).to_string();
772+
let xds_program_name = String::from_utf8_lossy(name_bytes).to_string();
773773

774774
debug!(
775775
msg_type = DebugMessageFlag::DECODER_XDS;
@@ -953,13 +953,13 @@ pub unsafe fn xds_do_current_and_future(
953953

954954
// Extract description from payload
955955
let desc_end = (ctx.cur_xds_payload_length - 1) as usize;
956-
let desc_bytes: Vec<u8> = payload[2..desc_end]
957-
.iter()
958-
.copied()
959-
.filter(|&b| b != 0)
960-
.collect();
956+
let desc_slice = &payload[2..desc_end];
957+
let desc_bytes = match desc_slice.iter().position(|&b| b == 0) {
958+
Some(pos) => &desc_slice[..pos],
959+
None => desc_slice,
960+
};
961961

962-
let xds_desc = String::from_utf8_lossy(&desc_bytes).to_string();
962+
let xds_desc = String::from_utf8_lossy(desc_bytes).to_string();
963963

964964
if !xds_desc.is_empty() {
965965
let line_num = ctx.cur_xds_packet_type - 0x10; // XDS_TYPE_PROGRAM_DESC_1 = 0x10
@@ -1056,13 +1056,13 @@ pub unsafe fn xds_do_channel(
10561056

10571057
// Extract network name from payload (bytes 2 to payload_length - 2)
10581058
let name_end = (ctx.cur_xds_payload_length - 1) as usize;
1059-
let name_bytes: Vec<u8> = payload[2..name_end]
1060-
.iter()
1061-
.copied()
1062-
.filter(|&b| b != 0)
1063-
.collect();
1059+
let name_slice = &payload[2..name_end];
1060+
let name_bytes = match name_slice.iter().position(|&b| b == 0) {
1061+
Some(pos) => &name_slice[..pos],
1062+
None => name_slice,
1063+
};
10641064

1065-
let xds_network_name = String::from_utf8_lossy(&name_bytes).to_string();
1065+
let xds_network_name = String::from_utf8_lossy(name_bytes).to_string();
10661066

10671067
debug!(
10681068
msg_type = DebugMessageFlag::DECODER_XDS;
@@ -1093,13 +1093,13 @@ pub unsafe fn xds_do_channel(
10931093

10941094
// Extract call letters from payload (bytes 2 to payload_length - 2)
10951095
let letters_end = (ctx.cur_xds_payload_length - 1) as usize;
1096-
let letters_bytes: Vec<u8> = payload[2..letters_end]
1097-
.iter()
1098-
.copied()
1099-
.filter(|&b| b != 0)
1100-
.collect();
1096+
let letters_slice = &payload[2..letters_end];
1097+
let letters_bytes = match letters_slice.iter().position(|&b| b == 0) {
1098+
Some(pos) => &letters_slice[..pos],
1099+
None => letters_slice,
1100+
};
11011101

1102-
let xds_call_letters = String::from_utf8_lossy(&letters_bytes).to_string();
1102+
let xds_call_letters = String::from_utf8_lossy(letters_bytes).to_string();
11031103

11041104
debug!(
11051105
msg_type = DebugMessageFlag::DECODER_XDS;

src/rust/src/xds/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod types;
1818
use crate::bindings::*;
1919
use crate::ctorust::FromCType;
2020
use crate::libccxr_exports::time::generate_timing_context;
21+
use crate::libccxr_exports::time::apply_timing_info;
2122
use crate::xds::handlers::{do_end_of_xds, TS_START_OF_XDS};
2223
use crate::xds::types::{copy_xds_context_from_rust_to_c, CcxDecodersXdsContext};
2324
use std::os::raw::c_int;
@@ -42,6 +43,9 @@ pub unsafe extern "C" fn ccxr_do_end_of_xds(
4243
return;
4344
}
4445

46+
// trying to sync cb_field2 etc globals from C to GLOBAL_TIMING_INFO. hope this works
47+
apply_timing_info();
48+
4549
// Convert C context to Rust
4650
let mut rust_ctx = match CcxDecodersXdsContext::from_ctype(*ctx) {
4751
Some(c) => c,

0 commit comments

Comments
 (0)