Merge pull request #20286 from drewhk/wip-15882-fix-windows-udp-unbind-drewhk
#15882: Fix UDP unbind for Windows
This commit is contained in:
commit
98947cdbcd
2 changed files with 26 additions and 3 deletions
|
|
@ -14,7 +14,7 @@ class UdpConnectedIntegrationSpec extends AkkaSpec("""
|
||||||
akka.actor.serialize-creators = on
|
akka.actor.serialize-creators = on
|
||||||
""") with ImplicitSender {
|
""") with ImplicitSender {
|
||||||
|
|
||||||
val addresses = temporaryServerAddresses(3, udp = true)
|
val addresses = temporaryServerAddresses(5, udp = true)
|
||||||
|
|
||||||
def bindUdp(address: InetSocketAddress, handler: ActorRef): ActorRef = {
|
def bindUdp(address: InetSocketAddress, handler: ActorRef): ActorRef = {
|
||||||
val commander = TestProbe()
|
val commander = TestProbe()
|
||||||
|
|
@ -69,6 +69,27 @@ class UdpConnectedIntegrationSpec extends AkkaSpec("""
|
||||||
expectMsgType[UdpConnected.Received].data should ===(data2)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@ package akka.io
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.nio.channels.SelectionKey._
|
import java.nio.channels.SelectionKey._
|
||||||
|
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
import akka.actor.{ ActorLogging, Actor, ActorRef }
|
import akka.actor.{ Actor, ActorLogging, ActorRef }
|
||||||
import akka.dispatch.{ RequiresMessageQueue, UnboundedMessageQueueSemantics }
|
import akka.dispatch.{ RequiresMessageQueue, UnboundedMessageQueueSemantics }
|
||||||
import akka.util.ByteString
|
import akka.util.{ ByteString, Helpers }
|
||||||
import akka.io.Inet.DatagramChannelCreator
|
import akka.io.Inet.DatagramChannelCreator
|
||||||
import akka.io.SelectionHandler._
|
import akka.io.SelectionHandler._
|
||||||
import akka.io.Udp._
|
import akka.io.Udp._
|
||||||
|
|
@ -74,6 +75,7 @@ private[io] class UdpListener(val udp: UdpExt,
|
||||||
log.debug("Unbinding endpoint [{}]", bind.localAddress)
|
log.debug("Unbinding endpoint [{}]", bind.localAddress)
|
||||||
try {
|
try {
|
||||||
channel.close()
|
channel.close()
|
||||||
|
if (Helpers.isWindows) registration.enableInterest(OP_READ)
|
||||||
sender() ! Unbound
|
sender() ! Unbound
|
||||||
log.debug("Unbound endpoint [{}], stopping listener", bind.localAddress)
|
log.debug("Unbound endpoint [{}], stopping listener", bind.localAddress)
|
||||||
} finally context.stop(self)
|
} finally context.stop(self)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue