MCPcopy Create free account
hub / github.com/Kitware/CMake / cmUVStreamRead

Function cmUVStreamRead

Source/cmUVStream.h:79–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78template <typename ReadCallback, typename FinishCallback>
79std::unique_ptr<cmUVStreamReadHandle> cmUVStreamRead(uv_stream_t* stream,
80 ReadCallback onRead,
81 FinishCallback onFinish)
82{
83 auto handle = cm::make_unique<cmUVStreamReadHandle>();
84 handle->OnRead = std::move(onRead);
85 handle->OnFinish = std::move(onFinish);
86
87 stream->data = handle.get();
88 uv_read_start(
89 stream,
90 [](uv_handle_t* s, std::size_t suggestedSize, uv_buf_t* buffer) {
91 auto* data = static_cast<cmUVStreamReadHandle*>(s->data);
92 data->Buffer.resize(suggestedSize);
93 buffer->base = data->Buffer.data();
94 buffer->len = suggestedSize;
95 },
96 [](uv_stream_t* s, ssize_t nread, uv_buf_t const* buffer) {
97 auto* data = static_cast<cmUVStreamReadHandle*>(s->data);
98 if (nread > 0) {
99 (void)buffer;
100 assert(buffer->base == data->Buffer.data());
101 data->Buffer.resize(nread);
102 data->OnRead(std::move(data->Buffer));
103 } else if (nread < 0 /*|| nread == UV_EOF*/) {
104 data->OnFinish();
105 uv_read_stop(s);
106 }
107 });
108
109 return handle;
110}

Callers 12

testUVStreamReadFunction · 0.85
testUVStreamReadLeakFunction · 0.85
RunProcessMethod · 0.85
RunMakeCommandMethod · 0.85
RunCommandMethod · 0.85
cmExecuteProcessCommandFunction · 0.85
startMethod · 0.85
RunSingleCommandMethod · 0.85
WaitForLineMethod · 0.85
RunChildMethod · 0.85
RunMakeCommandMethod · 0.85
RunTestMethod · 0.85

Calls 7

moveFunction · 0.85
uv_read_startFunction · 0.85
uv_read_stopFunction · 0.50
getMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
OnReadMethod · 0.45

Tested by 7

testUVStreamReadFunction · 0.68
testUVStreamReadLeakFunction · 0.68
RunMakeCommandMethod · 0.68
RunCommandMethod · 0.68
RunChildMethod · 0.68
RunMakeCommandMethod · 0.68
RunTestMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…