16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.ch;
27
28 import java.io.FileDescriptor;
29 import java.io.IOException;
30 import java.net.*;
31 import java.nio.ByteBuffer;
32 import java.nio.channels.*;
33 import java.nio.channels.spi.*;
34 import java.util.*;
35 import sun.net.ResourceManager;
36
37 /**
38 * An implementation of DatagramChannels.
39 */
40
41 class DatagramChannelImpl
42 extends DatagramChannel
43 implements SelChImpl
44 {
45
46 // Used to make native read and write calls
47 private static NativeDispatcher nd = new DatagramDispatcher();
48
49 // Our file descriptor
50 private final FileDescriptor fd;
51
52 // fd value needed for dev/poll. This value will remain valid
53 // even after the value in the file descriptor object has been set to -1
54 private final int fdVal;
55
300 }
301
302 // no special handling
303 return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
304 }
305 }
306
307 private static class DefaultOptionsHolder {
308 static final Set<SocketOption<?>> defaultOptions = defaultOptions();
309
310 private static Set<SocketOption<?>> defaultOptions() {
311 HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(8);
312 set.add(StandardSocketOptions.SO_SNDBUF);
313 set.add(StandardSocketOptions.SO_RCVBUF);
314 set.add(StandardSocketOptions.SO_REUSEADDR);
315 set.add(StandardSocketOptions.SO_BROADCAST);
316 set.add(StandardSocketOptions.IP_TOS);
317 set.add(StandardSocketOptions.IP_MULTICAST_IF);
318 set.add(StandardSocketOptions.IP_MULTICAST_TTL);
319 set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
320 return Collections.unmodifiableSet(set);
321 }
322 }
323
324 @Override
325 public final Set<SocketOption<?>> supportedOptions() {
326 return DefaultOptionsHolder.defaultOptions;
327 }
328
329 private void ensureOpen() throws ClosedChannelException {
330 if (!isOpen())
331 throw new ClosedChannelException();
332 }
333
334 private SocketAddress sender; // Set by receive0 (## ugh)
335
336 public SocketAddress receive(ByteBuffer dst) throws IOException {
337 if (dst.isReadOnly())
338 throw new IllegalArgumentException("Read-only buffer");
339 if (dst == null)
|
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.ch;
27
28 import java.io.FileDescriptor;
29 import java.io.IOException;
30 import java.net.*;
31 import java.nio.ByteBuffer;
32 import java.nio.channels.*;
33 import java.nio.channels.spi.*;
34 import java.util.*;
35 import sun.net.ResourceManager;
36 import sun.net.ExtendedOptionsImpl;
37
38 /**
39 * An implementation of DatagramChannels.
40 */
41
42 class DatagramChannelImpl
43 extends DatagramChannel
44 implements SelChImpl
45 {
46
47 // Used to make native read and write calls
48 private static NativeDispatcher nd = new DatagramDispatcher();
49
50 // Our file descriptor
51 private final FileDescriptor fd;
52
53 // fd value needed for dev/poll. This value will remain valid
54 // even after the value in the file descriptor object has been set to -1
55 private final int fdVal;
56
301 }
302
303 // no special handling
304 return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
305 }
306 }
307
308 private static class DefaultOptionsHolder {
309 static final Set<SocketOption<?>> defaultOptions = defaultOptions();
310
311 private static Set<SocketOption<?>> defaultOptions() {
312 HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(8);
313 set.add(StandardSocketOptions.SO_SNDBUF);
314 set.add(StandardSocketOptions.SO_RCVBUF);
315 set.add(StandardSocketOptions.SO_REUSEADDR);
316 set.add(StandardSocketOptions.SO_BROADCAST);
317 set.add(StandardSocketOptions.IP_TOS);
318 set.add(StandardSocketOptions.IP_MULTICAST_IF);
319 set.add(StandardSocketOptions.IP_MULTICAST_TTL);
320 set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
321 if (ExtendedOptionsImpl.flowSupported()) {
322 set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
323 }
324 return Collections.unmodifiableSet(set);
325 }
326 }
327
328 @Override
329 public final Set<SocketOption<?>> supportedOptions() {
330 return DefaultOptionsHolder.defaultOptions;
331 }
332
333 private void ensureOpen() throws ClosedChannelException {
334 if (!isOpen())
335 throw new ClosedChannelException();
336 }
337
338 private SocketAddress sender; // Set by receive0 (## ugh)
339
340 public SocketAddress receive(ByteBuffer dst) throws IOException {
341 if (dst.isReadOnly())
342 throw new IllegalArgumentException("Read-only buffer");
343 if (dst == null)
|