open_coroutine_hooks/unix/
socket.rs1use libc::{sockaddr, socklen_t};
2use once_cell::sync::Lazy;
3use std::ffi::c_int;
4
5static SOCKET: Lazy<extern "C" fn(c_int, c_int, c_int) -> c_int> = init_hook!("socket");
6
7#[no_mangle]
8pub extern "C" fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int {
9 open_coroutine_core::syscall::socket(Some(Lazy::force(&SOCKET)), domain, ty, protocol)
10}
11
12static CONNECT: Lazy<extern "C" fn(c_int, *const sockaddr, socklen_t) -> c_int> =
13 init_hook!("connect");
14
15#[no_mangle]
16pub extern "C" fn connect(socket: c_int, address: *const sockaddr, len: socklen_t) -> c_int {
17 open_coroutine_core::syscall::connect(Some(Lazy::force(&CONNECT)), socket, address, len)
18}
19
20static LISTEN: Lazy<extern "C" fn(c_int, c_int) -> c_int> = init_hook!("listen");
21
22#[no_mangle]
23pub extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int {
24 open_coroutine_core::syscall::listen(Some(Lazy::force(&LISTEN)), socket, backlog)
25}
26
27static ACCEPT: Lazy<extern "C" fn(c_int, *mut sockaddr, *mut socklen_t) -> c_int> =
28 init_hook!("accept");
29
30#[no_mangle]
31pub extern "C" fn accept(
32 socket: c_int,
33 address: *mut sockaddr,
34 address_len: *mut socklen_t,
35) -> c_int {
36 open_coroutine_core::syscall::accept(Some(Lazy::force(&ACCEPT)), socket, address, address_len)
37}
38
39static SHUTDOWN: Lazy<extern "C" fn(c_int, c_int) -> c_int> = init_hook!("shutdown");
40
41#[no_mangle]
42pub extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int {
43 open_coroutine_core::syscall::shutdown(Some(Lazy::force(&SHUTDOWN)), socket, how)
44}