Check following defined methods in class hierarchy, check the bold text.
╰─ $ cr run 2.cr
server.all_methods # => {
“UNIXServer” =>
[def initialize(path : String, type : Type = Type::STREAM, backlog : Int = 128),
def initialize(*, fd : Handle, type : Type = Type::STREAM, path : String | ::Nil),
def accept?() : UNIXSocket | ::Nil,
def close(delete = true) : Nil],
“Socket::Server” =>
[def accept() : IO,
def accept(),
def accept?() : IO | ::Nil,
def accept?()],
“UNIXSocket” =>
[def path() : String | ::Nil,
def initialize(path : String, type : Type = Type::STREAM),
def initialize(family : Family, type : Type),
def initialize(*, fd : Handle, type : Type = Type::STREAM, path : String | ::Nil),
def local_address() : Socket::UNIXAddress,
def remote_address() : Socket::UNIXAddress,
def receive()],
“Socket” =>
[def fd(),
def family() : Family,
def type() : Type,
def protocol() : Protocol,
def initialize(family : Family, type : Type, protocol : Protocol = Protocol::IP, blocking),
def initialize(fd, family : Family, type : Type, protocol : Protocol = Protocol::IP, blocking),
def connect(host : String, port : Int, connect_timeout) : Nil,
def connect(addr, timeout) : Nil,
def connect(addr, timeout),
def bind(host : String, port : Int) : Nil,
def bind(port : Int),
def bind(addr : Socket::Address) : Nil,
def listen(backlog : Int = SOMAXCONN) : Nil,
def listen(backlog : Int = SOMAXCONN),
def accept() : Socket,
def accept?() : Socket | ::Nil,
So, when i write code like this:
require "socket"
def handle_client(client)
message = client.gets
client.puts message
end
server = UNIXServer.new("/tmp/myapp.sock")
while client = server.accept # this #accept is Socket::Server#accept
spawn handle_client(client)
end
Does the behavior same as client = server.accept?
(this #accept? is UNIXServer#accept) ?
Thanks