Skip to content

Commit

Permalink
Refactor types for improved library stability (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Stanislav Gryumov <[email protected]>
  • Loading branch information
AlexKlo and gryumov authored Jan 16, 2025
1 parent 2a5a0b2 commit 83a0f49
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Libwebsockets"
uuid = "30a1cee6-c274-443c-b274-d8ea34e8f87d"
version = "1.0.0"
version = "1.0.1"

[deps]
libwebsockets_jll = "b6b84edf-6aef-5ff6-9b66-656961a84a09"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ function ws_open(callback::Function, addr::String, port::Int, path::String)
callback_ptr = @cfunction(ws_callback, Cint, (Ptr{Cvoid}, Cint, Ptr{Cvoid}, Ptr{Cvoid}, Csize_t))
protocols = [
LwsProtocols(pointer("ws"), callback_ptr, 0, 0, 0, C_NULL, 0),
LwsProtocols()
LwsProtocols(C_NULL, C_NULL, 0, 0, 0, C_NULL, 0)
]
user = UserData(callback)

ctx_info = LwsContextCreationInfo()
ctx_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
ctx_info.port = CONTEXT_PORT_NO_LISTEN
ctx_info.user = Base.unsafe_convert(Ptr{UserData}, Ref(user))
ctx_info.protocols = Base.unsafe_convert(Ptr{LwsProtocols}, Ref(protocols[1]))
ctx_info.protocols = pointer(protocols)
ws_ctx = lws_create_context(Ref(ctx_info))

conn_info = LwsClientConnectInfo()
Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ function ws_open(callback::Function, addr::String, port::Int, path::String)
callback_ptr = @cfunction(ws_callback, Cint, (Ptr{Cvoid}, Cint, Ptr{Cvoid}, Ptr{Cvoid}, Csize_t))
protocols = [
LwsProtocols(pointer("ws"), callback_ptr, 0, 0, 0, C_NULL, 0),
LwsProtocols()
LwsProtocols(C_NULL, C_NULL, 0, 0, 0, C_NULL, 0)
]
user = UserData(callback)

ctx_info = LwsContextCreationInfo()
ctx_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
ctx_info.port = CONTEXT_PORT_NO_LISTEN
ctx_info.user = Base.unsafe_convert(Ptr{UserData}, Ref(user))
ctx_info.protocols = Base.unsafe_convert(Ptr{LwsProtocols}, Ref(protocols[1]))
ctx_info.protocols = pointer(protocols)
ws_ctx = lws_create_context(Ref(ctx_info))

conn_info = LwsClientConnectInfo()
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ function ws_open(callback::Function, addr::String, port::Int, path::String)
callback_ptr = @cfunction(ws_callback, Cint, (Ptr{Cvoid}, Cint, Ptr{Cvoid}, Ptr{Cvoid}, Csize_t))
protocols = [
LwsProtocols(pointer("ws"), callback_ptr, 0, 0, 0, C_NULL, 0),
LwsProtocols()
LwsProtocols(C_NULL, C_NULL, 0, 0, 0, C_NULL, 0)
]
user = UserData(callback)

ctx_info = LwsContextCreationInfo()
ctx_info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
ctx_info.port = CONTEXT_PORT_NO_LISTEN
ctx_info.user = Base.unsafe_convert(Ptr{UserData}, Ref(user))
ctx_info.protocols = Base.unsafe_convert(Ptr{LwsProtocols}, Ref(protocols[1]))
ctx_info.protocols = pointer(protocols)
ws_ctx = lws_create_context(Ref(ctx_info))

conn_info = LwsClientConnectInfo()
Expand Down
17 changes: 16 additions & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ export lws_add_http_common_headers,
lwsl_visible,
lwsl_wsi_get_cx,
lwsws_get_config_globals,
lwsws_get_config_vhosts
lwsws_get_config_vhosts,
lws_sul_schedule,
lws_retry_sul_schedule,
lws_retry_sul_schedule_retry_wsi

function lwsl_context_get_cx(cx)
ccall((:lwsl_context_get_cx, libwebsockets), Ptr{LwsLogCx}, (Ptr{LwsContext},), cx)
Expand Down Expand Up @@ -775,3 +778,15 @@ end
function lws_tls_session_dump_load(vh, host, port, cb_load, opq)
ccall((:lws_tls_session_dump_load, libwebsockets), Cint, (Ptr{LwsVhost}, Ptr{Cchar}, UInt16, Ptr{Cvoid}, Ptr{Cvoid}), vh, host, port, cb_load, opq)
end

function lws_sul_schedule(ctx, tsi, sul, _cb, _us)
ccall((:lws_sul_schedule, libwebsockets), Cvoid, (Ptr{LwsContext}, Cint, Ptr{LwsSortedUsecList}, Ptr{Cvoid}, Cuint), ctx, tsi, sul, _cb, _us)
end

function lws_retry_sul_schedule(context, tid, sul, retry, cb, ctry)
ccall((:lws_retry_sul_schedule, libwebsockets), Cint, (Ptr{LwsContext}, Cint, Ptr{LwsSortedUsecList}, Ptr{LwsRetryBo}, Ptr{Cvoid}, Ptr{Cushort}), context, tid, sul, retry, cb, ctry)
end

function lws_retry_sul_schedule_retry_wsi(wsi, sul, cb, ctry)
ccall((:lws_retry_sul_schedule_retry_wsi, libwebsockets), Cint, (Ptr{Lws}, Ptr{LwsSortedUsecList}, Ptr{Cvoid}, Ptr{Cushort}), wsi, sul, cb, ctry)
end
77 changes: 56 additions & 21 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ export Lws,
LwsTokens,
LwsVhost,
LwsWritePassthru,
LwsX509Cert
LwsX509Cert,
LwsSslCtxSt,
LwsSystemOpts,
LwsRetryBo,
LwsDll2,
LwsStateNotifyLink,
LwsSortedUsecList

struct LwsContext end
struct LwsVhost end
Expand All @@ -54,6 +60,7 @@ struct LwsSequencer end
struct LwsSpa end
struct LwsAc end
struct LwsX509Cert end
struct LwsSslCtxSt end

Base.@kwdef mutable struct LwsLogCxUnion
emit::Ptr{Cvoid} = C_NULL
Expand Down Expand Up @@ -105,7 +112,7 @@ Base.@kwdef mutable struct LwsExtension
client_offer::Ptr{Cchar} = C_NULL
end

Base.@kwdef mutable struct LwsProtocols
Base.@kwdef struct LwsProtocols
name::Ptr{Cchar} = C_NULL
callback::Ptr{Cvoid} = C_NULL
per_session_data_size::Csize_t = 0
Expand Down Expand Up @@ -176,6 +183,44 @@ Base.@kwdef mutable struct LwsHttpMount
basic_auth_login_file::Ptr{Cchar} = C_NULL
end

struct LwsSystemOpts
reboot::Ptr{Cvoid}
set_clock::Ptr{Cvoid}
attach::Ptr{Cvoid}
captive_portal_detect_request::Ptr{Cvoid}
metric_report::Ptr{Cvoid}
jit_trust_query::Ptr{Cvoid}
wake_latency_us::UInt32
end

mutable struct LwsRetryBo
retry_ms_table::Ptr{UInt32}
retry_ms_table_count::UInt16
conceal_count::UInt16
secs_since_valid_ping::UInt16
secs_since_valid_hangup::UInt16
jitter_percent::UInt8
end

Base.@kwdef struct LwsDll2
prev::Ptr{LwsDll2} = C_NULL
next::Ptr{LwsDll2} = C_NULL
owner::Ptr{Cvoid} = C_NULL
end

struct LwsStateNotifyLink
list::LwsDll2
notify_cb::Ptr{Cvoid}
name::Ptr{Cchar}
end

Base.@kwdef mutable struct LwsSortedUsecList
list::LwsDll2 = LwsDll2()
us::Int64 = 0
cb::Ptr{Cvoid} = C_NULL
latency_us::UInt32 = UInt32(0)
end

Base.@kwdef mutable struct LwsContextCreationInfo
iface::Ptr{Cchar} = C_NULL
protocols::Ptr{LwsProtocols} = C_NULL
Expand All @@ -194,13 +239,7 @@ Base.@kwdef mutable struct LwsContextCreationInfo
max_http_header_data2::Cuint = 0
max_http_header_pool2::Cuint = 0
keepalive_timeout::Cint = 0
http2_settings1::Cuint = 0
http2_settings2::Cuint = 0
http2_settings3::Cuint = 0
http2_settings4::Cuint = 0
http2_settings5::Cuint = 0
http2_settings6::Cuint = 0
http2_settings7::Cuint = 0
http2_settings::NTuple{7,UInt32} = ntuple(i -> UInt32(0), 7)
max_http_header_data::Cushort = 0
max_http_header_pool::Cushort = 0
ssl_private_key_password::Ptr{Cchar} = C_NULL
Expand Down Expand Up @@ -236,7 +275,7 @@ Base.@kwdef mutable struct LwsContextCreationInfo
ssl_client_options_clear::Clong = 0
client_ssl_ca_mem_len::Cuint = 0
client_ssl_key_mem_len::Cuint = 0
provided_client_ssl_ctx::Ptr{Cint} = C_NULL
provided_client_ssl_ctx::Ptr{LwsSslCtxSt} = Ptr{LwsSslCtxSt}(C_NULL)
ka_time::Cint = 0
ka_probes::Cint = 0
ka_interval::Cint = 0
Expand Down Expand Up @@ -267,11 +306,11 @@ Base.@kwdef mutable struct LwsContextCreationInfo
username::Ptr{Cchar} = C_NULL
groupname::Ptr{Cchar} = C_NULL
unix_socket_perms::Ptr{Cchar} = C_NULL
system_ops::Ptr{Cint} = C_NULL
retry_and_idle_policy::Ptr{Cint} = C_NULL
register_notifier_list::Ptr{Ptr{Cint}} = C_NULL
system_ops::Ptr{LwsSystemOpts} = Ptr{LwsSystemOpts}(C_NULL)
retry_and_idle_policy::Ptr{LwsRetryBo} = Ptr{LwsRetryBo}(C_NULL)
register_notifier_list::Ptr{Ptr{LwsStateNotifyLink}} = Ptr{Ptr{LwsStateNotifyLink}}(C_NULL)
rlimit_nofile::Cint = 0
early_smd_cb::Cint = 0
early_smd_cb::Ptr{Cvoid} = C_NULL
early_smd_opaque::Ptr{Cvoid} = C_NULL
early_smd_class_filter::Cint = 0
smd_ttl_us::Cintmax_t = 0
Expand All @@ -283,8 +322,7 @@ Base.@kwdef mutable struct LwsContextCreationInfo
http_nsc_heap_max_footprint::Csize_t = 0
http_nsc_heap_max_items::Csize_t = 0
http_nsc_heap_max_payload::Csize_t = 0
_unused1::Ptr{Cvoid} = C_NULL
_unused2::Ptr{Cvoid} = C_NULL
_unused::NTuple{2,Ptr{Cvoid}} = (Ptr{Nothing}(C_NULL), Ptr{Nothing}(C_NULL))
end

Base.@kwdef mutable struct LwsClientConnectInfo
Expand All @@ -310,18 +348,15 @@ Base.@kwdef mutable struct LwsClientConnectInfo
alpn::Ptr{Cchar} = C_NULL
seq::Ptr{LwsSequencer} = C_NULL
opaque_user_data::Ptr{Cvoid} = C_NULL
retry_and_idle_policy::Ptr{Cint} = C_NULL
retry_and_idle_policy::Ptr{LwsRetryBo} = C_NULL
manual_initial_tx_credit::Cint = 0
sys_tls_client_cert::Cuchar = 0
priority::Cuchar = 0
mqtt_cp::Ptr{Cvoid} = C_NULL
fi_wsi_name::Ptr{Cchar} = C_NULL
keep_warm_secs::Cushort = 0
log_cx::Ptr{LwsLogCx} = C_NULL
_unused1::Ptr{Cvoid} = C_NULL
_unused2::Ptr{Cvoid} = C_NULL
_unused3::Ptr{Cvoid} = C_NULL
_unused4::Ptr{Cvoid} = C_NULL
_unused::NTuple{4,Ptr{Cvoid}} = (Ptr{Nothing}(C_NULL), Ptr{Nothing}(C_NULL), Ptr{Nothing}(C_NULL), Ptr{Nothing}(C_NULL))
end

Base.@kwdef mutable struct LwsProcessHtmlArgs
Expand Down

0 comments on commit 83a0f49

Please sign in to comment.