Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC 0007: Event loop refactor #7

Merged
merged 27 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift click to select a range
9a93501
Event loop refactor
straight-shoota May 2, 2024
04a7c37
Fix filename
straight-shoota May 7, 2024
c70c896
Fill guide-level explanation
straight-shoota May 7, 2024
ba1e1a4
Add abstract interface description
straight-shoota May 7, 2024
3e40217
Fix associate *Socket* subsection with *Optional event loop features*
straight-shoota May 27, 2024
3bff4d1
fixup
straight-shoota May 27, 2024
9afc76f
Resolve *`read` and `write` behaviour*
straight-shoota May 28, 2024
9ab3a8e
Resolve *Timeout and Resume events*
straight-shoota May 28, 2024
0647def
Fix typo
straight-shoota May 28, 2024
113e401
Drop `EventLoop#send`, `#receive`
straight-shoota May 28, 2024
b1978fa
Separate `EventLoop` interface into modules
straight-shoota May 28, 2024
a42930c
typo
straight-shoota May 28, 2024
5db0edb
Add `run` and `interrupt` for completeness
straight-shoota May 28, 2024
a08f935
fixup
straight-shoota May 29, 2024
5b7f663
Improve API docs for `EventLoop::Socket`
straight-shoota May 29, 2024
8b9b09b
Update text/0007-event_loop-refactor.md
straight-shoota May 30, 2024
04462e8
Apply suggestions from code review
straight-shoota May 31, 2024
8eee22e
Update implemented API
straight-shoota Nov 12, 2024
6334e16
Resolve `Socket` question
straight-shoota Nov 12, 2024
526b3d8
cleanup
straight-shoota Nov 12, 2024
53a1861
Add reference to RFC 0009
straight-shoota Nov 12, 2024
1061a51
Fix `write`/`read` docs
straight-shoota Nov 14, 2024
246c87f
Drop unresolved questions
straight-shoota Nov 14, 2024
f74db24
Turn _Type for sizes_ into a future possibility
straight-shoota Nov 14, 2024
70942fa
Turn more open questions into future possibilities
straight-shoota Nov 14, 2024
b7da5cc
Drop *Rationale and alternatives*
straight-shoota Nov 14, 2024
252f546
Add *Rationale and alternatives*
straight-shoota Nov 15, 2024
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
Prev Previous commit
Next Next commit
Improve API docs for EventLoop::Socket
  • Loading branch information
straight-shoota committed May 29, 2024
commit 5b7f663ad1b5506570e15108e9aed9561be89cad
65 changes: 45 additions & 20 deletions text/0007-event_loop-refactor.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,39 121,64 @@ abstract class Crystal::System::EventLoop
end

module Socket
# Reads at least one byte from the socket into *slice* and continues fiber
# when the read is complete.
# Returns the number of bytes read.
# Reads at least one byte from the socket into *slice*.
#
# Blocks the current fiber if no data is available for reading, continuing
# when available. Otherwise returns immediately.
#
# Returns the number of bytes read (up to `slice.size`).
# Returns 0 when the socket is closed and no data available.
#
# Use `#send_to` for sending a message to a specific target address.
beta-ziliani marked this conversation as resolved.
Show resolved Hide resolved
abstract def read(socket : ::Socket, slice : Bytes) : Int32

# Writes at least one byte from *slice* to the socket and continues fiber
# when the write is complete.
# Returns the number of bytes written.
# Writes at least one byte from *slice* to the socket.
#
# Blocks the current fiber if the socket is not ready for writing,
# continuing when ready. Otherwise returns immediately.
#
# Returns the number of bytes written (up to `slice.size`).
#
# Use `#receive_from` for capturing the source address of a message.
abstract def write(socket : ::Socket, slice : Bytes) : Int32

# Accepts an incoming TCP connection on the socket and continues fiber when a
# connection is available.
# Accepts an incoming TCP connection on the socket.
#
# Blocks the current fiber if no connection is watiting, continuing when one
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
# becomes available. Otherwise returns immediately.
#
# Returns a handle to the socket for the new connection.
abstract def accept(socket : ::Socket) : ::Socket::Handle?

# Opens a connection on *socket* to the target *address* and continues fiber
# when the connection has been established.
# Returns `IO::Error` but does not raise.
# Opens a connection on *socket* to the target *address*.
#
# Blocks the current fiber and continues when the connection is established.
#
# Returns `IO::Error` in case of en error. The caller is responsible for
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
# raising it as an exception if necessary.
abstract def connect(socket : ::Socket, address : ::Socket::Addrinfo | ::Socket::Address, timeout : ::Time::Span?) : IO::Error?

# Writes at least one byte from *slice* to the socket with a target *address* (UDP)
# and continues fiber when the write is complete.
# Returns the number of bytes written.
# Sends at least one byte from *slice* to the socket with a target address
# *address*.
#
# Blocks the current fiber if the socket is not ready for writing,
# continuing when ready. Otherwise returns immediately.
#
# Returns the number of bytes sent (up to `slice.size`).
abstract def send_to(socket : ::Socket, slice : Bytes, address : ::Socket::Address) : Int32

# Receives on the socket into *slice* and continues fiber when the package is
# completed.
# Returns a tuple containing the number of bytes received and the source address
# of the packet (UDP).
# Receives at least one byte from the socket into *slice*, capturing the
# source address.
#
# Blocks the current fiber if if no data is available for reading, continuing
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
# when available. Otherwise returns immediately.
#
# Returns a tuple containing the number of bytes received (up to `slice.size`)
# and the source address.
abstract def receive_from(socket : ::Socket, slice : Bytes) : Tuple(Int32, ::Socket::Address)

# Closes the *socket*.
abstract def close(socket :: Socket) : Nil
# Closes the socket.
abstract def close(socket : ::Socket) : Nil
end
end
```
Expand Down