Skip to content

Commit

Permalink
ffi: fix quiche_conn_new_scid(...) return value
Browse files Browse the repository at this point in the history
Motivation:

The implementation of quiche_conn_new_scid(...) made it impossible to know if the call was a success or not as even on a sucessfull call it might return a negative value.

Modifications:

Change signature to make it possible to detect if success or not.

Result:

Fix implementation
  • Loading branch information
normanmaurer authored Nov 27, 2023
1 parent 5796adc commit 1a92311
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions quiche/include/quiche.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,10 @@ size_t quiche_conn_scids_left(quiche_conn *conn);
size_t quiche_conn_active_scids(quiche_conn *conn);

// Provides additional source Connection IDs that the peer can use to reach
// this host.
uint64_t quiche_conn_new_scid(quiche_conn *conn,
// this host. Writes the sequence number to "scid_seq" and returns 0.
int quiche_conn_new_scid(quiche_conn *conn,
const uint8_t *scid, size_t scid_len,
const uint8_t *reset_token, bool retire_if_needed);
const uint8_t *reset_token, bool retire_if_needed, uint64_t *scid_seq);

enum quiche_path_event_type {
QUICHE_PATH_EVENT_NEW,
Expand Down
12 changes: 7 additions & 5 deletions quiche/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,8 @@ pub extern fn quiche_conn_scids_left(conn: &Connection) -> size_t {
#[no_mangle]
pub extern fn quiche_conn_new_scid(
conn: &mut Connection, scid: *const u8, scid_len: size_t,
reset_token: *const u8, retire_if_needed: bool,
) -> u64 {
reset_token: *const u8, retire_if_needed: bool, scid_seq: *mut u64,
) -> c_int {
let scid = unsafe { slice::from_raw_parts(scid, scid_len) };
let scid = ConnectionId::from_ref(scid);

Expand All @@ -1423,9 +1423,11 @@ pub extern fn quiche_conn_new_scid(
let reset_token = u128::from_be_bytes(reset_token);

match conn.new_scid(&scid, reset_token, retire_if_needed) {
Ok(c) => c,

Err(e) => e.to_c() as u64,
Ok(c) => {
unsafe { *scid_seq = c }
0
},
Err(e) => e.to_c() as c_int,
}
}

Expand Down

0 comments on commit 1a92311

Please sign in to comment.