Skip to content

Commit 6d48cec

Browse files
committed
src,stream: improve WriteString
Introduce HasDoTryWrite and make use of it in WriteString
1 parent 99f6084 commit 6d48cec

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/stream_base.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ StreamWriteResult StreamBase::Write(uv_buf_t* bufs,
9191
for (size_t i = 0; i < count; ++i) total_bytes += bufs[i].len;
9292
bytes_written_ += total_bytes;
9393

94-
if (send_handle == nullptr && !skip_try_write) {
94+
if (send_handle == nullptr && HasDoTryWrite() && !skip_try_write) {
9595
err = DoTryWrite(&bufs, &count);
9696
if (err != 0 || count == 0) {
9797
return StreamWriteResult{false, err, nullptr, total_bytes, {}};
@@ -365,7 +365,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
365365
size_t synchronously_written = 0;
366366
uv_buf_t buf;
367367

368-
bool try_write = storage_size <= sizeof(stack_storage) &&
368+
bool try_write = HasDoTryWrite() && storage_size <= sizeof(stack_storage) &&
369369
(!IsIPCPipe() || send_handle_obj.IsEmpty());
370370
if (try_write) {
371371
data_size = StringBytes::Write(isolate,

src/stream_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class StreamResource {
244244
// `*bufs` and `*count` accordingly. This is a no-op by default.
245245
// Return 0 for success and a libuv error code for failures.
246246
virtual int DoTryWrite(uv_buf_t** bufs, size_t* count);
247+
virtual inline bool HasDoTryWrite() const { return false; }
247248
// Initiate a write of data.
248249
// Upon an immediate failure, a libuv error code is returned,
249250
// w->Done() will never be called and caller should free `bufs`.

src/stream_wrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase {
5252
// Resource implementation
5353
int DoShutdown(ShutdownWrap* req_wrap) override;
5454
int DoTryWrite(uv_buf_t** bufs, size_t* count) override;
55+
inline bool HasDoTryWrite() const override { return true; };
5556
int DoWrite(WriteWrap* w,
5657
uv_buf_t* bufs,
5758
size_t count,

0 commit comments

Comments
 (0)