-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change signature of pipeline factories to accept a SocketConnection
- Loading branch information
1 parent
760ca2d
commit dee6f09
Showing
14 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
core/src/main/scala/org/http4s/blaze/channel/SocketConnection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.http4s.blaze.channel | ||
|
||
import java.net.{InetAddress, InetSocketAddress, SocketAddress} | ||
|
||
/** | ||
* Created by Bryce Anderson on 5/26/14. | ||
*/ | ||
trait SocketConnection { | ||
/** Return the SocketAddress of the remote connection */ | ||
def remote: SocketAddress | ||
|
||
/** Return the local SocketAddress associated with the connection */ | ||
def local: SocketAddress | ||
|
||
/** Return of the connection is currently open */ | ||
def isOpen: Boolean | ||
|
||
/** Close this Connection */ | ||
def close(): Unit | ||
|
||
final def remoteInetAddress: Option[InetAddress] = remote match { | ||
case addr: InetSocketAddress => Option(addr.getAddress) | ||
case _ => None | ||
} | ||
|
||
final def localInetAddress: Option[InetAddress] = local match { | ||
case addr: InetSocketAddress => Option(addr.getAddress) | ||
case _ => None | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
core/src/main/scala/org/http4s/blaze/channel/nio1/NIO1SocketConnection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.http4s.blaze.channel.nio1 | ||
|
||
import java.nio.channels.{SelectableChannel, SocketChannel} | ||
import org.http4s.blaze.channel.SocketConnection | ||
import java.net.SocketAddress | ||
|
||
/** | ||
* Created by Bryce Anderson on 5/26/14. | ||
*/ | ||
|
||
object NIO1Connection { | ||
def apply(connection: SelectableChannel): SocketConnection = connection match { | ||
case ch: SocketChannel => NIO1SocketConnection(ch) | ||
case _ => | ||
// We don't know what type this is, so implement what we can | ||
new SocketConnection { | ||
override def remote: SocketAddress = local | ||
|
||
override def local: SocketAddress = new SocketAddress {} | ||
|
||
override def close(): Unit = connection.close() | ||
|
||
override def isOpen: Boolean = connection.isOpen | ||
} | ||
} | ||
|
||
} | ||
|
||
case class NIO1SocketConnection(connection: SocketChannel) extends SocketConnection { | ||
|
||
override def remote: SocketAddress = connection.getRemoteAddress | ||
|
||
override def local: SocketAddress = connection.getLocalAddress | ||
|
||
override def isOpen: Boolean = connection.isConnected | ||
|
||
override def close(): Unit = connection.close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/main/scala/org/http4s/blaze/channel/nio2/NIO2SocketConnection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.http4s.blaze.channel.nio2 | ||
|
||
import org.http4s.blaze.channel.SocketConnection | ||
import java.nio.channels.AsynchronousSocketChannel | ||
import java.net.SocketAddress | ||
|
||
/** | ||
* Created by Bryce Anderson on 5/26/14. | ||
*/ | ||
case class NIO2SocketConnection(connection: AsynchronousSocketChannel) extends SocketConnection { | ||
|
||
override def remote: SocketAddress = connection.getRemoteAddress | ||
|
||
override def local: SocketAddress = connection.getLocalAddress | ||
|
||
override def isOpen: Boolean = connection.isOpen | ||
|
||
override def close(): Unit = connection.close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters