Repository navigation
Expand file tree
/
Copy pathresolver.wave
More file actions
51 lines (45 loc) · 1.68 KB
/
Copy pathresolver.wave
File metadata and controls
51 lines (45 loc) · 1.68 KB
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
// Winsock ADDRINFOA uses a pointer-sized address length.
import("std::sys::windows::socket")::{socket_runtime_init};
pub struct NativeAddrInfo {
flags: i32;
family: i32;
socket_type: i32;
protocol: i32;
address_length: u64;
canonical_name: ptr<i8>;
address: ptr<i8>;
next: ptr<NativeAddrInfo>;
}
extern(system, "getaddrinfo") fun native_getaddrinfo(
host: ptr<i8>, service: ptr<i8>, hints: ptr<NativeAddrInfo>, result: ptr<ptr<NativeAddrInfo>>
) -> i32;
extern(system, "freeaddrinfo") fun native_freeaddrinfo(result: ptr<NativeAddrInfo>);
pub fun resolver_open(
host: str, service: str, socket_type: i32, protocol: i32,
result: ptr<ptr<NativeAddrInfo>>
) -> i64 {
if (result == null) { return -22; }
var ready: i64 = socket_runtime_init();
if (ready < 0) { return ready; }
var hints: NativeAddrInfo;
hints.flags = 0;
hints.family = 0;
hints.socket_type = socket_type;
hints.protocol = protocol;
hints.address_length = 0;
hints.canonical_name = null;
hints.address = null;
hints.next = null;
return native_getaddrinfo(host as ptr<i8>, service as ptr<i8>, &hints, result) as i64;
}
pub fun resolver_close(result: ptr<NativeAddrInfo>) {
if (result != null) { native_freeaddrinfo(result); }
}
pub fun resolver_family(result: ptr<NativeAddrInfo>) -> i32 { return (deref result).family; }
pub fun resolver_address(result: ptr<NativeAddrInfo>) -> ptr<i8> { return (deref result).address; }
pub fun resolver_address_length(result: ptr<NativeAddrInfo>) -> i64 {
return (deref result).address_length as i64;
}
pub fun resolver_next(result: ptr<NativeAddrInfo>) -> ptr<NativeAddrInfo> {
return (deref result).next;
}