feat: cross-platform uSockets support and route cache optimization
1. Cross-platform uSockets configuration - Use @VMODROOT for portable library paths - Support macOS (arm64/x86_64), Windows, and Linux - Auto-detect Homebrew paths for libuv on macOS 2. Route cache optimization (3x performance boost) - Replace LRU cache with FastRouteCache for dynamic routes - Zero-overhead cache lookup (no TTL check, no LRU reordering) - Dynamic route performance: 30k -> 97k RPS 3. New test files - Go-based integration tests for picoev and uSockets - FastCache optimization validation tests - Benchmark comparison tools
This commit is contained in:
+49
-17
@@ -1,11 +1,43 @@
|
||||
module usockets
|
||||
|
||||
#flag -DLIBUS_USE_LIBUV
|
||||
#flag -DLIBUS_NO_SSL
|
||||
#flag -IC:/Users/admin/.vmodules/hono/usockets/include
|
||||
#flag -LC:/Users/admin/.vmodules/hono/usockets/lib
|
||||
#flag C:/Users/admin/.vmodules/hono/usockets/lib/libusockets_full.a
|
||||
#flag -lws2_32 -liphlpapi -lpsapi -luserenv -lole32
|
||||
// 条件编译:根据操作系统选择正确的路径和库
|
||||
// @VMODROOT 指向包含 v.mod 的模块根目录 (v-hono/)
|
||||
|
||||
$if windows {
|
||||
#flag -DLIBUS_USE_LIBUV
|
||||
#flag -DLIBUS_NO_SSL
|
||||
#flag -I@VMODROOT/usockets/include
|
||||
#flag -L@VMODROOT/lib
|
||||
#flag @VMODROOT/lib/libusockets_full.a
|
||||
#flag -lws2_32 -liphlpapi -lpsapi -luserenv -lole32
|
||||
} $else $if macos {
|
||||
// macOS: 支持 Apple Silicon (M1/M2/M3) 和 Intel Mac
|
||||
#flag -DLIBUS_USE_LIBUV
|
||||
#flag -DLIBUS_NO_SSL
|
||||
|
||||
// libuv 路径 - 根据架构选择 Homebrew 路径
|
||||
$if arm64 {
|
||||
#flag -I/opt/homebrew/include
|
||||
#flag -L/opt/homebrew/lib
|
||||
} $else {
|
||||
#flag -I/usr/local/include
|
||||
#flag -L/usr/local/lib
|
||||
}
|
||||
|
||||
// uSockets 库路径
|
||||
#flag -I@VMODROOT/usockets/include
|
||||
#flag -L@VMODROOT/lib
|
||||
#flag @VMODROOT/lib/libusockets_full.a
|
||||
#flag -luv
|
||||
} $else {
|
||||
// Linux 和其他平台
|
||||
#flag -DLIBUS_USE_LIBUV
|
||||
#flag -DLIBUS_NO_SSL
|
||||
#flag -I@VMODROOT/usockets/include
|
||||
#flag -L@VMODROOT/lib
|
||||
#flag @VMODROOT/lib/libusockets_full.a
|
||||
#flag -luv
|
||||
}
|
||||
|
||||
#include "libusockets.h"
|
||||
|
||||
@@ -20,13 +52,13 @@ struct C.us_socket_t {}
|
||||
struct C.us_listen_socket_t {}
|
||||
|
||||
struct C.us_socket_context_options_t {
|
||||
key_file_name voidptr
|
||||
cert_file_name voidptr
|
||||
passphrase voidptr
|
||||
dh_params_file_name voidptr
|
||||
ca_file_name voidptr
|
||||
ssl_ciphers voidptr
|
||||
ssl_prefer_low_memory_usage int
|
||||
key_file_name voidptr
|
||||
cert_file_name voidptr
|
||||
passphrase voidptr
|
||||
dh_params_file_name voidptr
|
||||
ca_file_name voidptr
|
||||
ssl_ciphers voidptr
|
||||
ssl_prefer_low_memory_usage int
|
||||
}
|
||||
|
||||
fn C.us_create_loop(hint voidptr, wakeup_cb voidptr, pre_cb voidptr, post_cb voidptr, ext_size u32) Loop
|
||||
@@ -54,15 +86,15 @@ fn empty_pre(loop Loop) {}
|
||||
fn empty_post(loop Loop) {}
|
||||
|
||||
pub fn create_loop() Loop {
|
||||
return C.us_create_loop(unsafe { nil }, empty_wakeup, empty_pre, empty_post, 0)
|
||||
return C.us_create_loop(unsafe { nil }, empty_wakeup, empty_pre, empty_post, 0)
|
||||
}
|
||||
|
||||
pub fn (l Loop) run() { C.us_loop_run(l) }
|
||||
pub fn (l Loop) free() { C.us_loop_free(l) }
|
||||
|
||||
pub fn create_socket_context(loop Loop) SocketContext {
|
||||
options := C.us_socket_context_options_t{}
|
||||
return C.us_create_socket_context(0, loop, 0, options)
|
||||
options := C.us_socket_context_options_t{}
|
||||
return C.us_create_socket_context(0, loop, 0, options)
|
||||
}
|
||||
|
||||
pub fn (ctx SocketContext) free() { C.us_socket_context_free(0, ctx) }
|
||||
@@ -73,7 +105,7 @@ pub fn (ctx SocketContext) on_writable(h voidptr) { C.us_socket_context_on_writa
|
||||
pub fn (ctx SocketContext) on_timeout(h voidptr) { C.us_socket_context_on_timeout(0, ctx, h) }
|
||||
pub fn (ctx SocketContext) on_end(h voidptr) { C.us_socket_context_on_end(0, ctx, h) }
|
||||
pub fn (ctx SocketContext) listen(port int) ListenSocket {
|
||||
return C.us_socket_context_listen(0, ctx, unsafe { nil }, port, 0, 0)
|
||||
return C.us_socket_context_listen(0, ctx, unsafe { nil }, port, 0, 0)
|
||||
}
|
||||
|
||||
pub fn (s Socket) write_bytes(data string) int { return C.us_socket_write(0, s, data.str, data.len, 0) }
|
||||
|
||||
Reference in New Issue
Block a user