This commit is contained in:
nora 2023-03-07 15:19:06 +01:00
parent 0b89e245d9
commit e1ebd97c91
73 changed files with 3822 additions and 3822 deletions

View file

@ -7,9 +7,9 @@ use libc::{c_int, size_t};
use super::task::{hyper_context, hyper_task, hyper_task_return_type, AsTaskType};
use super::{UserDataPointer, HYPER_ITER_CONTINUE};
use crate::body::{Body, Bytes, HttpBody as _};
/// A streaming HTTP body.
pub(crate) struct hyper_body(pub(super) Body);
/// A buffer of bytes that is sent or received on a `hyper_body`.
pub(crate) struct hyper_buf(pub(crate) Bytes);
pub(crate) struct UserBody {
data_func: hyper_body_data_callback,
@ -101,7 +101,7 @@ impl UserBody {
loop {}
}
}
/// cbindgen:ignore
extern "C" fn data_noop(
_userdata: *mut c_void,
_: *mut hyper_context<'_>,

View file

@ -9,17 +9,17 @@ use super::io::hyper_io;
use super::task::{
hyper_executor, hyper_task, hyper_task_return_type, AsTaskType, WeakExec,
};
/// An options builder to configure an HTTP client connection.
pub(crate) struct hyper_clientconn_options {
builder: conn::Builder,
/// Use a `Weak` to prevent cycles.
exec: WeakExec,
}
/// An HTTP client connection handle.
///
/// These are used to send a request on a single connection. It's possible to
/// send multiple requests on a single connection, such as when HTTP/1
/// keep-alive or HTTP/2 is used.
pub(crate) struct hyper_clientconn {
tx: conn::SendRequest<crate::Body>,
}

View file

@ -1,26 +1,26 @@
use libc::size_t;
/// A more detailed error object returned by some hyper functions.
pub(crate) struct hyper_error(crate::Error);
/// A return code for many of hyper's methods.
#[repr(C)]
pub(crate) enum hyper_code {
/// All is well.
HYPERE_OK,
/// General error, details in the `hyper_error *`.
HYPERE_ERROR,
/// A function argument was invalid.
HYPERE_INVALID_ARG,
/// The IO transport returned an EOF when one wasn't expected.
///
/// This typically means an HTTP request or response was expected, but the
/// connection closed cleanly without sending (all of) it.
HYPERE_UNEXPECTED_EOF,
/// Aborted by a user supplied callback.
HYPERE_ABORTED_BY_CALLBACK,
/// An optional hyper feature was not enabled.
#[cfg_attr(feature = "http2", allow(unused))]
HYPERE_FEATURE_NOT_ENABLED,
/// The peer sent an HTTP message that could not be parsed.
HYPERE_INVALID_PEER_MESSAGE,
}
impl hyper_error {

View file

@ -8,13 +8,13 @@ use super::{UserDataPointer, HYPER_ITER_CONTINUE};
use crate::ext::{HeaderCaseMap, OriginalHeaderOrder, ReasonPhrase};
use crate::header::{HeaderName, HeaderValue};
use crate::{Body, HeaderMap, Method, Request, Response, Uri};
/// An HTTP request.
pub(crate) struct hyper_request(pub(super) Request<Body>);
/// An HTTP response.
pub(crate) struct hyper_response(pub(super) Response<Body>);
/// An HTTP header map.
///
/// These can be part of a request or response.
pub(crate) struct hyper_headers {
pub(super) headers: HeaderMap,
orig_casing: HeaderCaseMap,

View file

@ -4,11 +4,11 @@ use std::task::{Context, Poll};
use libc::size_t;
use tokio::io::{AsyncRead, AsyncWrite};
use super::task::hyper_context;
/// Sentinel value to return from a read or write callback that the operation
/// is pending.
pub(crate) const HYPER_IO_PENDING: size_t = 0xFFFFFFFF;
/// Sentinel value to return from a read or write callback that the operation
/// has errored.
pub(crate) const HYPER_IO_ERROR: size_t = 0xFFFFFFFE;
type hyper_io_read_callback = extern "C" fn(
*mut c_void,
@ -22,7 +22,7 @@ type hyper_io_write_callback = extern "C" fn(
*const u8,
size_t,
) -> size_t;
/// An IO object used to represent a socket or similar concept.
pub(crate) struct hyper_io {
read: hyper_io_read_callback,
write: hyper_io_write_callback,
@ -77,7 +77,7 @@ ffi_fn! {
" should be the return value."] fn hyper_io_set_write(io : * mut hyper_io, func :
hyper_io_write_callback) { non_null!(& mut * io ?= ()) .write = func; }
}
/// cbindgen:ignore
extern "C" fn read_noop(
_userdata: *mut c_void,
_: *mut hyper_context<'_>,
@ -86,7 +86,7 @@ extern "C" fn read_noop(
) -> size_t {
loop {}
}
/// cbindgen:ignore
extern "C" fn write_noop(
_userdata: *mut c_void,
_: *mut hyper_context<'_>,

View file

@ -48,23 +48,23 @@ pub(crate) use self::error::*;
pub(crate) use self::http_types::*;
pub(crate) use self::io::*;
pub(crate) use self::task::*;
/// Return in iter functions to continue iterating.
pub(crate) const HYPER_ITER_CONTINUE: libc::c_int = 0;
/// Return in iter functions to stop iterating.
#[allow(unused)]
pub(crate) const HYPER_ITER_BREAK: libc::c_int = 1;
/// An HTTP Version that is unspecified.
pub(crate) const HYPER_HTTP_VERSION_NONE: libc::c_int = 0;
/// The HTTP/1.0 version.
pub(crate) const HYPER_HTTP_VERSION_1_0: libc::c_int = 10;
/// The HTTP/1.1 version.
pub(crate) const HYPER_HTTP_VERSION_1_1: libc::c_int = 11;
/// The HTTP/2 version.
pub(crate) const HYPER_HTTP_VERSION_2: libc::c_int = 20;
struct UserDataPointer(*mut std::ffi::c_void);
unsafe impl Send for UserDataPointer {}
unsafe impl Sync for UserDataPointer {}
/// cbindgen:ignore
static VERSION_CSTR: &str = concat!(env!("CARGO_PKG_VERSION"), "\0");
ffi_fn! {
#[doc = " Returns a static ASCII (null terminated) string of the hyper version."] fn

View file

@ -13,38 +13,38 @@ use super::error::hyper_code;
use super::UserDataPointer;
type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
type BoxAny = Box<dyn AsTaskType + Send + Sync>;
/// Return in a poll function to indicate it was ready.
pub(crate) const HYPER_POLL_READY: c_int = 0;
/// Return in a poll function to indicate it is still pending.
///
/// The passed in `hyper_waker` should be registered to wake up the task at
/// some later point.
pub(crate) const HYPER_POLL_PENDING: c_int = 1;
/// Return in a poll function indicate an error.
pub(crate) const HYPER_POLL_ERROR: c_int = 3;
/// A task executor for `hyper_task`s.
pub(crate) struct hyper_executor {
/// The executor of all task futures.
///
/// There should never be contention on the mutex, as it is only locked
/// to drive the futures. However, we cannot guarantee proper usage from
/// `hyper_executor_poll()`, which in C could potentially be called inside
/// one of the stored futures. The mutex isn't re-entrant, so doing so
/// would result in a deadlock, but that's better than data corruption.
driver: Mutex<FuturesUnordered<TaskFuture>>,
/// The queue of futures that need to be pushed into the `driver`.
///
/// This is has a separate mutex since `spawn` could be called from inside
/// a future, which would mean the driver's mutex is already locked.
spawn_queue: Mutex<Vec<TaskFuture>>,
/// This is used to track when a future calls `wake` while we are within
/// `hyper_executor::poll_next`.
is_woken: Arc<ExecWaker>,
}
#[derive(Clone)]
pub(crate) struct WeakExec(Weak<hyper_executor>);
struct ExecWaker(AtomicBool);
/// An async task.
pub(crate) struct hyper_task {
future: BoxFuture<BoxAny>,
output: Option<BoxAny>,
@ -53,24 +53,24 @@ pub(crate) struct hyper_task {
struct TaskFuture {
task: Option<Box<hyper_task>>,
}
/// An async context for a task that contains the related waker.
pub(crate) struct hyper_context<'a>(Context<'a>);
/// A waker that is saved and used to waken a pending task.
pub(crate) struct hyper_waker {
waker: std::task::Waker,
}
/// A descriptor for what type a `hyper_task` value is.
#[repr(C)]
pub(crate) enum hyper_task_return_type {
/// The value of this task is null (does not imply an error).
HYPER_TASK_EMPTY,
/// The value of this task is `hyper_error *`.
HYPER_TASK_ERROR,
/// The value of this task is `hyper_clientconn *`.
HYPER_TASK_CLIENTCONN,
/// The value of this task is `hyper_response *`.
HYPER_TASK_RESPONSE,
/// The value of this task is `hyper_buf *`.
HYPER_TASK_BUF,
}
pub(crate) unsafe trait AsTaskType {