Skip to content

Commit

Permalink
Don't NPE on ServerChannel.getRemoteAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvanzijst committed Sep 3, 2021
1 parent b52c4ad commit 21374c1
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel, config:

private var phase = Destination

def getServerAddress: String = Option(serverChannel)
.filter(_.isOpen)
.map(_.getRemoteAddress.toString)
.orElse(Option(destination)
.map(d => d._1 + ":" + d._2)
.orElse(Some("unconnected")) )
.get
def getServerAddress: String =
Try(serverChannel.getRemoteAddress.toString)
.recover { case _ => destination._1 + ":" + destination._2 }
.recover { case _ => "unconnected" }
.get

private def readClient(): Unit = {
if (clientKey.isValid && clientKey.isReadable && clientChannel.read(clientBuffer) == -1)
Expand Down

0 comments on commit 21374c1

Please sign in to comment.