1// Copyright 2025 International Digital Economy Academy
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15///|
16type GetAddrInfo
17
18///|
19extern "c" fn uv_getaddrinfo_make() -> 
type GetAddrInfo
GetAddrInfo
= "moonbit_uv_getaddrinfo_make"
20 21///| 22pub impl
trait ToReq {
  to_req(Self) -> Req
}
ToReq
for
type GetAddrInfo
GetAddrInfo
with to_req(self :
type GetAddrInfo
GetAddrInfo
) ->
type Req
Req
= "%identity"
23 24///| 25type AddrInfoHints 26 27///| 28extern "c" fn uv_addrinfo_hints( 29 flags :
Int
Int
,
30 family :
Int
Int
,
31 socktype :
Int
Int
,
32 protocol :
Int
Int
33) ->
type AddrInfoHints
AddrInfoHints
= "moonbit_uv_addrinfo_hints"
34 35///| 36type AddrInfoFlags
Int
Int
37 38///| 39extern "c" fn uv_AI_PASSIVE() ->
Int
Int
= "moonbit_uv_AI_PASSIVE"
40 41///| 42let
Int
_AI_PASSIVE
:
Int
Int
=
() -> Int
uv_AI_PASSIVE
()
43 44///| 45extern "c" fn uv_AI_CANONNAME() ->
Int
Int
= "moonbit_uv_AI_CANONNAME"
46 47///| 48let
Int
_AI_CANONNAME
:
Int
Int
=
() -> Int
uv_AI_CANONNAME
()
49 50///| 51extern "c" fn uv_AI_NUMERICHOST() ->
Int
Int
= "moonbit_uv_AI_NUMERICHOST"
52 53///| 54let
Int
_AI_NUMERICHOST
:
Int
Int
=
() -> Int
uv_AI_NUMERICHOST
()
55 56///| 57extern "c" fn uv_AI_NUMERICSERV() ->
Int
Int
= "moonbit_uv_AI_NUMERICSERV"
58 59///| 60let
Int
_AI_NUMERICSERV
:
Int
Int
=
() -> Int
uv_AI_NUMERICSERV
()
61 62///| 63extern "c" fn uv_AI_ALL() ->
Int
Int
= "moonbit_uv_AI_ALL"
64 65///| 66let
Int
_AI_ALL
:
Int
Int
=
() -> Int
uv_AI_ALL
()
67 68///| 69extern "c" fn uv_AI_ADDRCONFIG() ->
Int
Int
= "moonbit_uv_AI_ADDRCONFIG"
70 71///| 72let
Int
_AI_ADDRCONFIG
:
Int
Int
=
() -> Int
uv_AI_ADDRCONFIG
()
73 74///| 75extern "c" fn uv_AI_V4MAPPED() ->
Int
Int
= "moonbit_uv_AI_V4MAPPED"
76 77///| 78let
Int
_AI_V4MAPPED
:
Int
Int
=
() -> Int
uv_AI_V4MAPPED
()
79 80///| 81pub fn
type AddrInfoFlags Int
AddrInfoFlags
::
(passive~ : Bool = .., canonname~ : Bool = .., numeric_host~ : Bool = .., numeric_serv~ : Bool = .., all~ : Bool = .., addrconfig~ : Bool = .., v4mapped~ : Bool = ..) -> AddrInfoFlags
new
(
82
Bool
passive
~ :
Bool
Bool
= false,
83
Bool
canonname
~ :
Bool
Bool
= false,
84
Bool
numeric_host
~ :
Bool
Bool
= false,
85
Bool
numeric_serv
~ :
Bool
Bool
= false,
86
Bool
all
~ :
Bool
Bool
= false,
87
Bool
addrconfig
~ :
Bool
Bool
= false,
88
Bool
v4mapped
~ :
Bool
Bool
= false
89) ->
type AddrInfoFlags Int
AddrInfoFlags
{
90 let mut
Int
flags
= 0
91 if
Bool
passive
{
92
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_PASSIVE
93 } 94 if
Bool
canonname
{
95
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_CANONNAME
96 } 97 if
Bool
numeric_host
{
98
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_NUMERICHOST
99 } 100 if
Bool
numeric_serv
{
101
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_NUMERICSERV
102 } 103 if
Bool
all
{
104
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_ALL
105 } 106 if
Bool
addrconfig
{
107
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_ADDRCONFIG
108 } 109 if
Bool
v4mapped
{
110
Int
flags
=
Int
flags
(Int, Int) -> Int
|
Int
_AI_V4MAPPED
111 } 112 return
Int
flags
113} 114 115///| 116pub fn
type AddrInfoHints
AddrInfoHints
::
(flags? : AddrInfoFlags, family? : AddressFamily, socktype? : SockType, protocol? : Protocol) -> AddrInfoHints
new
(
117
AddrInfoFlags?
flags
? :
type AddrInfoFlags Int
AddrInfoFlags
,
118
AddressFamily?
family
? :
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
,
119
SockType?
socktype
? :
enum SockType {
  Stream
  Raw
  Datagram
}
SockType
,
120
Protocol?
protocol
? :
enum Protocol {
  Tcp
  Udp
}
Protocol
121) ->
type AddrInfoHints
AddrInfoHints
{
122 let
Int
flags
= match
AddrInfoFlags?
flags
{
123
(AddrInfoFlags) -> AddrInfoFlags?
Some
(
AddrInfoFlags
flags
) =>
AddrInfoFlags
flags
.
(self : AddrInfoFlags) -> Int

Convert newtype to its underlying type, automatically derived.

inner
()
124
AddrInfoFlags?
None
=> 0
125 } 126 let
Int
family
= match
AddressFamily?
family
{
127
(AddressFamily) -> AddressFamily?
Some
(
AddressFamily
family
) =>
AddressFamily
family
.
(self : AddressFamily) -> Int
to_int
()
128
AddressFamily?
None
=>
Int
_AF_UNSPEC
129 } 130 let
Int
socktype
= match
SockType?
socktype
{
131
(SockType) -> SockType?
Some
(
SockType
socktype
) =>
SockType
socktype
.
(self : SockType) -> Int
to_int
()
132
SockType?
None
=> 0
133 } 134 let
Int
protocol
= match
Protocol?
protocol
{
135
(Protocol) -> Protocol?
Some
(
Protocol
protocol
) =>
Protocol
protocol
.
(self : Protocol) -> Int
to_int
()
136
Protocol?
None
=> 0
137 } 138
(flags : Int, family : Int, socktype : Int, protocol : Int) -> AddrInfoHints
uv_addrinfo_hints
(
Int
flags
,
Int
family
,
Int
socktype
,
Int
protocol
)
139} 140 141///| 142extern "c" fn
type AddrInfoHints
AddrInfoHints
::nil() ->
type AddrInfoHints
AddrInfoHints
= "moonbit_c_null"
143 144///| 145priv type AddrInfoResults 146 147///| 148#borrow(addrinfo_results, cb) 149extern "c" fn uv_addrinfo_results_iterate( 150 addrinfo_results :
type AddrInfoResults
AddrInfoResults
,
151 cb : (
Int
Int
,
Int
Int
,
Int
Int
,
Int
Int
,
type Sockaddr Bytes
Sockaddr
, @c.Pointer[
Byte
Byte
]) ->
Bool
Bool
152) ->
Bool
Bool
= "moonbit_uv_addrinfo_results_iterate"
153 154///| 155extern "c" fn uv_IF_NAMESIZE() ->
Int
Int
= "moonbit_uv_IF_NAMESIZE"
156 157///| 158let
Int
_IF_NAMESIZE
:
Int
Int
=
() -> Int
uv_IF_NAMESIZE
()
159 160///| 161struct AddrInfo { 162
Int
family
:
Int
Int
163
Int
socktype
:
Int
Int
164
Int
protocol
:
Int
Int
165
Sockaddr
addr
:
type Sockaddr Bytes
Sockaddr
166
String?
canonname
:
String
String
?
167} 168 169///| 170extern "c" fn uv_AF_INET() ->
Int
Int
= "moonbit_uv_AF_INET"
171 172///| 173let
Int
_AF_INET
:
Int
Int
=
() -> Int
uv_AF_INET
()
174 175///| 176extern "c" fn uv_AF_INET6() ->
Int
Int
= "moonbit_uv_AF_INET6"
177 178///| 179let
Int
_AF_INET6
:
Int
Int
=
() -> Int
uv_AF_INET6
()
180 181///| 182extern "c" fn uv_AF_UNSPEC() ->
Int
Int
= "moonbit_uv_AF_UNSPEC"
183 184///| 185let
Int
_AF_UNSPEC
:
Int
Int
=
() -> Int
uv_AF_UNSPEC
()
186 187///| 188/// Represents the address family for network communication, specifying the 189/// format of network addresses. 190/// 191/// Constructors: 192/// 193/// * `Inet` : IPv4 address family 194/// * `Inet6` : IPv6 address family 195/// 196/// Example: 197/// 198/// ```moonbit 199/// let ipv4 = AddressFamily::inet() 200/// let ipv6 = AddressFamily::inet6() 201/// inspect(ipv4, content="Inet") 202/// inspect(ipv6, content="Inet6") 203/// ``` 204pub enum AddressFamily { 205
AddressFamily
Inet
206
AddressFamily
Inet6
207} derive(
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
)
208 209///| 210pub fn
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
::
() -> AddressFamily
inet
() ->
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
{
211 return
AddressFamily
Inet
212} 213 214///| 215pub fn
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
::
() -> AddressFamily
inet6
() ->
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
{
216 return
AddressFamily
Inet6
217} 218 219///| 220fn
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
::
(self : Int) -> AddressFamily raise Errno
of_int
(
Int
self
:
Int
Int
) ->
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
raise
type! Errno Status
Errno
{
221 if
Int
self
(self : Int, other : Int) -> Bool

Compares two integers for equality.

Parameters:

  • self : The first integer to compare.
  • other : The second integer to compare.

Returns true if both integers have the same value, false otherwise.

Example:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
Int
_AF_INET
{
222 return
AddressFamily
Inet
223 } 224 if
Int
self
(self : Int, other : Int) -> Bool

Compares two integers for equality.

Parameters:

  • self : The first integer to compare.
  • other : The second integer to compare.

Returns true if both integers have the same value, false otherwise.

Example:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
Int
_AF_INET6
{
225 return
AddressFamily
Inet6
226 } 227 raise
(Status) -> Errno
Errno
(
Status
EINVAL
)
228} 229 230///| 231fn
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
::
(self : AddressFamily) -> Int
to_int
(
AddressFamily
self
:
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
) ->
Int
Int
{
232 match
AddressFamily
self
{
233
AddressFamily
Inet
=>
Int
_AF_INET
234
AddressFamily
Inet6
=>
Int
_AF_INET6
235 } 236} 237 238///| 239pub fn
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
::
(self : AddrInfo) -> AddressFamily raise Errno
family
(
AddrInfo
self
:
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
) ->
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
raise
type! Errno Status
Errno
{
240
enum AddressFamily {
  Inet
  Inet6
}

Represents the address family for network communication, specifying the format of network addresses.

Constructors:

  • Inet : IPv4 address family
  • Inet6 : IPv6 address family

Example:

let ipv4 = AddressFamily::inet()
let ipv6 = AddressFamily::inet6()
inspect(ipv4, content="Inet")
inspect(ipv6, content="Inet6")
AddressFamily
::
(self : Int) -> AddressFamily raise Errno
of_int
(
AddrInfo
self
.
Int
family
)
241} 242 243///| 244pub fn
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
::
(self : AddrInfo) -> Sockaddr
addr
(
AddrInfo
self
:
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
) ->
type Sockaddr Bytes
Sockaddr
{
245
AddrInfo
self
.
Sockaddr
addr
246} 247 248///| 249pub fn
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
::
(self : AddrInfo) -> SockType raise Errno
socktype
(
AddrInfo
self
:
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
) ->
enum SockType {
  Stream
  Raw
  Datagram
}
SockType
raise
type! Errno Status
Errno
{
250 return
enum SockType {
  Stream
  Raw
  Datagram
}
SockType
::
(self : Int) -> SockType raise Errno
of_int
(
AddrInfo
self
.
Int
socktype
)
251} 252 253///| 254pub fn
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
::
(self : AddrInfo) -> Protocol raise Errno
protocol
(
AddrInfo
self
:
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
) ->
enum Protocol {
  Tcp
  Udp
}
Protocol
raise
type! Errno Status
Errno
{
255
enum Protocol {
  Tcp
  Udp
}
Protocol
::
(self : Int) -> Protocol raise Errno
of_int
(
AddrInfo
self
.
Int
protocol
)
256} 257 258///| 259pub fn
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
::
(self : AddrInfo) -> String?
canonname
(
AddrInfo
self
:
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
) ->
String
String
? {
260
AddrInfo
self
.
String?
canonname
261} 262 263///| 264fn
type AddrInfoResults
AddrInfoResults
::
(self : AddrInfoResults) -> Iter[AddrInfo]
iter
(
AddrInfoResults
self
:
type AddrInfoResults
AddrInfoResults
) ->
type Iter[T]
Iter
[
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
] {
265
type Iter[T]
Iter
::
(((AddrInfo) -> IterResult) -> IterResult) -> Iter[AddrInfo]

Do not use this method, it is for internal use only.

new
(fn(
(AddrInfo) -> IterResult
yield_
) {
266 if
(addrinfo_results : AddrInfoResults, cb : (Int, Int, Int, Int, Sockaddr, ?) -> Bool) -> Bool
uv_addrinfo_results_iterate
(
AddrInfoResults
self
, fn(
267 _, 268
Int
family
,
269
Int
socktype
,
270
Int
protocol
,
271
Sockaddr
addr
,
272
?
canonname
273 ) { 274 let
String?
canonname
= if
?
canonname
.
() -> Bool
is_null
() {
275
String?
None
276 } else { 277 let
@buffer.T
buffer
=
(size_hint~ : Int = ..) -> @buffer.T

Creates a new extensible buffer with specified initial capacity. If the initial capacity is less than 1, the buffer will be initialized with capacity 1.

Parameters:

  • size_hint : Initial capacity of the buffer in bytes. Defaults to 0.

Returns a new buffer of type T.

Example:

  let buf = @buffer.new(size_hint=10)
  inspect(buf.length(), content="0")
  buf.write_string("test")
  inspect(buf.length(), content="8")
@buffer.new
()
278 for
Int
i
= 0;
?
canonname
(Int) -> Int
[
i]
(x : Int, y : Int) -> Bool
!=
0;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
1 {
279
@buffer.T
buffer
.
(self : @buffer.T, value : Byte) -> Unit

Writes a single byte to the end of the buffer. The buffer will automatically grow if necessary to accommodate the new byte.

Parameters:

  • buffer : The buffer to write to.
  • byte : The byte value to be written.

Example:

  let buf = @buffer.new()
  buf.write_byte(b'\x41')
  inspect(buf.contents(), content="b\"\\x41\"")
write_byte
(
?
canonname
(Int) -> Byte
[
i])
280 } 281
(String) -> String?
Some
(
(encoding~ : @encoding.Encoding, input : @bytes.View) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
,
@buffer.T
buffer
.
(self : @buffer.T) -> Bytes

Returns a copy of the buffer's content as a sequence of bytes.

Parameters:

  • buffer : The buffer to read from.

Returns a Bytes object containing all bytes written to the buffer.

Example:

  let buf = @buffer.new()
  buf.write_string("Test")
  inspect(
    buf.contents(),
    content=
      #|b"\x54\x00\x65\x00\x73\x00\x74\x00"
    ,
  )
contents
()))
282 } 283 match
(AddrInfo) -> IterResult
yield_
({
Int
family
,
Int
socktype
,
Int
protocol
,
Sockaddr
addr
,
String?
canonname
}) {
284
IterResult
IterEnd
=> true
285
IterResult
IterContinue
=> false
286 } 287 }) { 288 return
IterResult
IterEnd
289 } else { 290 return
IterResult
IterContinue
291 } 292 }) 293} 294 295///| 296extern "c" fn uv_getaddrinfo( 297 uv :
type Loop Bytes
Loop
,
298 req :
type GetAddrInfo
GetAddrInfo
,
299 getaddrinfo_cb : (
type GetAddrInfo
GetAddrInfo
,
Int
Int
,
type AddrInfoResults
AddrInfoResults
) ->
Unit
Unit
,
300 node :
Bytes
Bytes
,
301 service :
Bytes
Bytes
,
302 hints :
type AddrInfoHints
AddrInfoHints
303) ->
Int
Int
= "moonbit_uv_getaddrinfo"
304 305///| 306pub fn[Node :
trait ToNtbs {
  to_ntbs(Self) -> Bytes
}

