Add rust experiment example
This commit is contained in:
+5
-2
@@ -1,4 +1,7 @@
|
||||
default:
|
||||
rm -f *.o
|
||||
make -C ../uSockets
|
||||
g++ -O3 -std=c++17 -flto -DUWS_NO_ZLIB -I ../src -I ../uSockets/src App.cpp -c
|
||||
gcc -O3 -flto example.c *.o -lstdc++ ../uSockets/uSockets.a -o example
|
||||
g++ -c -O3 -std=c++17 -flto -DUWS_NO_ZLIB -I ../src -I ../uSockets/src App.cpp
|
||||
$(AR) rvs uWebSockets.a App.o ../uSockets/*.o
|
||||
gcc -O3 -flto example.c *.o -lstdc++ ../uSockets/uSockets.a -o c_example
|
||||
rustc -C link-arg=uWebSockets.a -C link-arg=-lstdc++ -C opt-level=3 -C lto -L all=. example.rs -o rust_example
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/* automatically generated by rust-bindgen 0.59.2 */
|
||||
|
||||
pub type size_t = ::std::os::raw::c_ulong;
|
||||
pub type wchar_t = ::std::os::raw::c_uint;
|
||||
#[repr(C)]
|
||||
#[repr(align(16))]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct max_align_t {
|
||||
pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
|
||||
pub __bindgen_padding_0: u64,
|
||||
pub __clang_max_align_nonce2: u128,
|
||||
}
|
||||
#[test]
|
||||
fn bindgen_test_layout_max_align_t() {
|
||||
assert_eq!(
|
||||
::std::mem::size_of::<max_align_t>(),
|
||||
32usize,
|
||||
concat!("Size of: ", stringify!(max_align_t))
|
||||
);
|
||||
assert_eq!(
|
||||
::std::mem::align_of::<max_align_t>(),
|
||||
16usize,
|
||||
concat!("Alignment of ", stringify!(max_align_t))
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe {
|
||||
&(*(::std::ptr::null::<max_align_t>())).__clang_max_align_nonce1 as *const _ as usize
|
||||
},
|
||||
0usize,
|
||||
concat!(
|
||||
"Offset of field: ",
|
||||
stringify!(max_align_t),
|
||||
"::",
|
||||
stringify!(__clang_max_align_nonce1)
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
unsafe {
|
||||
&(*(::std::ptr::null::<max_align_t>())).__clang_max_align_nonce2 as *const _ as usize
|
||||
},
|
||||
16usize,
|
||||
concat!(
|
||||
"Offset of field: ",
|
||||
stringify!(max_align_t),
|
||||
"::",
|
||||
stringify!(__clang_max_align_nonce2)
|
||||
)
|
||||
);
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct uws_app_s {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct uws_req_s {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct uws_res_s {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
pub type uws_app_t = uws_app_s;
|
||||
pub type uws_req_t = uws_req_s;
|
||||
pub type uws_res_t = uws_res_s;
|
||||
extern "C" {
|
||||
pub fn uws_create_app() -> *mut uws_app_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn uws_app_get(
|
||||
app: *mut uws_app_t,
|
||||
pattern: *const ::std::os::raw::c_char,
|
||||
handler: ::std::option::Option<
|
||||
unsafe extern "C" fn(arg1: *mut uws_res_t,
|
||||
arg2: *mut uws_req_t),
|
||||
>,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn uws_app_run(arg1: *mut uws_app_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn uws_app_listen(
|
||||
app: *mut uws_app_t,
|
||||
port: ::std::os::raw::c_int,
|
||||
handler: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn uws_res_end(res: *mut uws_res_t, data: *const ::std::os::raw::c_char, length: size_t);
|
||||
}
|
||||
|
||||
extern "C" fn listen_handler(listen_socket: *mut ::std::os::raw::c_void) {
|
||||
println!("Listening");
|
||||
}
|
||||
|
||||
extern "C" fn get_handler(res: *mut uws_res_t, req: *mut uws_req_t) {
|
||||
unsafe {
|
||||
uws_res_end(res, "Hello!".as_bytes().as_ptr(), 6);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let app = uws_create_app();
|
||||
uws_app_get(app, ::std::ffi::CString::new("/*").expect("").as_ptr(), ::std::option::Option::Some(get_handler));
|
||||
uws_app_listen(app, 3000, ::std::option::Option::Some(listen_handler));
|
||||
uws_app_run(app);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef LIBUWS_CAPI_HEADER
|
||||
#define LIBUS_CAPI_HEADER
|
||||
#define LIBUWS_CAPI_HEADER
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user