Skip to content

Commit 7c2486e

Browse files
committed
Wrap LibC.getaddrinfo in syscall(&) on UNIX and Windows 7
1 parent ed566aa commit 7c2486e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/crystal/system/unix/addrinfo.cr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ module Crystal::System::Addrinfo
4949
end
5050
{% end %}
5151

52-
ret = LibC.getaddrinfo(domain, service.to_s, pointerof(hints), out ptr)
52+
ptr = Pointer(LibC::Addrinfo).null
53+
ret =
54+
{% if flag?(:execution_context) %}
55+
::Fiber::ExecutionContext.syscall do
56+
LibC.getaddrinfo(domain, service.to_s, pointerof(hints), pointerof(ptr))
57+
end
58+
{% else %}
59+
LibC.getaddrinfo(domain, service.to_s, pointerof(hints), pointerof(ptr))
60+
{% end %}
5361
unless ret.zero?
5462
if ret == LibC::EAI_SYSTEM
5563
raise ::Socket::Addrinfo::Error.from_os_error nil, Errno.value, domain: domain

src/crystal/system/win32/addrinfo_win7.cr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ module Crystal::System::Addrinfo
4343
end
4444
end
4545

46-
ret = LibC.getaddrinfo(domain, service.to_s, pointerof(hints), out ptr)
46+
ptr = Pointer(LibC::Addrinfo).null
47+
ret =
48+
{% if flag?(:execution_context) %}
49+
::Fiber::ExecutionContext.syscall do
50+
LibC.getaddrinfo(domain, service.to_s, pointerof(hints), pointerof(ptr))
51+
end
52+
{% else %}
53+
LibC.getaddrinfo(domain, service.to_s, pointerof(hints), pointerof(ptr))
54+
{% end %}
4755
unless ret.zero?
4856
error = WinError.new(ret.to_u32!)
4957
raise ::Socket::Addrinfo::Error.from_os_error(nil, error, domain: domain, type: type, protocol: protocol, service: service)

0 commit comments

Comments
 (0)