Skip to content

Commit d85a2ac

Browse files
committed
Fix: remove internal calls to deprecated IO::FileDescriptor#new (blocking arg)
1 parent 0b077a0 commit d85a2ac

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

src/crystal/event_loop/iocp.cr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,11 @@ class Crystal::EventLoop::IOCP < Crystal::EventLoop
237237

238238
def pipe(read_blocking : Bool?, write_blocking : Bool?) : {IO::FileDescriptor, IO::FileDescriptor}
239239
r, w = System::FileDescriptor.system_pipe(!!read_blocking, !!write_blocking)
240+
create_completion_port(r) unless read_blocking
241+
create_completion_port(w) unless write_blocking
240242
{
241-
IO::FileDescriptor.new(r, !!read_blocking),
242-
IO::FileDescriptor.new(w, !!write_blocking),
243+
IO::FileDescriptor.new(handle: r, blocking: !!read_blocking)
244+
IO::FileDescriptor.new(handle: w, blocking: !!write_blocking)
243245
}
244246
end
245247

src/crystal/event_loop/libevent.cr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ class Crystal::EventLoop::LibEvent < Crystal::EventLoop
118118

119119
def pipe(read_blocking : Bool?, write_blocking : Bool?) : {IO::FileDescriptor, IO::FileDescriptor}
120120
r, w = System::FileDescriptor.system_pipe
121-
{
122-
IO::FileDescriptor.new(r, !!read_blocking),
123-
IO::FileDescriptor.new(w, !!write_blocking),
124-
}
121+
122+
reader = IO::FileDescriptor.new(handle: r)
123+
reader.blocking = !!read_blocking
124+
125+
writer = IO::FileDescriptor.new(handle: w)
126+
writer.blocking = !!write_blocking
127+
128+
{reader, writer}
125129
end
126130

127131
def open(path : String, flags : Int32, permissions : File::Permissions, blocking : Bool?) : {System::FileDescriptor::Handle, Bool} | Errno

src/crystal/event_loop/polling.cr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,14 @@ abstract class Crystal::EventLoop::Polling < Crystal::EventLoop
164164

165165
def pipe(read_blocking : Bool?, write_blocking : Bool?) : {IO::FileDescriptor, IO::FileDescriptor}
166166
r, w = System::FileDescriptor.system_pipe
167-
{
168-
IO::FileDescriptor.new(r, !!read_blocking),
169-
IO::FileDescriptor.new(w, !!write_blocking),
170-
}
167+
168+
reader = IO::FileDescriptor.new(handle: r)
169+
reader.blocking = !!read_blocking
170+
171+
writer = IO::FileDescriptor.new(handle: w)
172+
writer.blocking = !!write_blocking
173+
174+
{reader, writer}
171175
end
172176

173177
def open(path : String, flags : Int32, permissions : File::Permissions, blocking : Bool?) : {System::FileDescriptor::Handle, Bool} | Errno

src/crystal/system/process.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ struct Crystal::System::Process
8484
end
8585

8686
module Crystal::System
87-
ORIGINAL_STDIN = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDIN_HANDLE, blocking: true)
88-
ORIGINAL_STDOUT = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDOUT_HANDLE, blocking: true)
89-
ORIGINAL_STDERR = IO::FileDescriptor.new(Crystal::System::FileDescriptor::STDERR_HANDLE, blocking: true)
87+
ORIGINAL_STDIN = IO::FileDescriptor.new(handle: Crystal::System::FileDescriptor::STDIN_HANDLE, blocking: true)
88+
ORIGINAL_STDOUT = IO::FileDescriptor.new(handle: Crystal::System::FileDescriptor::STDOUT_HANDLE, blocking: true)
89+
ORIGINAL_STDERR = IO::FileDescriptor.new(handle: Crystal::System::FileDescriptor::STDERR_HANDLE, blocking: true)
9090
end
9191

9292
{% if flag?(:wasi) %}

src/io/file_descriptor.cr

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,30 @@ class IO::FileDescriptor < IO
5252
# event loop runtime requirements.
5353
#
5454
# NOTE: On Windows the handle should have been created with `FILE_FLAG_OVERLAPPED`.
55-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use `#blocking=`
56-
# to change the blocking mode instead.
57-
def self.new(fd : Handle, blocking = nil, *, close_on_finalize = true)
55+
def self.new(fd : Handle, *, close_on_finalize = true)
56+
file_descriptor = new(handle: fd, close_on_finalize: close_on_finalize)
57+
file_descriptor.system_blocking_init(nil) unless file_descriptor.closed?
58+
file_descriptor
59+
end
60+
61+
@[Deprecated("The blocking argument is deprecated. Use #blocking= to change it after creating the file descriptor.")]
62+
def self.new(fd : Handle, blocking, *, close_on_finalize = true)
5863
file_descriptor = new(handle: fd, close_on_finalize: close_on_finalize)
5964
file_descriptor.system_blocking_init(blocking) unless file_descriptor.closed?
6065
file_descriptor
6166
end
6267

6368
# :nodoc:
64-
def initialize(*, handle : Handle, @close_on_finalize = true)
69+
#
70+
# Internal constructor to wrap a system *handle*. The *blocking* arg is purely
71+
# informational.
72+
def initialize(*, handle : Handle, @close_on_finalize = true, blocking = nil)
6573
@volatile_fd = Atomic.new(handle)
6674
@closed = true # This is necessary so we can reference `self` in `system_closed?` (in case of an exception)
6775
@closed = system_closed?
76+
{% if flag?(:win32) %}
77+
@system_blocking = !!blocking
78+
{% end %}
6879
end
6980

7081
# :nodoc:

0 commit comments

Comments
 (0)