Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/socket/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ class Socket
module Server
# Accepts an incoming connection and returns the client socket.
#
# ```
# require "socket"
#
# server = TCPServer.new(2202)
# while true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loop do?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are fine. I'm fact, I'm starting to think we should remove loop, it adds absolutely nothing and it's just another way of doing something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I guess it was useful when it had its block argument :P

# socket = server.accept
# socket.puts Time.utc_now
# socket.close
# end
# ```
#
# If the server is closed after invoking this method, an `IO::Error` (closed stream) exception must be raised.
abstract def accept : Socket

# Accepts an incoming connection and returns the client socket.
#
# Returns `nil` if the server is closed after invoking this method.
#
# ```
# require "socket"
#
# server = TCPServer.new(2202)
# while socket = server.accept?
# socket.puts Time.utc_now
# socket.close
# end
# ```
abstract def accept? : Socket?

# Accepts an incoming connection and yields the client socket to the block.
Expand Down