Skip to content

Commit b616f6f

Browse files
ywave620richardlau
authored andcommitted
src,stream: improve WriteString
Introduce HasDoTryWrite and make use of it in WriteString PR-URL: #51155 Reviewed-By: Luigi Pinca <[email protected]>
1 parent 06a6eef commit b616f6f

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/stream_base.cc

+2-2
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

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ 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+
// Indicates whether this subclass overrides the DoTryWrite
248+
virtual inline bool HasDoTryWrite() const { return false; }
247249
// Initiate a write of data.
248250
// Upon an immediate failure, a libuv error code is returned,
249251
// w->Done() will never be called and caller should free `bufs`.

src/stream_wrap.h

+1
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)