8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)

Reviewed-by: dfuchs, chegar
This commit is contained in:
Alan Bateman 2019-11-20 08:35:53 +00:00
parent 62d6862485
commit 7e42642939
11 changed files with 494 additions and 146 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,8 @@ import java.nio.channels.IllegalSelectorException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.util.Arrays;
import java.util.function.Consumer;
/**
@ -171,6 +173,20 @@ public abstract class AbstractSelectableChannel
}
}
/**
* Invokes an action for each key.
*
* This method is invoked by DatagramChannelImpl::disconnect.
*/
private void forEach(Consumer<SelectionKey> action) {
synchronized (keyLock) {
SelectionKey[] keys = this.keys;
if (keys != null) {
Arrays.stream(keys).filter(k -> k != null).forEach(action::accept);
}
}
}
/**
* Registers this channel with the given selector, returning a selection key.
*