1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use libc::size_t;
pub struct hyper_error(crate::Error);
#[repr(C)]
pub enum hyper_code {
HYPERE_OK,
HYPERE_ERROR,
HYPERE_INVALID_ARG,
HYPERE_UNEXPECTED_EOF,
HYPERE_ABORTED_BY_CALLBACK,
#[cfg_attr(feature = "http2", allow(unused))]
HYPERE_FEATURE_NOT_ENABLED,
HYPERE_INVALID_PEER_MESSAGE,
}
impl hyper_error {
fn code(&self) -> hyper_code {
use crate::error::Kind as ErrorKind;
use crate::error::User;
match self.0.kind() {
ErrorKind::Parse(_) => hyper_code::HYPERE_INVALID_PEER_MESSAGE,
ErrorKind::IncompleteMessage => hyper_code::HYPERE_UNEXPECTED_EOF,
ErrorKind::User(User::AbortedByCallback) => hyper_code::HYPERE_ABORTED_BY_CALLBACK,
_ => hyper_code::HYPERE_ERROR,
}
}
fn print_to(&self, dst: &mut [u8]) -> usize {
use std::io::Write;
let mut dst = std::io::Cursor::new(dst);
let _ = write!(dst, "{}", &self.0);
dst.position() as usize
}
}
ffi_fn! {
fn hyper_error_free(err: *mut hyper_error) {
drop(non_null!(Box::from_raw(err) ?= ()));
}
}
ffi_fn! {
fn hyper_error_code(err: *const hyper_error) -> hyper_code {
non_null!(&*err ?= hyper_code::HYPERE_INVALID_ARG).code()
}
}
ffi_fn! {
fn hyper_error_print(err: *const hyper_error, dst: *mut u8, dst_len: size_t) -> size_t {
let dst = unsafe {
std::slice::from_raw_parts_mut(dst, dst_len)
};
non_null!(&*err ?= 0).print_to(dst)
}
}