55package akka .stream .impl .io
66
77import java .net .InetSocketAddress
8- import java .util .concurrent .TimeoutException
98import java .util .concurrent .atomic .{ AtomicBoolean , AtomicLong }
10-
119import scala .annotation .nowarn
1210import scala .collection .immutable
1311import scala .concurrent .{ Future , Promise }
1412import scala .concurrent .duration .{ Duration , FiniteDuration }
15-
1613import akka .{ Done , NotUsed }
1714import akka .actor .{ ActorRef , Terminated }
1815import akka .annotation .InternalApi
@@ -22,6 +19,7 @@ import akka.io.Tcp
2219import akka .io .Tcp ._
2320import akka .stream ._
2421import akka .stream .impl .ReactiveStreamsCompliance
22+ import akka .stream .impl .Timers
2523import akka .stream .impl .fusing .GraphStages .detacher
2624import akka .stream .scaladsl .{ BidiFlow , Flow , TcpIdleTimeoutException , Tcp => StreamTcp }
2725import akka .stream .scaladsl .Tcp .{ OutgoingConnection , ServerBinding }
@@ -593,19 +591,13 @@ private[stream] object ConnectionSourceStage {
593591 case Some (address) => s " on connection to [ $address] "
594592 case _ => " "
595593 }
594+ BidiFlow .fromGraph(
595+ new Timers .IdleTimeoutBidi (
596+ idleTimeout,
597+ createFailure = _ =>
598+ new TcpIdleTimeoutException (
599+ s " TCP idle-timeout encountered $connectionToString, no bytes passed in the last $idleTimeout" ,
600+ idleTimeout)))
596601
597- val toNetTimeout : BidiFlow [ByteString , ByteString , ByteString , ByteString , NotUsed ] =
598- BidiFlow .fromFlows(
599- Flow [ByteString ].mapError {
600- case _ : TimeoutException =>
601- new TcpIdleTimeoutException (
602- s " TCP idle-timeout encountered $connectionToString, no bytes passed in the last $idleTimeout" ,
603- idleTimeout)
604- },
605- Flow [ByteString ])
606- val fromNetTimeout : BidiFlow [ByteString , ByteString , ByteString , ByteString , NotUsed ] =
607- toNetTimeout.reversed // now the bottom flow transforms the exception, the top one doesn't (since that one is "fromNet")
608-
609- fromNetTimeout.atop(BidiFlow .bidirectionalIdleTimeout[ByteString , ByteString ](idleTimeout)).atop(toNetTimeout)
610602 }
611603}
0 commit comments