-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
languageChanges to the Raku Programming LanguageChanges to the Raku Programming Language
Description
When IO::Socket::Async
was designed, its bind-udp
was developed just with unicast and broadcast modes in mind, hence it has the option :broadcast
, defaulting to :unicast
. MoarVM similarly was designed only to handle this option, though I've since added support for multicast.
Adding a :multicast
option would, given the current interface, feel nice, but provide two incompatible named arguments. That is
IO::Socket::Async.bind-udp($host, :broadcast, :multicast);
The above makes no sense and will/should ultimately create an error somewhere further down the line at the VM level, which will provide a LTA error.
jonathanstowe
Metadata
Metadata
Assignees
Labels
languageChanges to the Raku Programming LanguageChanges to the Raku Programming Language
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
alabamenhu commentedon Dec 19, 2024
In a perfect world, we'd have:
This would require a language revision, plus gating. But then we could throw a better error of having bad arguments / unsupport values (+ extra bikeshedding, as @timo suggested equally cromulent
:cast<uni>
,:cast<multi>
and:cast<broad>
alabamenhu commentedon Dec 19, 2024
We could just throw an error when detecting
:broadcast
and:multicast
. It's a simple check, and we could use the incompatible adverbs error. The docs describe them as adverb, although they could just as easy be envisioned as named args:This method would be backwards compatible with current code.
alabamenhu commentedon Dec 19, 2024
We could do nothing. Any of the VMs should instead catch it or error internally, and pass it back up.
niner commentedon Dec 19, 2024
The type argument should not be a string. That's what Enums are for. Otherwise we'd again have to validate that argument against an allowlist manually and there would not be any tool support for allowed values.
lizmat commentedon Dec 19, 2024
Perhaps better an
nqp::const
value?alabamenhu commentedon Dec 19, 2024
Could do it like with the Endianness then:
alabamenhu commentedon Dec 26, 2024
As I've continued to refine the implementation, a few other wrinkles to consider:
With regards to the interface, NodeJS says the OS will choose a default interface if not specified for IPv6, but can be specified (and virtually all IPv6 examples do include this, with some users reporting issues unless they do). NodeJS's manner is passing
NULL
to libuv's add_membership, which fails, at least, on macOS. Julia makes no mention of the group/interfaces being optional in their docs, but does the same. They explicitly disable testing on some systems, though, implying there's still some trouble to be figured out here, as BSD/Mac, Windows, and other *nix all handle the interfaces naming/indexing a teeny bit differently.In other words, it seems like it's a really good idea for us to expose the ability to specify an interface, and probably also leaving it to module land to decide optimal defaults (and/or even saying attempts will be made without it specified, but no guarantees).
Regardless, we need to have a way to specify one or more interfaces.
Both NodeJS and Julia specify the broadcast/multicast status after creating the socket, akin to the following in Raku:
I don't necessarily think we need to go that route, since to me it's not immediately intuitive that you should bind to
::
(or0.0.0.0
for IPv4). In that senseSeems much cleaner and intuitive. However, there are even more potential complexities that NodeJS and Julia support. Potential rendering in a single call as Raku currently does, versus the multicall way they do:
alabamenhu commentedon Dec 31, 2024
Actually, @timo had an even better idea. Multidispatch, such that the signatures would be:
The broadcast option doesn't really need a host, it's only available on IPv4 sockets and will always be
255.255.255.255
, but it feels weird to have just the port with:broadcast
. Instead, we could provide better error message if there's a problem binding to the host, suggesting255.255.255.255
(on a given network this might reroute to192.168.1.255
, so that would also be valid, but the 4x255 functions like127.0.0.1
as an alias).