mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(ext/node): check if resource can be used with write_vectored (#19868)
Fixes https://github.com/denoland/deno/issues/19766 Fixes https://github.com/denoland/deno/issues/19846
This commit is contained in:
parent
7e1218cd8f
commit
51b3534b3d
3 changed files with 12 additions and 2 deletions
|
@ -1078,6 +1078,11 @@ impl Resource for UpgradeStream {
|
|||
}
|
||||
}
|
||||
|
||||
#[op(fast)]
|
||||
pub fn op_can_write_vectored(state: &mut OpState, rid: ResourceId) -> bool {
|
||||
state.resource_table.get::<UpgradeStream>(rid).is_ok()
|
||||
}
|
||||
|
||||
#[op]
|
||||
pub async fn op_raw_write_vectored(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
|
|
|
@ -121,6 +121,7 @@ deno_core::extension!(
|
|||
http_next::op_http_upgrade_websocket_next,
|
||||
http_next::op_http_upgrade_raw,
|
||||
http_next::op_raw_write_vectored,
|
||||
http_next::op_can_write_vectored,
|
||||
http_next::op_http_try_wait,
|
||||
http_next::op_http_wait,
|
||||
],
|
||||
|
|
|
@ -199,14 +199,18 @@ export class LibuvStreamWrap extends HandleWrap {
|
|||
allBuffers: boolean,
|
||||
): number {
|
||||
const supportsWritev = this.provider === providerType.TCPSERVERWRAP;
|
||||
const rid = this[kStreamBaseField]!.rid;
|
||||
// Fast case optimization: two chunks, and all buffers.
|
||||
if (chunks.length === 2 && allBuffers && supportsWritev) {
|
||||
if (
|
||||
chunks.length === 2 && allBuffers && supportsWritev &&
|
||||
ops.op_can_write_vectored(rid)
|
||||
) {
|
||||
// String chunks.
|
||||
if (typeof chunks[0] === "string") chunks[0] = Buffer.from(chunks[0]);
|
||||
if (typeof chunks[1] === "string") chunks[1] = Buffer.from(chunks[1]);
|
||||
|
||||
ops.op_raw_write_vectored(
|
||||
this[kStreamBaseField]!.rid,
|
||||
rid,
|
||||
chunks[0],
|
||||
chunks[1],
|
||||
).then((nwritten) => {
|
||||
|
|
Loading…
Reference in a new issue