Skip to content

Commit f5c845d

Browse files
committed
Fix h2c_compile compile on unix
1 parent 12a3720 commit f5c845d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

examples/h2c_client.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ unsafe fn to_str(ptr: *const u8, len: usize) -> String {
240240
String::from_utf8_lossy(unsafe { slice::from_raw_parts(ptr, len) }).into()
241241
}
242242

243+
#[cfg(windows)]
243244
unsafe extern "C" fn send_cb(
244245
_: *mut nghttp2_session,
245246
data: *const u8,
@@ -256,6 +257,23 @@ unsafe extern "C" fn send_cb(
256257
}
257258
}
258259

260+
#[cfg(not(windows))]
261+
unsafe extern "C" fn send_cb(
262+
_: *mut nghttp2_session,
263+
data: *const u8,
264+
len: usize,
265+
_: i32,
266+
user_data: *mut std::os::raw::c_void,
267+
) -> isize {
268+
unsafe {
269+
let ctx = &mut *(user_data as *mut Context);
270+
match ctx.stream.write_all(slice::from_raw_parts(data, len)) {
271+
Ok(_) => len as isize,
272+
Err(_) => NGHTTP2_ERR_CALLBACK_FAILURE as isize,
273+
}
274+
}
275+
}
276+
259277
unsafe extern "C" fn data_cb(
260278
_: *mut nghttp2_session,
261279
_: u8,

0 commit comments

Comments
 (0)