!act #13490 Changed the callback to SocketOption to accept a channel instead of a Socket, this allows for using the nio features.

For example in Java 7 you can now join a multicast group:

case class JoinGroup(group: InetAddress, networkInterface: NetworkInterface) extends SocketOption {

  override def afterConnect(c: DatagramChannel): Unit = {
    c.join(group, networkInterface)
  }
}

  IO(Udp) ! Udp.Bind(self, new InetSocketAddress(MulticastListener.port),
    options=List(ReuseAddress(true),
      JoinGroup(MulticastListener.group, MulticastListener.interf)))

Other minor changes:

 - changed all methods in SocketOption to take a Channel instead of a Socket.  The socket can be gotten from the Channel but not the reverse.
 - all methods that are called before the bind are now called beforeBind for consistency.
 - All network connections now call the beforeBind and afterConnect.
This commit is contained in:
Michael R. Maletich 2013-09-08 09:29:45 -05:00
parent cb05725c1e
commit a6d3704ef6
11 changed files with 104 additions and 30 deletions

View file

@ -179,7 +179,7 @@ private[io] abstract class TcpConnection(val tcp: TcpExt, val channel: SocketCha
options: immutable.Traversable[SocketOption]): Unit = {
// Turn off Nagle's algorithm by default
channel.socket.setTcpNoDelay(true)
options.foreach(_.afterConnect(channel.socket))
options.foreach(_.afterConnect(channel))
commander ! Connected(
channel.socket.getRemoteSocketAddress.asInstanceOf[InetSocketAddress],