Skip to content

Commit

Permalink
avoid multiple inheritance in stream reader context
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Jul 20, 2024
1 parent 9be8202 commit 75fbe74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/hx/libs/asys/libuv/net/LibuvIpcSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace
hx::asys::libuv::net::LibuvIpcSocket::LibuvIpcSocket(uv_pipe_t* pipe)
: pipe(pipe)
, reader(new hx::asys::libuv::stream::StreamReader_obj(reinterpret_cast<uv_stream_t*>(pipe)))
, writer(new hx::asys::libuv::stream::StreamReader_obj(reinterpret_cast<uv_stream_t*>(pipe)))
, writer(new hx::asys::libuv::stream::StreamWriter_obj(reinterpret_cast<uv_stream_t*>(pipe)))
{
HX_OBJ_WB_NEW_MARKED_OBJECT(this);

Expand Down
12 changes: 6 additions & 6 deletions src/hx/libs/asys/libuv/net/LibuvTcpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace
void onAlloc(uv_handle_t* handle, const size_t suggested, uv_buf_t* buffer)
{
auto ctx = static_cast<hx::asys::libuv::net::LibuvTcpSocket::Ctx*>(handle->data);
auto& staging = ctx->staging.emplace_back(suggested);
auto& staging = ctx->stream.staging.emplace_back(suggested);

buffer->base = staging.data();
buffer->len = staging.size();
Expand All @@ -124,24 +124,24 @@ namespace

if (len <= 0)
{
ctx->reject(len);
ctx->stream.reject(len);

return;
}

ctx->buffer.insert(ctx->buffer.end(), read->base, read->base + len);
ctx->consume();
ctx->stream.buffer.insert(ctx->stream.buffer.end(), read->base, read->base + len);
ctx->stream.consume();
}
}

hx::asys::libuv::net::LibuvTcpSocket::Ctx::Ctx(Dynamic cbSuccess, Dynamic cbFailure)
: hx::asys::libuv::BaseRequest(cbSuccess, cbFailure)
, hx::asys::libuv::stream::StreamReader_obj::Ctx(reinterpret_cast<uv_stream_t*>(&tcp))
, tcp()
, connection()
, shutdown()
, keepAlive(hx::asys::libuv::net::KEEP_ALIVE_VALUE)
, status(0)
, stream(reinterpret_cast<uv_stream_t*>(&tcp))
{
shutdown.data = this;
connection.data = this;
Expand Down Expand Up @@ -176,7 +176,7 @@ void hx::asys::libuv::net::LibuvTcpSocket::Ctx::onShutdown(uv_shutdown_t* handle

hx::asys::libuv::net::LibuvTcpSocket::LibuvTcpSocket(Ctx* ctx)
: ctx(ctx)
, reader(new hx::asys::libuv::stream::StreamReader_obj(ctx, onAlloc, onRead))
, reader(new hx::asys::libuv::stream::StreamReader_obj(&ctx->stream, onAlloc, onRead))
, writer(new hx::asys::libuv::stream::StreamWriter_obj(reinterpret_cast<uv_stream_t*>(&ctx->tcp)))
{
HX_OBJ_WB_NEW_MARKED_OBJECT(this);
Expand Down
3 changes: 2 additions & 1 deletion src/hx/libs/asys/libuv/net/LibuvTcpSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ namespace hx::asys::libuv::net
hx::asys::libuv::stream::StreamReader reader;

public:
struct Ctx final : public BaseRequest, public hx::asys::libuv::stream::StreamReader_obj::Ctx
struct Ctx final : public BaseRequest
{
uv_tcp_t tcp;
uv_connect_t connection;
uv_shutdown_t shutdown;
int keepAlive;
int status;
hx::asys::libuv::stream::StreamReader_obj::Ctx stream;

Ctx(Dynamic cbSuccess, Dynamic cbFailure);

Expand Down

0 comments on commit 75fbe74

Please sign in to comment.