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 UnixSockets classpath detection logic #2624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions io/jvm/src/main/scala/fs2/io/net/unixsocket/JdkUnixSockets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ object JdkUnixSockets {

def supported: Boolean = StandardProtocolFamily.values.size > 2

implicit def forAsync[F[_]](implicit F: Async[F]): UnixSockets[F] =
new UnixSockets.AsyncUnixSockets[F] {
protected def openChannel(address: UnixSocketAddress) = F.delay {
val ch = SocketChannel.open(StandardProtocolFamily.UNIX)
ch.connect(UnixDomainSocketAddress.of(address.path))
ch
}
implicit def forAsync[F[_]: Async]: UnixSockets[F] =
new JdkUnixSocketsImpl[F]
}

private[unixsocket] class JdkUnixSocketsImpl[F[_]](implicit F: Async[F])
extends UnixSockets.AsyncUnixSockets[F] {
protected def openChannel(address: UnixSocketAddress) = F.delay {
val ch = SocketChannel.open(StandardProtocolFamily.UNIX)
ch.connect(UnixDomainSocketAddress.of(address.path))
ch
}

protected def openServerChannel(address: UnixSocketAddress) = F.blocking {
val serverChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX)
serverChannel.configureBlocking(false)
serverChannel.bind(UnixDomainSocketAddress.of(address.path))
(F.blocking(serverChannel.accept()), F.blocking(serverChannel.close()))
}
}
protected def openServerChannel(address: UnixSocketAddress) = F.blocking {
val serverChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX)
serverChannel.configureBlocking(false)
serverChannel.bind(UnixDomainSocketAddress.of(address.path))
(F.blocking(serverChannel.accept()), F.blocking(serverChannel.close()))
}
}
27 changes: 15 additions & 12 deletions io/jvm/src/main/scala/fs2/io/net/unixsocket/JnrUnixSockets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ object JnrUnixSockets {
case _: ClassNotFoundException => false
}

implicit def forAsync[F[_]](implicit F: Async[F]): UnixSockets[F] =
new UnixSockets.AsyncUnixSockets[F] {
protected def openChannel(address: UnixSocketAddress) =
F.delay(UnixSocketChannel.open(new JnrUnixSocketAddress(address.path)))
implicit def forAsync[F[_]: Async]: UnixSockets[F] =
new JnrUnixSocketsImpl[F]
}

protected def openServerChannel(address: UnixSocketAddress) = F.blocking {
val serverChannel = UnixServerSocketChannel.open()
serverChannel.configureBlocking(false)
val sock = serverChannel.socket()
sock.bind(new JnrUnixSocketAddress(address.path))
(F.blocking(serverChannel.accept()), F.blocking(serverChannel.close()))
}
}
private[unixsocket] class JnrUnixSocketsImpl[F[_]](implicit F: Async[F])
extends UnixSockets.AsyncUnixSockets[F] {
protected def openChannel(address: UnixSocketAddress) =
F.delay(UnixSocketChannel.open(new JnrUnixSocketAddress(address.path)))

protected def openServerChannel(address: UnixSocketAddress) = F.blocking {
val serverChannel = UnixServerSocketChannel.open()
serverChannel.configureBlocking(false)
val sock = serverChannel.socket()
sock.bind(new JnrUnixSocketAddress(address.path))
(F.blocking(serverChannel.accept()), F.blocking(serverChannel.close()))
}
}