Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
RFC 0007: Event loop refactor #7
Changes from 1 commit
9a93501
04a7c37
c70c896
ba1e1a4
3e40217
3bff4d1
9afc76f
9ab3a8e
0647def
113e401
b1978fa
a42930c
5db0edb
a08f935
5b7f663
8b9b09b
04462e8
8eee22e
6334e16
526b3d8
53a1861
1061a51
246c87f
f74db24
70942fa
b7da5cc
252f546
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
address
type could perhaps be abstracted. We need to support both types, though they both boil down to the same interface:#to_unsafe
returning a pointer to aLibC::Sockaddr
and#size
returning its size in bytes.So it could be an option to define an interface for that and use that as type restriction. But we cannot actually make it strictly type-safe because the return type of
#to_unsafe
isVoid*
and we cannot enforce a pointer toLibC::Sockaddr
(soArray
would implement this interface for example).Alternatively, we could remove the type restriction entirely because any type that fulfills the implicit interface should work.
I think it's better to be explicit, either with
::Socket::Addrinfo | ::Socket::Address
or an abstract module interface.Introducing a new model would also solve the issue that the
Socket
name space is not in core lib (see https://github.com/crystal-lang/rfcs/blob/rfc/0005/text/0007-event_loop-refactor.md#socket).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually hard to stub out
::Socket::Addrinfo
and::Socket::Address
because that would require defining theSocket
namespace, which is a class that inheritsIO
and that's so much complexity we could just includesocket.cr
.I've considered introducing a module which could be included in both types. But that's actually not a great solution for when we return an address.
So I think it's probably best to introduce an internal struct type which holds a reference to
LibC::Sockaddr
and its size.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or to leave it as the union?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those types are not in core lib. Their existence depends on
require "socket"
. So leaving the union won't work as is. Trying to see if we can stub it out (or replace with an internal type) is one possible way to deal with that.But I think a better approach is described in #7 (comment)