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

Fix #2280: Add Unix-only IPv6 TCP support to javalib #2823

Merged

Conversation

LeeTibbert
Copy link
Contributor

We add IPv6 TCP, a.k.a streaming, support to javalib net on Unix-like systems.

This allows Scala Native programs using javalib TCP sockets to use a more efficient
network protocol.

This capability will probably be most used by programs ported from JVM or ScalaJVM.
posixlib sockets offer much finer control with less internal overhead.

The "Java Standard Library" section of the ReadTheDocs Scala Native documentation
is updated in the PR and provides the best description of the new IPv6 support.

The TL;DR is that if a Scala Native JVM program is using IPv6 successfully, then
that program should work with this new IPv6 support.

This work follows the two decade long precedent of the JVM in silently
enabling the use of IPv6 if any network interface, other than the loopback
interface, is configured for IPv6. Programs can execute code to
disable that default enabling.

This PR incorporates the changes from two network related PRs that
were merged in the 0.4.x stream.

It has benefited from review and discussion in WIP PR #2484, which
it supersedes.

@LeeTibbert LeeTibbert changed the title Pr j net tcp6 socket i2280 v2 Fix #2280: Add Unix-only IPv6 TCP support to javalib Sep 1, 2022
@LeeTibbert
Copy link
Contributor Author

I believe that support for Windows could be provided by someone with knowledge. I believe
there are three key intervention points where Windows does something different. Of course,
there could be more.

Over the course of the next few months, I hope to get a Windows development environment
set up and may take a run at providing Windows support. The Unix code can be
exercised and provide value during that time, even though not "All at once".

@LeeTibbert
Copy link
Contributor Author

LeeTibbert commented Sep 1, 2022

I believe that support for Windows could be provided by someone with knowledge. I believe
there are three key intervention points where Windows does something different. Of course,
there could be more.

Over the course of the next few months, I hope to get a Windows development environment
set up and may take a run at providing Windows support. The Unix code can be
exercised and provide value during that time, even though IPv6 support is not provided "All at once".

Comment on lines +167 to +168
val prop = System.getProperty("java.net.preferIPv4Stack")
val useIPv4 = (prop != null) && (prop.toLowerCase() == "true")
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really important but we can use sys.SystemProperties.preferIPv4Stack.value here. Just a tip for future usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can retrace the sys.SystemProperties.preferIPv4Stack path again. I usually like single points
of implementation. Either I found the sys.systemProperties after I wrote this. My memory
is that there is a subtlety about the time the (lazy?) val is evaluated. The present code
is pretty sure to evaluate when the first Socket is accessed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like to do thing right the first time, but this whole initialization is subject to "appropriate precision".
That is, it is almost certain that likely change will overwhelm & obliterate putting too fine a point on
this initialization in particular.

Thank you for the merge.

@WojciechMazur WojciechMazur merged commit f35adcf into scala-native:main Sep 5, 2022
@LeeTibbert
Copy link
Contributor Author

LeeTibbert commented Sep 5, 2022

For future reference: Lee: double-check when the Scala sys.SystemProperties.preferIPv4Stack gets evaluated
and how lazy that evaluation is. The vague timing issue I have been trying to remember may hinge on the
fact that Scala Native needs to give an application time after Scala has initialized, to set java.net.preferMumble.
Then the SN lazy val will return that value. I might be dreaming here, or it might be subtle, so check carefully,
the next time this comes to haunt your nights.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants