Skip to content

Unify TCP/UDP and UnixSocket APIs #3563

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

Open
wants to merge 71 commits into
base: main
Choose a base branch
from
Open

Unify TCP/UDP and UnixSocket APIs #3563

wants to merge 71 commits into from

Conversation

mpilquist
Copy link
Member

@mpilquist mpilquist commented Apr 8, 2025

Fixes #3560

This PR revamps fs2.io.net in a number of significant ways:

  • Unifies support for IP and Unix sockets in to a single set of operations -- connect for clients and bind for servers, both taking the new com.comcast.ip4s.GenSocketAddress type, which is a supertype of SocketAddress[Host] and UnixSocketAddress
  • Resultantly adds support for socket options on unix sockets
  • Deprecates SocketGroup - there has never really been a great reason to manage explicit thread pools / async socket groups & the API was JVM only. With the new polling system, there's even less of a reason to ever use the explicitly managed socket groups.
  • Deprecates UnixSockets as there's no utility provided that's not also provided by Network now
  • Deprecates client, server, serverResource in favor of connect, bindAndAccept, bind
  • Introduces ServerSocket, which provides the bound address of the server socket, access to options, and a stream of client sockets.
  • Introduces SocketInfo as a supertype of Socket and ServerSocket.
  • Introduces address: GenSocketAddress on SocketInfo and peerAddress: GenSocketAddress on Socket, replacing localAddress and remoteAddress (each of type F[SocketAddress[IpAddress]].
  • Deprecating isOpen on Socket which is a vestige from when there was a close method.

Datagram sockets have been similarly revamped:

  • openDatagramSocket has been replaced with bindDatagramSocket, taking a GenSocketAddress
  • As of this PR, datagrams over unix sockets are only supported on the JVM, via jnr-unixsocket (JEP-380 doesn't support datagrams). Node.js doesn't have built-in support for datagrams over unix sockets, though we could add via a dependency. Datagram sockets, in general, are not currently implemented on native.

Updates to downstream projects:

TODO:

  • Finish conversion of DatagramSocketOption to SocketOption
  • Finish implementation of supportedOptions / getOption / setOption on all platforms and socket types
  • Implement a cross platform NetworkInterface

@mpilquist mpilquist marked this pull request as ready for review April 22, 2025 12:07
@armanbilge armanbilge self-requested a review April 23, 2025 14:52
@mpilquist
Copy link
Member Author

Need to lazily load socket options that were added in Java 9+. Here's an example failure with 3.13.0-M2 and http4s tests running on Java 8:

java.lang.NoSuchFieldError: SO_REUSEPORT
	at fs2.io.net.SocketOptionCompanionPlatform.$init$(SocketOptionPlatform.scala:75)
	at fs2.io.net.SocketOption$.<clinit>(SocketOption.scala:36)
	at org.http4s.ember.server.internal.ServerHelpers$.$anonfun$unixSocketServer$1(ServerHelpers.scala:150)

@mpilquist mpilquist changed the title Unify TCP and UnixSocket APIs Unify TCP/UDP and UnixSocket APIs Jun 4, 2025
@mpilquist
Copy link
Member Author

UnixDatagramSuite on Linux is failing due to jnr/jnr-unixsocket#107. Will exclude it for now.

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.

Improve unix sockets support
2 participants