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

Refactor Socket#system_receive to return Address #14384

Merged

Conversation

straight-shoota
Copy link
Member

The internal method Socket#system_receive returns the remote address in a platform-specific way, consisting of a LibC::Sockaddr pointer and the length of the address.
I'm not sure what's the motivation behind that and I don't see a good reason. Returning a Socket::Address value directly leads to a cleaner API with native Crystal types only.

This cleans up the interface and make it free of platform specifics in preparation of a bigger refactoring of the event loop (#10766).

This cleans up the interface and make it free of platform specifics
in preparation of a bigger refactoring (crystal-lang#10766).
Comment on lines +91 to +92
bytes_read, address = system_receive(message)
{bytes_read, address.as(IPAddress)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be shortened to, I think:

Suggested change
bytes_read, address = system_receive(message)
{bytes_read, address.as(IPAddress)}
system_receive(message)

Copy link
Contributor

Choose a reason for hiding this comment

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

@Sija but system_receive returns an Address while we want an IPAddress here.

@straight-shoota straight-shoota added this to the 1.12.0 milestone Mar 22, 2024
@straight-shoota straight-shoota merged commit d3d2668 into crystal-lang:master Mar 24, 2024
58 checks passed
@straight-shoota straight-shoota deleted the refactor/receive-address branch March 24, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants