-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): split up resource code and add a resource test (#472)
Partially extracted from #440 Also pulls in `BufMutViewWhole` from that PR that will be required for buffer soundness in a later PR -- you should not split a buffer that is owned by JavaScript.
- Loading branch information
Showing
13 changed files
with
897 additions
and
21 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
// Think of Resources as File Descriptors. They are integers that are allocated | ||
// by the privileged side of Deno which refer to various rust objects that need | ||
// to be persisted between various ops. For example, network sockets are | ||
// resources. Resources may or may not correspond to a real operating system | ||
// file descriptor (hence the different name). | ||
|
||
use anyhow::Error; | ||
use futures::Future; | ||
use std::pin::Pin; | ||
|
||
mod buffer_strategy; | ||
mod buffers; | ||
mod resource; | ||
mod resource_handle; | ||
mod resource_table; | ||
|
||
pub use buffer_strategy::AdaptiveBufferStrategy; | ||
pub use buffers::BufMutView; | ||
pub use buffers::BufMutViewWhole; | ||
pub use buffers::BufView; | ||
pub use resource::Resource; | ||
pub use resource_handle::ResourceHandle; | ||
pub use resource_handle::ResourceHandleFd; | ||
pub use resource_handle::ResourceHandleSocket; | ||
pub use resource_table::ResourceId; | ||
pub use resource_table::ResourceTable; | ||
|
||
/// Returned by resource shutdown methods | ||
pub type AsyncResult<T> = Pin<Box<dyn Future<Output = Result<T, Error>>>>; | ||
|
||
pub enum WriteOutcome { | ||
Partial { nwritten: usize, view: BufView }, | ||
Full { nwritten: usize }, | ||
} | ||
|
||
impl WriteOutcome { | ||
pub fn nwritten(&self) -> usize { | ||
match self { | ||
WriteOutcome::Partial { nwritten, .. } => *nwritten, | ||
WriteOutcome::Full { nwritten } => *nwritten, | ||
} | ||
} | ||
} |
Oops, something went wrong.