File tree Expand file tree Collapse file tree
junixsocket-common/src/main/java/org/newsclub/net/unix Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,10 +80,8 @@ boolean isSelected() {
8080
8181 @ Override
8282 public void cancel () {
83- if (!cancelled .compareAndSet (false , true ) || !chann .isOpen ()) {
84- return ;
85- }
86- sel .prepareRemove (this );
83+ sel .remove (this );
84+ cancelNoRemove ();
8785 }
8886
8987 void cancelNoRemove () {
Original file line number Diff line number Diff line change @@ -49,7 +49,6 @@ final class AFSelector extends AbstractSelector {
4949
5050 private final Set <SelectionKey > selectedKeysSet = new HashSet <>();
5151 private final Set <SelectionKey > selectedKeysPublic = new UngrowableSet <>(selectedKeysSet );
52- private final Set <SelectionKey > cancelledKeysSet = new HashSet <>();
5352
5453 private PollFd pollFd = null ;
5554
@@ -113,7 +112,6 @@ private int select0(int timeout) throws IOException {
113112 throw new ClosedSelectorException ();
114113 }
115114 pfd = pollFd = initPollFd (pollFd );
116- performRemove ();
117115 selectedKeysSet .clear ();
118116 }
119117 int num ;
@@ -301,23 +299,6 @@ synchronized void remove(AFSelectionKey key) {
301299 pollFd = null ;
302300 }
303301
304- void prepareRemove (AFSelectionKey key ) {
305- synchronized (cancelledKeysSet ) {
306- cancelledKeysSet .add (key );
307- }
308- }
309-
310- void performRemove () {
311- synchronized (cancelledKeysSet ) {
312- for (SelectionKey key : cancelledKeysSet ) {
313- selectedKeysSet .remove (key );
314- deregister ((AFSelectionKey ) key );
315- pollFd = null ;
316- }
317- cancelledKeysSet .clear ();
318- }
319- }
320-
321302 private void deregister (AFSelectionKey key ) {
322303 // super.deregister unnecessarily casts SelectionKey to AbstractSelectionKey, and
323304 // ((AbstractSelectableChannel)key.channel()).removeKey(key); is not visible.
You can’t perform that action at this time.
0 commit comments