Merge pull request #20286 from drewhk/wip-15882-fix-windows-udp-unbind-drewhk

#15882: Fix UDP unbind for Windows
This commit is contained in:
drewhk 2016-04-11 16:05:42 +02:00
commit 98947cdbcd
2 changed files with 26 additions and 3 deletions

View file

@ -14,7 +14,7 @@ class UdpConnectedIntegrationSpec extends AkkaSpec("""
akka.actor.serialize-creators = on
""") with ImplicitSender {
val addresses = temporaryServerAddresses(3, udp = true)
val addresses = temporaryServerAddresses(5, udp = true)
def bindUdp(address: InetSocketAddress, handler: ActorRef): ActorRef = {
val commander = TestProbe()
@ -69,6 +69,27 @@ class UdpConnectedIntegrationSpec extends AkkaSpec("""
expectMsgType[UdpConnected.Received].data should ===(data2)
}
"be able to unbind and bind again successfully" in {
val serverAddress = addresses(3)
val clientAddress = addresses(4)
val server1 = bindUdp(serverAddress, testActor)
val data1 = ByteString("test")
val client = connectUdp(Some(clientAddress), serverAddress, testActor)
client ! UdpConnected.Send(data1)
expectMsgType[Udp.Received].data should ===(data1)
server1 ! Udp.Unbind
expectMsg(Udp.Unbound)
// Reusing the address
val server2 = bindUdp(serverAddress, testActor)
client ! UdpConnected.Send(data1)
expectMsgType[Udp.Received].data should ===(data1)
}
}
}

View file

@ -6,11 +6,12 @@ package akka.io
import java.net.InetSocketAddress
import java.nio.ByteBuffer
import java.nio.channels.SelectionKey._
import scala.annotation.tailrec
import scala.util.control.NonFatal
import akka.actor.{ ActorLogging, Actor, ActorRef }
import akka.actor.{ Actor, ActorLogging, ActorRef }
import akka.dispatch.{ RequiresMessageQueue, UnboundedMessageQueueSemantics }
import akka.util.ByteString
import akka.util.{ ByteString, Helpers }
import akka.io.Inet.DatagramChannelCreator
import akka.io.SelectionHandler._
import akka.io.Udp._
@ -74,6 +75,7 @@ private[io] class UdpListener(val udp: UdpExt,
log.debug("Unbinding endpoint [{}]", bind.localAddress)
try {
channel.close()
if (Helpers.isWindows) registration.enableInterest(OP_READ)
sender() ! Unbound
log.debug("Unbound endpoint [{}], stopping listener", bind.localAddress)
} finally context.stop(self)