From 567afe6fdc4d3052369ca42d318bd88a0af70fc5 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sat, 3 Apr 2021 03:22:52 +0200 Subject: [PATCH] Add return type restrictions to I/O methods --- src/compress/deflate/reader.cr | 6 +++--- src/compress/deflate/writer.cr | 4 ++-- src/compress/gzip/reader.cr | 4 ++-- src/compress/gzip/writer.cr | 2 +- src/compress/zip/checksum_reader.cr | 4 ++-- src/compress/zip/checksum_writer.cr | 2 +- src/compress/zlib/reader.cr | 6 +++--- src/compress/zlib/writer.cr | 2 +- src/digest/io_digest.cr | 2 +- src/file/preader.cr | 4 ++-- src/http/content.cr | 28 ++++++++++++++-------------- src/http/server/response.cr | 4 ++-- src/http/web_socket/protocol.cr | 2 +- src/io.cr | 18 +++++++++--------- src/io/argf.cr | 6 +++--- src/io/buffered.cr | 10 +++++----- src/io/byte_format.cr | 8 ++++---- src/io/delimited.cr | 2 +- src/io/encoding.cr | 14 +++++++------- src/io/file_descriptor.cr | 12 ++++++------ src/io/hexdump.cr | 2 +- src/io/memory.cr | 22 +++++++++++----------- src/io/multi_writer.cr | 6 +++--- src/io/sized.cr | 6 +++--- src/io/stapled.cr | 2 +- src/openssl/ssl/socket.cr | 6 +++--- src/socket.cr | 2 +- src/string/builder.cr | 4 ++-- 28 files changed, 95 insertions(+), 95 deletions(-) diff --git a/src/compress/deflate/reader.cr b/src/compress/deflate/reader.cr index d174e4536a9b..9a185d809a9c 100644 --- a/src/compress/deflate/reader.cr +++ b/src/compress/deflate/reader.cr @@ -52,12 +52,12 @@ class Compress::Deflate::Reader < IO end # Always raises `IO::Error` because this is a read-only `IO`. - def unbuffered_write(slice : Bytes) + def unbuffered_write(slice : Bytes) : NoReturn raise IO::Error.new "Can't write to Compress::Deflate::Reader" end # See `IO#read`. - def unbuffered_read(slice : Bytes) + def unbuffered_read(slice : Bytes) : Int32 check_open return 0 if slice.empty? @@ -125,7 +125,7 @@ class Compress::Deflate::Reader < IO end end - def unbuffered_flush + def unbuffered_flush : NoReturn raise IO::Error.new "Can't flush Compress::Deflate::Reader" end diff --git a/src/compress/deflate/writer.cr b/src/compress/deflate/writer.cr index c09b6da2da76..e844604f9b6a 100644 --- a/src/compress/deflate/writer.cr +++ b/src/compress/deflate/writer.cr @@ -38,7 +38,7 @@ class Compress::Deflate::Writer < IO end # Always raises `IO::Error` because this is a write-only `IO`. - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise "Can't read from Flate::Writer" end @@ -77,7 +77,7 @@ class Compress::Deflate::Writer < IO end # Returns `true` if this IO is closed. - def closed? + def closed? : Bool @closed end diff --git a/src/compress/gzip/reader.cr b/src/compress/gzip/reader.cr index 73412a1b3bd5..63b5530dcad7 100644 --- a/src/compress/gzip/reader.cr +++ b/src/compress/gzip/reader.cr @@ -78,7 +78,7 @@ class Compress::Gzip::Reader < IO end # See `IO#read`. - def unbuffered_read(slice : Bytes) + def unbuffered_read(slice : Bytes) : Int32 check_open return 0 if slice.empty? @@ -133,7 +133,7 @@ class Compress::Gzip::Reader < IO raise IO::Error.new("Can't write to Compress::Gzip::Reader") end - def unbuffered_flush + def unbuffered_flush : NoReturn raise IO::Error.new "Can't flush Compress::Gzip::Reader" end diff --git a/src/compress/gzip/writer.cr b/src/compress/gzip/writer.cr index cce946ea48fb..9cdbe02a370c 100644 --- a/src/compress/gzip/writer.cr +++ b/src/compress/gzip/writer.cr @@ -63,7 +63,7 @@ class Compress::Gzip::Writer < IO end # Always raises `IO::Error` because this is a write-only `IO`. - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise IO::Error.new("Can't read from Gzip::Writer") end diff --git a/src/compress/zip/checksum_reader.cr b/src/compress/zip/checksum_reader.cr index b2a981bcd552..879a63d50fe0 100644 --- a/src/compress/zip/checksum_reader.cr +++ b/src/compress/zip/checksum_reader.cr @@ -8,7 +8,7 @@ module Compress::Zip def initialize(@io : IO, @filename : String, verify @expected_crc32 : UInt32? = nil) end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 read_bytes = @io.read(slice) if read_bytes == 0 if (expected_crc32 = @expected_crc32) && crc32 != expected_crc32 @@ -20,7 +20,7 @@ module Compress::Zip read_bytes end - def peek + def peek : Bytes? @io.peek end diff --git a/src/compress/zip/checksum_writer.cr b/src/compress/zip/checksum_writer.cr index 2f2b6732cb18..da5a33351c97 100644 --- a/src/compress/zip/checksum_writer.cr +++ b/src/compress/zip/checksum_writer.cr @@ -9,7 +9,7 @@ module Compress::Zip def initialize(@compute_crc32 = false) end - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise IO::Error.new "Can't read from Zip::Writer entry" end diff --git a/src/compress/zlib/reader.cr b/src/compress/zlib/reader.cr index 86726e1b6900..df6eecb84ffe 100644 --- a/src/compress/zlib/reader.cr +++ b/src/compress/zlib/reader.cr @@ -58,7 +58,7 @@ class Compress::Zlib::Reader < IO end # See `IO#read`. - def unbuffered_read(slice : Bytes) + def unbuffered_read(slice : Bytes) : Int32 check_open return 0 if slice.empty? @@ -81,11 +81,11 @@ class Compress::Zlib::Reader < IO end # Always raises `IO::Error` because this is a read-only `IO`. - def unbuffered_write(slice : Bytes) + def unbuffered_write(slice : Bytes) : NoReturn raise IO::Error.new "Can't write to Compress::Zlib::Reader" end - def unbuffered_flush + def unbuffered_flush : NoReturn raise IO::Error.new "Can't flush Compress::Zlib::Reader" end diff --git a/src/compress/zlib/writer.cr b/src/compress/zlib/writer.cr index c609ce6cb34c..03e27cf07ab5 100644 --- a/src/compress/zlib/writer.cr +++ b/src/compress/zlib/writer.cr @@ -39,7 +39,7 @@ class Compress::Zlib::Writer < IO end # Always raises `IO::Error` because this is a write-only `IO`. - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise IO::Error.new("Can't read from Gzip::Writer") end diff --git a/src/digest/io_digest.cr b/src/digest/io_digest.cr index 06167a349870..6789513cc847 100644 --- a/src/digest/io_digest.cr +++ b/src/digest/io_digest.cr @@ -30,7 +30,7 @@ class IO::Digest < IO def initialize(@io : IO, @digest_algorithm : ::Digest, @mode = DigestMode::Read) end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 read_bytes = io.read(slice) if @mode.read? digest_algorithm.update(slice[0, read_bytes]) diff --git a/src/file/preader.cr b/src/file/preader.cr index e8b91a8d6b55..e036929f4fee 100644 --- a/src/file/preader.cr +++ b/src/file/preader.cr @@ -26,11 +26,11 @@ class File::PReader < IO bytes_read end - def unbuffered_write(slice : Bytes) + def unbuffered_write(slice : Bytes) : NoReturn raise IO::Error.new("Can't write to read-only IO") end - def unbuffered_flush + def unbuffered_flush : NoReturn raise IO::Error.new("Can't flush read-only IO") end diff --git a/src/http/content.cr b/src/http/content.cr index e7dd653845c2..ec7fe2bb252c 100644 --- a/src/http/content.cr +++ b/src/http/content.cr @@ -26,27 +26,27 @@ module HTTP class FixedLengthContent < IO::Sized include Content - def read(slice : Bytes) + def read(slice : Bytes) : Int32 ensure_send_continue super end - def read_byte + def read_byte : UInt8? ensure_send_continue super end - def peek + def peek : Bytes? ensure_send_continue super end - def skip(bytes_count) + def skip(bytes_count) : Nil ensure_send_continue super end - def write(slice : Bytes) + def write(slice : Bytes) : NoReturn raise IO::Error.new "Can't write to FixedLengthContent" end end @@ -58,22 +58,22 @@ module HTTP def initialize(@io : IO) end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 ensure_send_continue @io.read(slice) end - def read_byte + def read_byte : UInt8? ensure_send_continue @io.read_byte end - def peek + def peek : Bytes? ensure_send_continue @io.peek end - def skip(bytes_count) + def skip(bytes_count) : Int32? ensure_send_continue @io.skip(bytes_count) end @@ -112,7 +112,7 @@ module HTTP @received_final_chunk = false end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 ensure_send_continue count = slice.size return 0 if count == 0 @@ -134,7 +134,7 @@ module HTTP bytes_read end - def read_byte + def read_byte : UInt8? ensure_send_continue next_chunk return super if @received_final_chunk @@ -148,7 +148,7 @@ module HTTP end end - def peek + def peek : Bytes? ensure_send_continue next_chunk return Bytes.empty if @received_final_chunk @@ -164,7 +164,7 @@ module HTTP peek end - def skip(bytes_count) + def skip(bytes_count) : Int32? ensure_send_continue if bytes_count <= @chunk_remaining @io.skip(bytes_count) @@ -233,7 +233,7 @@ module HTTP raise IO::Error.new "Can't write to ChunkedContent" end - def closed? + def closed? : Bool @received_final_chunk || super end end diff --git a/src/http/server/response.cr b/src/http/server/response.cr index 6d0eef046126..89634fe60430 100644 --- a/src/http/server/response.cr +++ b/src/http/server/response.cr @@ -92,7 +92,7 @@ class HTTP::Server end # :nodoc: - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise "Can't read from HTTP::Server::Response" end @@ -117,7 +117,7 @@ class HTTP::Server end # Returns `true` if this response has been closed. - def closed? + def closed? : Bool @output.closed? end diff --git a/src/http/web_socket/protocol.cr b/src/http/web_socket/protocol.cr index 6075c67453cf..d4d88d7e4b6d 100644 --- a/src/http/web_socket/protocol.cr +++ b/src/http/web_socket/protocol.cr @@ -70,7 +70,7 @@ class HTTP::WebSocket::Protocol end end - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise "This IO is write-only" end diff --git a/src/io.cr b/src/io.cr index 37abcdea3722..00f391c06bf6 100644 --- a/src/io.cr +++ b/src/io.cr @@ -110,7 +110,7 @@ abstract class IO # Returns `true` if this `IO` is closed. # # `IO` defines returns `false`, but including types may override. - def closed? + def closed? : Bool false end @@ -388,7 +388,7 @@ abstract class IO # # "你".bytes # => [228, 189, 160] # ``` - def read_utf8_byte + def read_utf8_byte : UInt8? if decoder = decoder() decoder.read_byte(self) else @@ -463,7 +463,7 @@ abstract class IO end # Writes a slice of UTF-8 encoded bytes to this `IO`, using the current encoding. - def write_utf8(slice : Bytes) + def write_utf8(slice : Bytes) : Nil if encoder = encoder() encoder.write(self, slice) else @@ -499,7 +499,7 @@ abstract class IO # slice # => Bytes[49, 50, 51, 52, 53] # io.read_fully(slice) # raises IO::EOFError # ``` - def read_fully(slice : Bytes) + def read_fully(slice : Bytes) : Int32 read_fully?(slice) || raise(EOFError.new) end @@ -514,7 +514,7 @@ abstract class IO # slice # => Bytes[49, 50, 51, 52, 53] # io.read_fully?(slice) # => nil # ``` - def read_fully?(slice : Bytes) + def read_fully?(slice : Bytes) : Int32? count = slice.size while slice.size > 0 read_bytes = read slice @@ -838,7 +838,7 @@ abstract class IO # io.write_byte 97_u8 # io.to_s # => "a" # ``` - def write_byte(byte : UInt8) + def write_byte(byte : UInt8) : Nil x = byte write Slice.new(pointerof(x), 1) end @@ -857,7 +857,7 @@ abstract class IO # io.rewind # io.gets(4) # => "\u{4}\u{3}\u{2}\u{1}" # ``` - def write_bytes(object, format : IO::ByteFormat = IO::ByteFormat::SystemEndian) + def write_bytes(object, format : IO::ByteFormat = IO::ByteFormat::SystemEndian) : Nil object.to_io(self, format) end @@ -1030,7 +1030,7 @@ abstract class IO end # :nodoc: - def has_non_utf8_encoding? + def has_non_utf8_encoding? : Bool !!@encoding end @@ -1156,7 +1156,7 @@ abstract class IO # stream2 = IO::Memory.new("123") # IO.same_content?(stream1, stream2) # => true # ``` - def self.same_content?(stream1 : IO, stream2 : IO) + def self.same_content?(stream1 : IO, stream2 : IO) : Bool buf1 = uninitialized UInt8[1024] buf2 = uninitialized UInt8[1024] diff --git a/src/io/argf.cr b/src/io/argf.cr index 47b2a7503e06..a0af097ed594 100644 --- a/src/io/argf.cr +++ b/src/io/argf.cr @@ -10,7 +10,7 @@ class IO::ARGF < IO @read_from_stdin = false end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 first_initialize unless @initialized if current_io = @current_io @@ -29,7 +29,7 @@ class IO::ARGF < IO end # :nodoc: - def peek + def peek : Bytes? first_initialize unless @initialized if current_io = @current_io @@ -57,7 +57,7 @@ class IO::ARGF < IO raise IO::Error.new "Can't write to ARGF" end - def path + def path : String @path || @argv.first? || "-" end diff --git a/src/io/buffered.cr b/src/io/buffered.cr index be8275db3f9a..36ef8ddffae3 100644 --- a/src/io/buffered.cr +++ b/src/io/buffered.cr @@ -31,7 +31,7 @@ module IO::Buffered abstract def unbuffered_rewind # Return the buffer size used - def buffer_size + def buffer_size : Int32 @buffer_size end @@ -66,7 +66,7 @@ module IO::Buffered end # Buffered implementation of `IO#read(slice)`. - def read(slice : Bytes) + def read(slice : Bytes) : Int32 check_open count = slice.size @@ -188,7 +188,7 @@ module IO::Buffered end # Determines if this `IO` does write buffering. If `true`, no buffering is done. - def sync? + def sync? : Bool @sync end @@ -198,7 +198,7 @@ module IO::Buffered end # Determines whether this `IO` buffers reads. - def read_buffering? + def read_buffering? : Bool @read_buffering end @@ -208,7 +208,7 @@ module IO::Buffered end # Determines if this `IO` flushes automatically when a newline is written. - def flush_on_newline? + def flush_on_newline? : Bool @flush_on_newline end diff --git a/src/io/byte_format.cr b/src/io/byte_format.cr index 6f6b6a1082cd..89c92420b270 100644 --- a/src/io/byte_format.cr +++ b/src/io/byte_format.cr @@ -85,11 +85,11 @@ module IO::ByteFormat encode(float.unsafe_as(Int32), bytes) end - def decode(type : Float32.class, io : IO) + def decode(type : Float32.class, io : IO) : Float32 decode(Int32, io).unsafe_as(Float32) end - def decode(type : Float32.class, bytes : Bytes) + def decode(type : Float32.class, bytes : Bytes) : Float32 decode(Int32, bytes).unsafe_as(Float32) end @@ -101,11 +101,11 @@ module IO::ByteFormat encode(float.unsafe_as(Int64), bytes) end - def decode(type : Float64.class, io : IO) + def decode(type : Float64.class, io : IO) : Float64 decode(Int64, io).unsafe_as(Float64) end - def decode(type : Float64.class, bytes : Bytes) + def decode(type : Float64.class, bytes : Bytes) : Float64 decode(Int64, bytes).unsafe_as(Float64) end diff --git a/src/io/delimited.cr b/src/io/delimited.cr index 2142391502a0..172362309346 100644 --- a/src/io/delimited.cr +++ b/src/io/delimited.cr @@ -42,7 +42,7 @@ class IO::Delimited < IO @active_delimiter_buffer = Bytes.empty end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 check_open return 0 if @finished diff --git a/src/io/encoding.cr b/src/io/encoding.cr index 07c7661afd73..dd697e0a077b 100644 --- a/src/io/encoding.cr +++ b/src/io/encoding.cr @@ -27,7 +27,7 @@ class IO @closed = false end - def write(io, slice : Bytes) + def write(io, slice : Bytes) : Nil inbuf_ptr = slice.to_unsafe inbytesleft = LibC::SizeT.new(slice.size) outbuf = uninitialized UInt8[1024] @@ -42,7 +42,7 @@ class IO end end - def close + def close : Nil return if @closed @closed = true @iconv.close @@ -71,7 +71,7 @@ class IO @closed = false end - def read(io) + def read(io) : Nil loop do return unless @out_slice.empty? @@ -130,7 +130,7 @@ class IO @in_buffer_left += LibC::SizeT.new(io.read(Slice.new(@in_buffer + @in_buffer_left, buffer_remaining))) end - def read_byte(io) + def read_byte(io) : UInt8? read(io) if out_slice.empty? nil @@ -141,7 +141,7 @@ class IO end end - def read_utf8(io, slice) + def read_utf8(io, slice) : Int32 count = 0 until slice.empty? read(io) @@ -156,7 +156,7 @@ class IO count end - def gets(io, delimiter : UInt8, limit : Int, chomp) + def gets(io, delimiter : UInt8, limit : Int, chomp) : String? read(io) return nil if @out_slice.empty? @@ -238,7 +238,7 @@ class IO @out_slice += numbytes end - def close + def close : Nil return if @closed @closed = true diff --git a/src/io/file_descriptor.cr b/src/io/file_descriptor.cr index 204f468276b6..f14d2bc385e3 100644 --- a/src/io/file_descriptor.cr +++ b/src/io/file_descriptor.cr @@ -7,7 +7,7 @@ class IO::FileDescriptor < IO # The raw file-descriptor. It is defined to be an `Int`, but its size is # platform-specific. - def fd + def fd : Int @volatile_fd.get end @@ -31,7 +31,7 @@ class IO::FileDescriptor < IO end # :nodoc: - def self.from_stdio(fd) + def self.from_stdio(fd) : self Crystal::System::FileDescriptor.from_stdio(fd) end @@ -43,7 +43,7 @@ class IO::FileDescriptor < IO self.system_blocking = value end - def close_on_exec? + def close_on_exec? : Bool system_close_on_exec? end @@ -113,7 +113,7 @@ class IO::FileDescriptor < IO # file.gets(2) # => "he" # file.pos # => 2 # ``` - def pos + def pos : Int64 check_open system_pos - @in_buffer_rem.size @@ -193,11 +193,11 @@ class IO::FileDescriptor < IO close rescue nil end - def closed? + def closed? : Bool @closed end - def tty? + def tty? : Bool system_tty? end diff --git a/src/io/hexdump.cr b/src/io/hexdump.cr index 3df681f62ef8..2c155afe2e85 100644 --- a/src/io/hexdump.cr +++ b/src/io/hexdump.cr @@ -26,7 +26,7 @@ class IO::Hexdump < IO def initialize(@io : IO, @output : IO = STDERR, @read = false, @write = false) end - def read(buf : Bytes) + def read(buf : Bytes) : Int32 @io.read(buf).tap do |read_bytes| @output.puts buf[0, read_bytes].hexdump if @read && read_bytes end diff --git a/src/io/memory.cr b/src/io/memory.cr index 531acb9bcc40..44a05ed4868a 100644 --- a/src/io/memory.cr +++ b/src/io/memory.cr @@ -70,7 +70,7 @@ class IO::Memory < IO end # See `IO#read(slice)`. - def read(slice : Bytes) + def read(slice : Bytes) : Int32 check_open count = slice.size @@ -108,7 +108,7 @@ class IO::Memory < IO # See `IO#write_byte`. Raises if this `IO::Memory` is non-writeable, # or if it's non-resizeable and a resize is needed. - def write_byte(byte : UInt8) + def write_byte(byte : UInt8) : Nil check_writeable check_open @@ -131,7 +131,7 @@ class IO::Memory < IO end # :nodoc: - def gets(delimiter : Char, limit : Int32, chomp = false) + def gets(delimiter : Char, limit : Int32, chomp = false) : String? return super if @encoding || delimiter.ord >= 128 check_open @@ -170,7 +170,7 @@ class IO::Memory < IO end # :nodoc: - def read_byte + def read_byte : UInt8? check_open pos = Math.min(@pos, @bytesize) @@ -185,7 +185,7 @@ class IO::Memory < IO end # :nodoc: - def peek + def peek : Bytes check_open Slice.new(@buffer + @pos, @bytesize - @pos) @@ -211,7 +211,7 @@ class IO::Memory < IO end # :nodoc: - def gets_to_end + def gets_to_end : String return super if @encoding check_open @@ -257,7 +257,7 @@ class IO::Memory < IO # io.print "hello" # io.empty? # => false # ``` - def empty? + def empty? : Bool @bytesize == 0 end @@ -269,7 +269,7 @@ class IO::Memory < IO # io.rewind # io.gets(2) # => "he" # ``` - def rewind + def rewind : self @pos = 0 self end @@ -280,7 +280,7 @@ class IO::Memory < IO # io = IO::Memory.new "hello" # io.size # => 5 # ``` - def size + def size : Int32 @bytesize end @@ -317,7 +317,7 @@ class IO::Memory < IO # io.gets(2) # => "he" # io.pos # => 2 # ``` - def pos + def pos : Int32 @pos end @@ -384,7 +384,7 @@ class IO::Memory < IO # io.close # io.closed? # => true # ``` - def closed? + def closed? : Bool @closed end diff --git a/src/io/multi_writer.cr b/src/io/multi_writer.cr index c06bc8649ed9..2b03b7f90ce8 100644 --- a/src/io/multi_writer.cr +++ b/src/io/multi_writer.cr @@ -37,18 +37,18 @@ class IO::MultiWriter < IO @writers.each { |writer| writer.write(slice) } end - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise IO::Error.new("Can't read from IO::MultiWriter") end - def close + def close : Nil return if @closed @closed = true @writers.each { |writer| writer.close } if sync_close? end - def flush + def flush : Nil @writers.each(&.flush) end end diff --git a/src/io/sized.cr b/src/io/sized.cr index 40e2e49ad988..7c26b20319fa 100644 --- a/src/io/sized.cr +++ b/src/io/sized.cr @@ -25,7 +25,7 @@ class IO::Sized < IO @read_remaining = read_size.to_u64 end - def read(slice : Bytes) + def read(slice : Bytes) : Int32 check_open count = {slice.size.to_u64, @read_remaining}.min @@ -34,7 +34,7 @@ class IO::Sized < IO bytes_read end - def read_byte + def read_byte : UInt8? check_open if @read_remaining > 0 @@ -46,7 +46,7 @@ class IO::Sized < IO end end - def peek + def peek : Bytes? check_open return Bytes.empty if @read_remaining == 0 # EOF diff --git a/src/io/stapled.cr b/src/io/stapled.cr index 3fc6e2f92d7d..f236baf0ec76 100644 --- a/src/io/stapled.cr +++ b/src/io/stapled.cr @@ -30,7 +30,7 @@ class IO::Stapled < IO end # Reads a slice from `reader`. - def read(slice : Bytes) + def read(slice : Bytes) : Int32 check_open @reader.read(slice) diff --git a/src/openssl/ssl/socket.cr b/src/openssl/ssl/socket.cr index cbab93538402..c74e9142bd3c 100644 --- a/src/openssl/ssl/socket.cr +++ b/src/openssl/ssl/socket.cr @@ -115,7 +115,7 @@ abstract class OpenSSL::SSL::Socket < IO LibSSL.ssl_free(@ssl) end - def unbuffered_read(slice : Bytes) + def unbuffered_read(slice : Bytes) : Int32 check_open count = slice.size @@ -134,7 +134,7 @@ abstract class OpenSSL::SSL::Socket < IO end end - def unbuffered_write(slice : Bytes) + def unbuffered_write(slice : Bytes) : Nil check_open return if slice.empty? @@ -159,7 +159,7 @@ abstract class OpenSSL::SSL::Socket < IO end {% end %} - def unbuffered_close + def unbuffered_close : Nil return if @closed @closed = true diff --git a/src/socket.cr b/src/socket.cr index 7781515f7e6e..50515488d573 100644 --- a/src/socket.cr +++ b/src/socket.cr @@ -563,7 +563,7 @@ class Socket < IO close rescue nil end - def closed? + def closed? : Bool @closed end diff --git a/src/string/builder.cr b/src/string/builder.cr index eb187535420a..05ee124d5c2c 100644 --- a/src/string/builder.cr +++ b/src/string/builder.cr @@ -34,7 +34,7 @@ class String::Builder < IO io end - def read(slice : Bytes) + def read(slice : Bytes) : NoReturn raise "Not implemented" end @@ -51,7 +51,7 @@ class String::Builder < IO @bytesize += count end - def write_byte(byte : UInt8) + def write_byte(byte : UInt8) : Nil new_bytesize = real_bytesize + 1 if new_bytesize > @capacity resize_to_capacity(Math.pw2ceil(new_bytesize))