Skip to content

Commit

Permalink
feat: add auto accept
Browse files Browse the repository at this point in the history
  • Loading branch information
Chronostasys committed Sep 9, 2024
1 parent fa11c27 commit c858f5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 15 additions & 1 deletion planglib/std/libuv.pi
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn set_data_for_handle<H|T> (handle:*H, data:*T) void {
/// # get_data_for_handle
///
/// This function is used to get the data of the handle.
/// It will undo the pinning and keep-alive of the data
/// It will undo the keep-alive of the data
///
/// For more information, see the `set_data_for_handle` function.
pub fn get_data_for_handle<H|T> (handle:*H) *T {
Expand All @@ -124,3 +124,17 @@ pub fn get_data_for_handle<H|T> (handle:*H) *T {
}


/// # get_data_for_handle_raw
///
/// This function is used to get the data of the handle.
///
/// Unlike the `get_data_for_handle` function, this function
/// has no side effect, can be used to get the data without
/// undoing the keep-alive.
pub fn get_data_for_handle_raw<H|T> (handle:*H) *T {
let re = uv_handle_get_data(unsafe_cast<()>(handle));
// gc::rm_alive_pinned(re);
return unsafe_cast<T>(re);
}


5 changes: 4 additions & 1 deletion planglib/std/task/reactor.pi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ fn close_cb(handle:*()) void {


fn conn_cb(server:*libuv::uv_stream_t, status:u32) void {
let on_conn = libuv::get_data_for_handle<libuv::uv_stream_t|||=>void>(server);
let client = libuv::new_uv_tcp_t();
libuv::uv_tcp_init(GLOBAL_REACTOR.loop, unsafe_cast<libuv::uv_tcp_t>(client));
libuv::uv_accept(server, unsafe_cast<libuv::uv_stream_t>(client));
let on_conn = libuv::get_data_for_handle_raw<libuv::uv_stream_t|||=>void>(server);
(*on_conn)();
return;
}
Expand Down

0 comments on commit c858f5b

Please sign in to comment.