Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
= io: small refactorings and documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sirthias committed Oct 18, 2013
1 parent ba7171a commit e20bc7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
16 changes: 6 additions & 10 deletions spray-io/src/main/scala/spray/io/ConnectionHandler.scala
Expand Up @@ -24,16 +24,14 @@ trait ConnectionHandler extends Actor with ActorLogging {

//# final-stages
def baseCommandPipeline(tcpConnection: ActorRef): Pipeline[Command] = {
case x: Tcp.WriteCommand tcpConnection ! x
case x @ (_: Tcp.WriteCommand | _: Tcp.CloseCommand) tcpConnection ! x
case Pipeline.Tell(receiver, msg, sender) receiver.tell(msg, sender)
case x: Tcp.CloseCommand tcpConnection ! x
case x @ (Tcp.SuspendReading | Tcp.ResumeReading | Tcp.ResumeWriting) tcpConnection ! x
case _: Droppable // don't warn
case cmd log.warning("command pipeline: dropped {}", cmd)
}

def baseEventPipeline(keepOpenOnPeerClosed: Boolean): Pipeline[Event] = {
case Tcp.PeerClosed if keepOpenOnPeerClosed // don't automatically stop
def baseEventPipeline: Pipeline[Event] = {
case x: Tcp.ConnectionClosed
log.debug("Stopping connection actor, connection was {}", x)
context.stop(self)
Expand All @@ -44,16 +42,14 @@ trait ConnectionHandler extends Actor with ActorLogging {
//#

def running(tcpConnection: ActorRef, stage: PipelineStage, remoteAddress: InetSocketAddress,
localAddress: InetSocketAddress, keepOpenOnPeerClosed: Boolean = false): Receive = {
localAddress: InetSocketAddress): Receive = {
val pipelineContext = PipelineContext(context, remoteAddress, localAddress, log)
running(tcpConnection, stage, pipelineContext, keepOpenOnPeerClosed)
running(tcpConnection, stage, pipelineContext)
}

def running[C <: PipelineContext](tcpConnection: ActorRef, pipelineStage: RawPipelineStage[C],
pipelineContext: C, keepOpenOnPeerClosed: Boolean = false): Receive = {
val stage = pipelineStage(pipelineContext,
baseCommandPipeline(tcpConnection),
baseEventPipeline(keepOpenOnPeerClosed))
pipelineContext: C): Receive = {
val stage = pipelineStage(pipelineContext, baseCommandPipeline(tcpConnection), baseEventPipeline)
running(tcpConnection, stage)
}

Expand Down
9 changes: 4 additions & 5 deletions spray-io/src/main/scala/spray/io/SslTlsSupport.scala
Expand Up @@ -138,7 +138,7 @@ object SslTlsSupport {
runDelegatedTasks()
encrypt(send, tempBuf, fromQueue)
}
case CLOSED
case CLOSED // from now on: engine.isOutboundDone == true
if (postContentLeft) {
log.warning("SSLEngine closed prematurely while sending")
commandPL(Tcp.Abort)
Expand Down Expand Up @@ -176,14 +176,13 @@ object SslTlsSupport {
runDelegatedTasks()
decrypt(buffer, tempBuf)
}
case CLOSED
if (!engine.isOutboundDone) {
case CLOSED // from now on: engine.isInboundDone == true
if (originalCloseCommand eq null) {
closeEngine(tempBuf)
eventPL(Tcp.PeerClosed)
} else { // now both sides are closed on the SSL level
eventPL(originalCloseCommand.event)
// close the underlying connection, we don't need it any more
commandPL(Tcp.Close)
commandPL(Tcp.Close) // close the underlying connection, we don't need it any more
}
case BUFFER_UNDERFLOW
inboundReceptacle = buffer // save buffer so we can append the next one to it
Expand Down

0 comments on commit e20bc7c

Please sign in to comment.