Convertible to null-terminated byte strings (NTBS).

ToNtbs
, Service :
trait ToNtbs {
  to_ntbs(Self) -> Bytes
}

Convertible to null-terminated byte strings (NTBS).

ToNtbs
]
type Loop Bytes
Loop
::
(self : Loop, getaddrinfo_cb : (Iter[AddrInfo]) -> Unit, error_cb : (Errno) -> Unit, node : Node, service : Service, hints? : AddrInfoHints) -> GetAddrInfo raise Errno
getaddrinfo
(
307
Loop
self
:
type Loop Bytes
Loop
,
308
(Iter[AddrInfo]) -> Unit
getaddrinfo_cb
: (
type Iter[T]
Iter
[
struct AddrInfo {
  family: Int
  socktype: Int
  protocol: Int
  addr: Sockaddr
  canonname: String?
}
AddrInfo
]) ->
Unit
Unit
,
309
(Errno) -> Unit
error_cb
: (
type! Errno Status
Errno
) ->
Unit
Unit
,
310
Node
node
:

type parameter Node

Node
,
311
Service
service
:

type parameter Service

Service
,
312
AddrInfoHints?
hints
? :
type AddrInfoHints
AddrInfoHints
313) ->
type GetAddrInfo
GetAddrInfo
raise
type! Errno Status
Errno
{
314 fn
(GetAddrInfo, Int, AddrInfoResults) -> Unit
uv_cb
(_ :
type GetAddrInfo
GetAddrInfo
,
Int
status
:
Int
Int
,
AddrInfoResults
addrinfo
:
type AddrInfoResults
AddrInfoResults
) {
315 if
Int
status
(self_ : Int, other : Int) -> Bool
<
0 {
316
(Errno) -> Unit
error_cb
(
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
status
))
317 } else { 318
(Iter[AddrInfo]) -> Unit
getaddrinfo_cb
(
AddrInfoResults
addrinfo
.
(self : AddrInfoResults) -> Iter[AddrInfo]
iter
())
319 } 320 } 321 322 let
GetAddrInfo
req
=
() -> GetAddrInfo
uv_getaddrinfo_make
()
323 let
Int
status
=
(uv : Loop, req : GetAddrInfo, getaddrinfo_cb : (GetAddrInfo, Int, AddrInfoResults) -> Unit, node : Bytes, service : Bytes, hints : AddrInfoHints) -> Int
uv_getaddrinfo
(
324
Loop
self
,
325
GetAddrInfo
req
,
326
(GetAddrInfo, Int, AddrInfoResults) -> Unit
uv_cb
,
327
Node
node
.
(Node) -> Bytes
to_ntbs
(),
328
Service
service
.
(Service) -> Bytes
to_ntbs
(),
329
AddrInfoHints?
hints
.
(self : AddrInfoHints?, default : () -> AddrInfoHints) -> AddrInfoHints

Return the contained Some value or the provided default.

Default is lazily evaluated

or_else
(
type AddrInfoHints
AddrInfoHints
() -> AddrInfoHints
::nil
),
330 ) 331 if
Int
status
(self_ : Int, other : Int) -> Bool
<
0 {
332 raise
type! Errno Status
Errno
::
(errno : Int) -> Errno
of_int
(
Int
status
)
333 } 334 return
GetAddrInfo
req
335} 336