Skip to content

Commit c853b4e

Browse files
committed
Fix: use the deprecated annotation when possible (sockets)
1 parent d85a2ac commit c853b4e

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

src/socket.cr

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,40 @@ class Socket < IO
5151

5252
# Creates a TCP socket. Consider using `TCPSocket` or `TCPServer` unless you
5353
# need full control over the socket.
54-
#
55-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use `#blocking=`
56-
# to change the blocking mode after creating the socket.
57-
def self.tcp(family : Family, blocking = nil) : self
54+
def self.tcp(family : Family) : self
55+
new(family, Type::STREAM, Protocol::TCP)
56+
end
57+
58+
@[Deprecated("The blocking argument is deprecated. Use #blocking= to change it after creating the socket.")]
59+
def self.tcp(family : Family, blocking) : self
5860
new(family, Type::STREAM, Protocol::TCP, blocking)
5961
end
6062

6163
# Creates an UDP socket. Consider using `UDPSocket` unless you need full
6264
# control over the socket.
63-
#
64-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use `#blocking=`
65-
# to change the blocking mode after creating the socket.
66-
def self.udp(family : Family, blocking = nil) : self
65+
def self.udp(family : Family) : self
66+
new(family, Type::DGRAM, Protocol::UDP)
67+
end
68+
69+
@[Deprecated("The blocking argument is deprecated. Use #blocking= to change it after creating the socket.")]
70+
def self.udp(family : Family, blocking) : self
6771
new(family, Type::DGRAM, Protocol::UDP, blocking)
6872
end
6973

7074
# Creates an UNIX socket. Consider using `UNIXSocket` or `UNIXServer` unless
7175
# you need full control over the socket.
7276
#
73-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use `#blocking=`
74-
# to change the blocking mode after creating the socket.
77+
# NOTE: The *blocking* argument is deprecated. Use `#blocking=` to change it
78+
# after creating the socket.
7579
def self.unix(type : Type = Type::STREAM, blocking = nil) : self
7680
new(Family::UNIX, type, blocking: blocking)
7781
end
7882

7983
# Creates a socket. Consider using `TCPSocket`, `TCPServer`, `UDPSocket`,
8084
# `UNIXSocket` or `UNIXServer` unless you need full control over the socket.
8185
#
82-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use `#blocking=`
83-
# to change the blocking mode after creating the socket.
86+
# NOTE: The *blocking* argument is deprecated since Crystal 1.17. Use
87+
# `#blocking=` to change it after creating the socket.
8488
def initialize(family : Family, type : Type, protocol : Protocol = Protocol::IP, blocking = nil)
8589
# This method is `#initialize` instead of `.new` because it is used as super
8690
# constructor from subclasses.
@@ -95,8 +99,8 @@ class Socket < IO
9599
# event loop runtime requirements.
96100
#
97101
# NOTE: On Windows the handle must have been created with `WSA_FLAG_OVERLAPPED`.
98-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use `#blocking=`
99-
# to change the blocking mode after creating the socket.
102+
# NOTE: The *blocking* argument is deprecated since Crystal 1.17. Use
103+
# `#blocking=` to change it after creating the socket.
100104
def initialize(fd, @family : Family, @type : Type, @protocol : Protocol = Protocol::IP, blocking = nil)
101105
initialize(handle: fd, family: family, type: type, protocol: protocol)
102106
blocking = Crystal::EventLoop.default_socket_blocking? if blocking.nil?

src/socket/tcp_socket.cr

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ require "./ip_socket"
1616
class TCPSocket < IPSocket
1717
# Creates a new `TCPSocket`, waiting to be connected.
1818
#
19-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use
20-
# `Socket#blocking=` to change the blocking mode after creating the socket.
19+
# NOTE: The *blocking* argument is deprecated since Crystal 1.17. Use
20+
# `Socket#blocking=` to change it after creating the socket.
2121
def self.new(family : Family = Family::INET, blocking = nil)
2222
super(family, Type::STREAM, Protocol::TCP, blocking)
2323
end
@@ -28,8 +28,8 @@ class TCPSocket < IPSocket
2828
# connection time to the remote server with `connect_timeout`. Both values
2929
# must be in seconds (integers or floats).
3030
#
31-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use
32-
# `Socket#blocking=` to change the blocking mode after creating the socket.
31+
# NOTE: The *blocking* argument is deprecated since Crystal 1.17. Use
32+
# `Socket#blocking=` to change it after creating the socket.
3333
def initialize(host : String, port, dns_timeout = nil, connect_timeout = nil, blocking = nil)
3434
Addrinfo.tcp(host, port, timeout: dns_timeout) do |addrinfo|
3535
super(addrinfo.family, addrinfo.type, addrinfo.protocol, blocking)
@@ -44,7 +44,8 @@ class TCPSocket < IPSocket
4444
super family, type, protocol
4545
end
4646

47-
# constructor for TCPServer#accept?
47+
# Internal constructor for TCPServer#accept?
48+
# The *blocking* arg is purely informational.
4849
protected def initialize(*, handle, family, type, protocol, blocking)
4950
super(handle: handle, family: family, type: type, protocol: protocol, blocking: blocking)
5051
end
@@ -56,8 +57,8 @@ class TCPSocket < IPSocket
5657
# event loop runtime requirements.
5758
#
5859
# NOTE: On Windows the handle must have been created with `WSA_FLAG_OVERLAPPED`.
59-
# NOTE: The *blocking* arg is deprecated since Crystal 1.17. Use
60-
# `Socket#blocking=` to change the blocking mode after creating the socket.
60+
# NOTE: The *blocking* argument is deprecated since Crystal 1.17. Use
61+
# `Socket#blocking=` to change it after creating the socket.
6162
def initialize(*, fd : Handle, family : Family = Family::INET, blocking = nil)
6263
super fd, family, Type::STREAM, Protocol::TCP, blocking
6364
end

src/socket/unix_socket.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class UNIXSocket < Socket
3333
end
3434

3535
# Internal constructor for UNIXSocket#pair and UNIXServer#accept?
36+
# The *blocking* arg is purely informational.
3637
protected def initialize(*, handle : Handle, type : Type = Type::STREAM, path : Path | String? = nil, blocking : Bool = nil)
3738
@path = path.to_s
3839
super handle: handle, family: Family::UNIX, type: type, protocol: Protocol::IP, blocking: blocking

0 commit comments

Comments
 (0)