-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibuv_extensions.jl
134 lines (106 loc) · 3.59 KB
/
libuv_extensions.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module LibUVExtensions
##
#
# These functions are generated from Julia's LibUV
# (https://github.com/libuv/libuv) using Clang.jl -- taking only those functions
# needed by this module
#
# Note: _Some_ of Julia's LibUV prefixes uv_* symbols with jl_*. Eg.:
# uv_interface_addresses becomes: jl_uv_interface_addresses
# (but not all!)
#
##
const sa_family_t = Cushort
const in_port_t = UInt16
const in_addr_t = UInt32
struct in_addr
s_addr::in_addr_t
end
struct sockaddr_in
sin_family::sa_family_t
sin_port::in_port_t
sin_addr::in_addr
sin_zero::NTuple{8, Cuchar}
end
struct sockaddr_in6
data::NTuple{28, UInt8}
end
function Base.getproperty(x::Ptr{sockaddr_in6}, f::Symbol)
f === :sin6_family && return Ptr{sa_family_t}(x + 0)
f === :sin6_port && return Ptr{in_port_t}(x + 2)
f === :sin6_flowinfo && return Ptr{UInt32}(x + 4)
f === :sin6_addr && return Ptr{in6_addr}(x + 8)
f === :sin6_scope_id && return Ptr{UInt32}(x + 24)
return getfield(x, f)
end
function Base.getproperty(x::sockaddr_in6, f::Symbol)
r = Ref{sockaddr_in6}(x)
ptr = Base.unsafe_convert(Ptr{sockaddr_in6}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{sockaddr_in6}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
struct var"##Ctag#362"
data::NTuple{28, UInt8}
end
function Base.getproperty(x::Ptr{var"##Ctag#362"}, f::Symbol)
f === :address4 && return Ptr{sockaddr_in}(x + 0)
f === :address6 && return Ptr{sockaddr_in6}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::var"##Ctag#362", f::Symbol)
r = Ref{var"##Ctag#362"}(x)
ptr = Base.unsafe_convert(Ptr{var"##Ctag#362"}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{var"##Ctag#362"}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
struct var"##Ctag#363"
data::NTuple{28, UInt8}
end
function Base.getproperty(x::Ptr{var"##Ctag#363"}, f::Symbol)
f === :netmask4 && return Ptr{sockaddr_in}(x + 0)
f === :netmask6 && return Ptr{sockaddr_in6}(x + 0)
return getfield(x, f)
end
function Base.getproperty(x::var"##Ctag#363", f::Symbol)
r = Ref{var"##Ctag#363"}(x)
ptr = Base.unsafe_convert(Ptr{var"##Ctag#363"}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{var"##Ctag#363"}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
struct uv_interface_address_s
data::NTuple{80, UInt8}
end
function Base.getproperty(x::Ptr{uv_interface_address_s}, f::Symbol)
f === :name && return Ptr{Ptr{Cchar}}(x + 0)
f === :phys_addr && return Ptr{NTuple{6, Cchar}}(x + 8)
f === :is_internal && return Ptr{Cint}(x + 16)
f === :address && return Ptr{var"##Ctag#362"}(x + 20)
f === :netmask && return Ptr{var"##Ctag#363"}(x + 48)
return getfield(x, f)
end
function Base.getproperty(x::uv_interface_address_s, f::Symbol)
r = Ref{uv_interface_address_s}(x)
ptr = Base.unsafe_convert(Ptr{uv_interface_address_s}, r)
fptr = getproperty(ptr, f)
GC.@preserve r unsafe_load(fptr)
end
function Base.setproperty!(x::Ptr{uv_interface_address_s}, f::Symbol, v)
unsafe_store!(getproperty(x, f), v)
end
const uv_interface_address_t = uv_interface_address_s
function uv_interface_addresses(addresses, count)
ccall(:jl_uv_interface_addresses, Cint, (Ptr{Ptr{uv_interface_address_t}}, Ptr{Cint}), addresses, count)
end
function uv_free_interface_addresses(addresses, count)
ccall(:uv_free_interface_addresses, Cvoid, (Ptr{uv_interface_address_t}, Cint), addresses, count)
end
end