fs2
fs2 copied to clipboard
Unify TCP/UDP and UnixSocket APIs
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 --
connectfor clients andbindfor servers, both taking the newcom.comcast.ip4s.GenSocketAddresstype, which is a supertype ofSocketAddress[Host]andUnixSocketAddress - 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
UnixSocketsas there's no utility provided that's not also provided byNetworknow - Deprecates
client,server,serverResourcein favor ofconnect,bindAndAccept,bind - Introduces
ServerSocket, which provides the bound address of the server socket, access to options, and a stream of client sockets. - Introduces
SocketInfoas a supertype ofSocketandServerSocket. - Introduces
address: GenSocketAddressonSocketInfoandpeerAddress: GenSocketAddressonSocket, replacinglocalAddressandremoteAddress(each of typeF[SocketAddress[IpAddress]]. - Deprecating
isOpenonSocketwhich is a vestige from when there was aclosemethod.
Datagram sockets have been similarly revamped:
openDatagramSockethas been replaced withbindDatagramSocket, taking aGenSocketAddress- 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:
- https://github.com/http4s/http4s/pull/7675/
- https://github.com/typelevel/fs2-chat/commit/c4f264324b2c61d876b9d064dd61fd01c5c603ba
TODO:
- Finish conversion of
DatagramSocketOptiontoSocketOption - Finish implementation of
supportedOptions/getOption/setOptionon all platforms and socket types - Implement a cross platform
NetworkInterface
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)
UnixDatagramSuite on Linux is failing due to https://github.com/jnr/jnr-unixsocket/pull/107. Will exclude it for now.
Going to merge this one this week unless there's any objections.