@@ -3,9 +3,8 @@ package io.github.erikvanzijst.scalatlsproxy
3
3
import java .io .IOException
4
4
import java .net .InetSocketAddress
5
5
import java .nio .ByteBuffer
6
- import java .nio .channels .{SelectionKey , Selector , SocketChannel , UnresolvedAddressException }
6
+ import java .nio .channels .{CancelledKeyException , SelectionKey , Selector , SocketChannel , UnresolvedAddressException }
7
7
import java .nio .charset .StandardCharsets
8
-
9
8
import com .typesafe .scalalogging .StrictLogging
10
9
11
10
import scala .util .Try
@@ -152,7 +151,7 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel, config:
152
151
}.get
153
152
154
153
if (phase == Response )
155
- if (clientKey.isValid && clientKey. isWritable) {
154
+ if (clientKey.isWritable) {
156
155
serverBuffer.flip()
157
156
clientChannel.write(serverBuffer)
158
157
serverBuffer.compact()
@@ -180,7 +179,7 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel, config:
180
179
}
181
180
182
181
if (phase == Error )
183
- if (clientKey.isValid && clientKey. isWritable) {
182
+ if (clientKey.isWritable) {
184
183
serverBuffer.flip()
185
184
clientChannel.write(serverBuffer)
186
185
serverBuffer.compact()
@@ -190,11 +189,10 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel, config:
190
189
}
191
190
192
191
} catch {
193
- case e : IOException =>
194
- val msg = s " $clientAddress -> $getServerAddress" +
192
+ case e @ ( _ : IOException | _ : CancelledKeyException ) =>
193
+ logger.warn( s " $clientAddress -> $getServerAddress" +
195
194
(if (phase == Established ) s " (up: ${upstreamPipe.bytes} down: ${downstreamPipe.bytes}) " else " " ) +
196
- s " connection failed: ${e.getClass.getSimpleName}: ${e.getMessage}"
197
- logger.warn(msg)
195
+ s " connection failed: ${e.getClass.getSimpleName}: ${e.getMessage}" )
198
196
close()
199
197
}
200
198
0 commit comments