Skip to content

Commit

Permalink
Don't unnecessarily parse server handle as URI
Browse files Browse the repository at this point in the history
It seems ServerHandle.uri is only used for logging purposes, no need to
parse it as a java.net.URI.

When using Windows named pipes (like bloop bsp --protocol local --pipe
\\.\pipe\foo), ServerHandle.WindowsLocal.uri crashes because of the
back-slashes when trying to parse it as a URI.
  • Loading branch information
alexarchambault committed Sep 4, 2021
1 parent 794af02 commit a0edc09
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions frontend/src/main/scala/bloop/io/ServerHandle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ import java.net.{InetAddress, InetSocketAddress, ServerSocket, URI}
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

0 comments on commit a0edc09

Please sign in to comment.