Skip to content

Commit fdd0f9d

Browse files
committed
UVStream, feat: close fd before deleting the object.
1 parent 5415a6b commit fdd0f9d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

fibjs/include/UVStream.h

+20
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ class UVStream : public Stream_base {
5252
});
5353
}
5454

55+
static void on_delete(uv_handle_t* handle)
56+
{
57+
UVStream* pThis = container_of(handle, UVStream, m_pipe);
58+
delete pThis;
59+
}
60+
61+
virtual void Delete()
62+
{
63+
result_t hr = uv_call([&] {
64+
if (uv_is_closing((uv_handle_t*)&m_pipe))
65+
return CALL_E_INVALID_CALL;
66+
67+
uv_close((uv_handle_t*)&m_pipe, on_delete);
68+
return CALL_E_PENDDING;
69+
});
70+
71+
if (hr != CALL_E_PENDDING)
72+
delete this;
73+
}
74+
5575
public:
5676
// Stream_base
5777
class AsyncRead : public AsyncEvent {

0 commit comments

Comments
 (0)