@@ -56,11 +56,6 @@ final class NetMulticastSocket extends MulticastSocket {
56
56
*/
57
57
private final DatagramSocketImpl impl ;
58
58
59
- /**
60
- * Are we using an older DatagramSocketImpl?
61
- */
62
- private final boolean oldImpl ;
63
-
64
59
/**
65
60
* Set when a socket is ST_CONNECTED until we are certain
66
61
* that any packets which might have been received prior
@@ -76,11 +71,9 @@ final class NetMulticastSocket extends MulticastSocket {
76
71
* Connection state:
77
72
* ST_NOT_CONNECTED = socket not connected
78
73
* ST_CONNECTED = socket connected
79
- * ST_CONNECTED_NO_IMPL = socket connected but not at impl level
80
74
*/
81
75
static final int ST_NOT_CONNECTED = 0 ;
82
76
static final int ST_CONNECTED = 1 ;
83
- static final int ST_CONNECTED_NO_IMPL = 2 ;
84
77
85
78
int connectState = ST_NOT_CONNECTED ;
86
79
@@ -97,7 +90,6 @@ final class NetMulticastSocket extends MulticastSocket {
97
90
NetMulticastSocket (DatagramSocketImpl impl ) {
98
91
super ((MulticastSocket ) null );
99
92
this .impl = Objects .requireNonNull (impl );
100
- this .oldImpl = checkOldImpl (impl );
101
93
}
102
94
103
95
/**
@@ -135,59 +127,24 @@ private synchronized void connectInternal(InetAddress address, int port) throws
135
127
if (!isBound ())
136
128
bind (new InetSocketAddress (0 ));
137
129
138
- // old impls do not support connect/disconnect
139
- if (oldImpl ) {
140
- connectState = ST_CONNECTED_NO_IMPL ;
141
- } else {
142
- try {
143
- getImpl ().connect (address , port );
144
-
145
- // socket is now connected by the impl
146
- connectState = ST_CONNECTED ;
147
- // Do we need to filter some packets?
148
- int avail = getImpl ().dataAvailable ();
149
- if (avail == -1 ) {
150
- throw new SocketException ();
151
- }
152
- explicitFilter = avail > 0 ;
153
- if (explicitFilter ) {
154
- bytesLeftToFilter = getReceiveBufferSize ();
155
- }
156
- } catch (SocketException se ) {
130
+ getImpl ().connect (address , port );
157
131
158
- // connection will be emulated by DatagramSocket
159
- connectState = ST_CONNECTED_NO_IMPL ;
160
- }
132
+ // socket is now connected by the impl
133
+ connectState = ST_CONNECTED ;
134
+ // Do we need to filter some packets?
135
+ int avail = getImpl ().dataAvailable ();
136
+ if (avail == -1 ) {
137
+ throw new SocketException ();
138
+ }
139
+ explicitFilter = avail > 0 ;
140
+ if (explicitFilter ) {
141
+ bytesLeftToFilter = getReceiveBufferSize ();
161
142
}
162
143
163
144
connectedAddress = address ;
164
145
connectedPort = port ;
165
146
}
166
147
167
- /**
168
- * Return true if the given DatagramSocketImpl is an "old" impl. An old impl
169
- * is one that doesn't implement the abstract methods added in Java SE 1.4.
170
- */
171
- @ SuppressWarnings ("removal" )
172
- private static boolean checkOldImpl (DatagramSocketImpl impl ) {
173
- // DatagramSocketImpl.peekData() is a protected method, therefore we need to use
174
- // getDeclaredMethod, therefore we need permission to access the member
175
- try {
176
- AccessController .doPrivileged (
177
- new PrivilegedExceptionAction <>() {
178
- public Void run () throws NoSuchMethodException {
179
- Class <?>[] cl = new Class <?>[1 ];
180
- cl [0 ] = DatagramPacket .class ;
181
- impl .getClass ().getDeclaredMethod ("peekData" , cl );
182
- return null ;
183
- }
184
- });
185
- return false ;
186
- } catch (java .security .PrivilegedActionException e ) {
187
- return true ;
188
- }
189
- }
190
-
191
148
/**
192
149
* Return the {@code DatagramSocketImpl} attached to this socket,
193
150
* creating the socket if not already created.
@@ -382,19 +339,11 @@ public synchronized void receive(DatagramPacket p) throws IOException {
382
339
SecurityManager security = System .getSecurityManager ();
383
340
if (security != null ) {
384
341
while (true ) {
385
- String peekAd = null ;
386
342
int peekPort = 0 ;
387
343
// peek at the packet to see who it is from.
388
- if (!oldImpl ) {
389
- // We can use the new peekData() API
390
- DatagramPacket peekPacket = new DatagramPacket (new byte [1 ], 1 );
391
- peekPort = getImpl ().peekData (peekPacket );
392
- peekAd = peekPacket .getAddress ().getHostAddress ();
393
- } else {
394
- InetAddress adr = new InetAddress ();
395
- peekPort = getImpl ().peek (adr );
396
- peekAd = adr .getHostAddress ();
397
- }
344
+ DatagramPacket peekPacket = new DatagramPacket (new byte [1 ], 1 );
345
+ peekPort = getImpl ().peekData (peekPacket );
346
+ String peekAd = peekPacket .getAddress ().getHostAddress ();
398
347
try {
399
348
security .checkAccept (peekAd , peekPort );
400
349
// security check succeeded - so now break
@@ -418,29 +367,19 @@ public synchronized void receive(DatagramPacket p) throws IOException {
418
367
}
419
368
}
420
369
DatagramPacket tmp = null ;
421
- if (( connectState == ST_CONNECTED_NO_IMPL ) || explicitFilter ) {
370
+ if (explicitFilter ) {
422
371
// We have to do the filtering the old fashioned way since
423
372
// the native impl doesn't support connect or the connect
424
373
// via the impl failed, or .. "explicitFilter" may be set when
425
374
// a socket is connected via the impl, for a period of time
426
375
// when packets from other sources might be queued on socket.
427
376
boolean stop = false ;
428
377
while (!stop ) {
429
- InetAddress peekAddress = null ;
430
- int peekPort = -1 ;
431
378
// peek at the packet to see who it is from.
432
- if (!oldImpl ) {
433
- // We can use the new peekData() API
434
- DatagramPacket peekPacket = new DatagramPacket (new byte [1 ], 1 );
435
- peekPort = getImpl ().peekData (peekPacket );
436
- peekAddress = peekPacket .getAddress ();
437
- } else {
438
- // this api only works for IPv4
439
- peekAddress = new InetAddress ();
440
- peekPort = getImpl ().peek (peekAddress );
441
- }
442
- if ((!connectedAddress .equals (peekAddress )) ||
443
- (connectedPort != peekPort )) {
379
+ DatagramPacket peekPacket = new DatagramPacket (new byte [1 ], 1 );
380
+ int peekPort = getImpl ().peekData (peekPacket );
381
+ InetAddress peekAddress = peekPacket .getAddress ();
382
+ if ((!connectedAddress .equals (peekAddress )) || (connectedPort != peekPort )) {
444
383
// throw the packet away and silently continue
445
384
tmp = new DatagramPacket (
446
385
new byte [1024 ], 1024 );
@@ -578,11 +517,7 @@ public synchronized int getReceiveBufferSize() throws SocketException {
578
517
public synchronized void setReuseAddress (boolean on ) throws SocketException {
579
518
if (isClosed ())
580
519
throw new SocketException ("Socket is closed" );
581
- // Integer instead of Boolean for compatibility with older DatagramSocketImpl
582
- if (oldImpl )
583
- getImpl ().setOption (SocketOptions .SO_REUSEADDR , on ? -1 : 0 );
584
- else
585
- getImpl ().setOption (SocketOptions .SO_REUSEADDR , Boolean .valueOf (on ));
520
+ getImpl ().setOption (SocketOptions .SO_REUSEADDR , Boolean .valueOf (on ));
586
521
}
587
522
588
523
@ Override
@@ -809,9 +744,6 @@ public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
809
744
if (!(mcastaddr instanceof InetSocketAddress addr ))
810
745
throw new IllegalArgumentException ("Unsupported address type" );
811
746
812
- if (oldImpl )
813
- throw new UnsupportedOperationException ();
814
-
815
747
checkAddress (addr .getAddress (), "joinGroup" );
816
748
@ SuppressWarnings ("removal" )
817
749
SecurityManager security = System .getSecurityManager ();
@@ -835,9 +767,6 @@ public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
835
767
if (!(mcastaddr instanceof InetSocketAddress addr ))
836
768
throw new IllegalArgumentException ("Unsupported address type" );
837
769
838
- if (oldImpl )
839
- throw new UnsupportedOperationException ();
840
-
841
770
checkAddress (addr .getAddress (), "leaveGroup" );
842
771
@ SuppressWarnings ("removal" )
843
772
SecurityManager security = System .getSecurityManager ();
0 commit comments