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

Don't unnecessarily parse server handle as URI #1559

Merged
merged 1 commit into from
Sep 6, 2021
Merged
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
11 changes: 6 additions & 5 deletions frontend/src/main/scala/bloop/io/ServerHandle.scala
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package bloop.io

import java.net.{InetAddress, InetSocketAddress, ServerSocket, URI}
import java.net.{InetAddress, InetSocketAddress, ServerSocket}

import bloop.sockets.{UnixDomainServerSocket, Win32NamedPipeServerSocket}

sealed trait ServerHandle {
def uri: URI
def uri: String
def server: ServerSocket
}

object ServerHandle {
final case class WindowsLocal(pipeName: String) extends ServerHandle {
val server: ServerSocket = new Win32NamedPipeServerSocket(pipeName)
def uri: URI = URI.create(s"local:$pipeName")
// pipeName should already look like "\\.\pipe\…", no need to add a prefix or anything
def uri: String = pipeName
override def toString: String = s"pipe $pipeName"
}

final case class UnixLocal(socketFile: AbsolutePath) extends ServerHandle {
val server: ServerSocket = new UnixDomainServerSocket(socketFile.syntax)
def uri: URI = URI.create(s"local://${socketFile.syntax}")
def uri: String = s"local://${socketFile.syntax}"
override def toString: String = s"local://${socketFile.syntax}"
}

final case class Tcp(address: InetSocketAddress, backlog: Int) extends ServerHandle {
val server: ServerSocket = new ServerSocket(address.getPort, backlog, address.getAddress)
def uri: URI = URI.create(s"tcp://${address.getHostString}:${server.getLocalPort}")
def uri: String = s"tcp://${address.getHostString}:${server.getLocalPort}"
override def toString: String = s"${address.getHostString}:${server.getLocalPort}"
}

Expand Down