Skip to content

Commit

Permalink
initial constructor callback commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Aug 23, 2023
1 parent 15821c5 commit ae9dcc9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/quic/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace oxen::quic
stream_data_callback stream_data_cb;
stream_open_callback stream_open_cb;
stream_close_callback stream_close_cb;
stream_constructor_callback stream_construct_cb;
user_config config{};

template <typename... Opt>
Expand All @@ -60,6 +61,7 @@ namespace oxen::quic
void handle_ioctx_opt(stream_data_callback func);
void handle_ioctx_opt(stream_open_callback func);
void handle_ioctx_opt(stream_close_callback func);
void handle_ioctx_opt(stream_constructor_callback func);
};

} // namespace oxen::quic
1 change: 1 addition & 0 deletions include/quic/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace oxen::quic
// Stream callbacks
using stream_data_callback = std::function<void(Stream&, bstring_view)>;
using stream_close_callback = std::function<void(Stream&, uint64_t error_code)>;
using stream_constructor_callback = std::function<std::shared_ptr<Stream>(int64_t)>;
// returns 0 on success
using stream_open_callback = std::function<uint64_t(Stream&)>;
using stream_unblocked_callback = std::function<bool(Stream&)>;
Expand Down
5 changes: 4 additions & 1 deletion src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,10 @@ namespace oxen::quic
log::trace(log_cat, "{} called", __PRETTY_FUNCTION__);
log::info(log_cat, "New stream ID:{}", id);

auto stream = std::make_shared<Stream>(*this, _endpoint, context->stream_data_cb, context->stream_close_cb, id);
auto stream =
(context->stream_construct_cb)
? context->stream_construct_cb(id)
: std::make_shared<Stream>(*this, _endpoint, context->stream_data_cb, context->stream_close_cb, id);
stream->set_ready();

log::debug(log_cat, "Local endpoint creating stream to match remote");
Expand Down
6 changes: 6 additions & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ namespace oxen::quic
log::trace(log_cat, "IO context stored stream open callback");
stream_close_cb = std::move(func);
}

void IOContext::handle_ioctx_opt(stream_constructor_callback func)
{
log::trace(log_cat, "IO context stored stream constructor callback");
stream_construct_cb = std::move(func);
}
} // namespace oxen::quic

0 comments on commit ae9dcc9

Please sign in to comment.