summaryrefslogtreecommitdiff
path: root/ext/net
diff options
context:
space:
mode:
Diffstat (limited to 'ext/net')
-rw-r--r--ext/net/ops.rs23
-rw-r--r--ext/net/ops_unix.rs7
2 files changed, 19 insertions, 11 deletions
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index 739807123..538eab2d9 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -103,6 +103,15 @@ pub(crate) struct AcceptArgs {
pub transport: String,
}
+pub(crate) fn accept_err(e: std::io::Error) -> AnyError {
+ // FIXME(bartlomieju): compatibility with current JS implementation
+ if let std::io::ErrorKind::Interrupted = e.kind() {
+ bad_resource("Listener has been closed")
+ } else {
+ e.into()
+ }
+}
+
async fn accept_tcp(
state: Rc<RefCell<OpState>>,
args: AcceptArgs,
@@ -119,15 +128,11 @@ async fn accept_tcp(
.try_borrow_mut()
.ok_or_else(|| custom_error("Busy", "Another accept task is ongoing"))?;
let cancel = RcRef::map(resource, |r| &r.cancel);
- let (tcp_stream, _socket_addr) =
- listener.accept().try_or_cancel(cancel).await.map_err(|e| {
- // FIXME(bartlomieju): compatibility with current JS implementation
- if let std::io::ErrorKind::Interrupted = e.kind() {
- bad_resource("Listener has been closed")
- } else {
- e.into()
- }
- })?;
+ let (tcp_stream, _socket_addr) = listener
+ .accept()
+ .try_or_cancel(cancel)
+ .await
+ .map_err(accept_err)?;
let local_addr = tcp_stream.local_addr()?;
let remote_addr = tcp_stream.peer_addr()?;
diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs
index 20d085a5d..58bfa0557 100644
--- a/ext/net/ops_unix.rs
+++ b/ext/net/ops_unix.rs
@@ -91,8 +91,11 @@ pub(crate) async fn accept_unix(
.try_borrow_mut()
.ok_or_else(|| custom_error("Busy", "Listener already in use"))?;
let cancel = RcRef::map(resource, |r| &r.cancel);
- let (unix_stream, _socket_addr) =
- listener.accept().try_or_cancel(cancel).await?;
+ let (unix_stream, _socket_addr) = listener
+ .accept()
+ .try_or_cancel(cancel)
+ .await
+ .map_err(crate::ops::accept_err)?;
let local_addr = unix_stream.local_addr()?;
let remote_addr = unix_stream.peer_addr()?;