< prev index next >

src/share/classes/java/net/DatagramSocket.java

Print this page
rev 1564 : 7090158: Networking Libraries don't build with javac -Werror
7125055: ContentHandler.getContent API changed in error
Summary: Minor changes to networking java files to remove warnings
Reviewed-by: chegar, weijun, hawtin, alanb
Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com
   1 /*
   2  * Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 java.net;
  27 
  28 import java.io.FileDescriptor;
  29 import java.io.IOException;
  30 import java.io.InterruptedIOException;
  31 import java.nio.channels.DatagramChannel;
  32 import java.security.AccessController;
  33 import java.security.PrivilegedExceptionAction;
  34 
  35 /**
  36  * This class represents a socket for sending and receiving datagram packets.
  37  *
  38  * <p>A datagram socket is the sending or receiving point for a packet
  39  * delivery service. Each packet sent or received on a datagram socket
  40  * is individually addressed and routed. Multiple packets sent from
  41  * one machine to another may be routed differently, and may arrive in
  42  * any order.
  43  *
  44  * <p>UDP broadcasts sends are always enabled on a DatagramSocket.
  45  * In order to receive broadcast packets a DatagramSocket
  46  * should be bound to the wildcard address. In some
  47  * implementations, broadcast packets may also be received when
  48  * a DatagramSocket is bound to a more specific address.
  49  * <p>
  50  * Example:


 305     private void checkOldImpl() {
 306         if (impl == null)
 307             return;
 308         // DatagramSocketImpl.peekdata() is a protected method, therefore we need to use
 309         // getDeclaredMethod, therefore we need permission to access the member
 310         try {
 311             AccessController.doPrivileged(
 312                 new PrivilegedExceptionAction<Void>() {
 313                     public Void run() throws NoSuchMethodException {
 314                         Class[] cl = new Class[1];
 315                         cl[0] = DatagramPacket.class;
 316                         impl.getClass().getDeclaredMethod("peekData", cl);
 317                         return null;
 318                     }
 319                 });
 320         } catch (java.security.PrivilegedActionException e) {
 321             oldImpl = true;
 322         }
 323     }
 324 
 325     static Class implClass = null;
 326 
 327     void createImpl() throws SocketException {
 328         if (impl == null) {
 329             if (factory != null) {
 330                 impl = factory.createDatagramSocketImpl();
 331                 checkOldImpl();
 332             } else {
 333                 boolean isMulticast = (this instanceof MulticastSocket) ? true : false;
 334                 impl = DefaultDatagramSocketImplFactory.createDatagramSocketImpl(isMulticast);
 335 
 336                 checkOldImpl();
 337             }
 338         }
 339         // creates a udp socket
 340         impl.create();
 341         created = true;
 342     }
 343 
 344     /**
 345      * Get the <code>DatagramSocketImpl</code> attached to this socket,


   1 /*
   2  * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 java.net;
  27 

  28 import java.io.IOException;

  29 import java.nio.channels.DatagramChannel;
  30 import java.security.AccessController;
  31 import java.security.PrivilegedExceptionAction;
  32 
  33 /**
  34  * This class represents a socket for sending and receiving datagram packets.
  35  *
  36  * <p>A datagram socket is the sending or receiving point for a packet
  37  * delivery service. Each packet sent or received on a datagram socket
  38  * is individually addressed and routed. Multiple packets sent from
  39  * one machine to another may be routed differently, and may arrive in
  40  * any order.
  41  *
  42  * <p>UDP broadcasts sends are always enabled on a DatagramSocket.
  43  * In order to receive broadcast packets a DatagramSocket
  44  * should be bound to the wildcard address. In some
  45  * implementations, broadcast packets may also be received when
  46  * a DatagramSocket is bound to a more specific address.
  47  * <p>
  48  * Example:


 303     private void checkOldImpl() {
 304         if (impl == null)
 305             return;
 306         // DatagramSocketImpl.peekdata() is a protected method, therefore we need to use
 307         // getDeclaredMethod, therefore we need permission to access the member
 308         try {
 309             AccessController.doPrivileged(
 310                 new PrivilegedExceptionAction<Void>() {
 311                     public Void run() throws NoSuchMethodException {
 312                         Class[] cl = new Class[1];
 313                         cl[0] = DatagramPacket.class;
 314                         impl.getClass().getDeclaredMethod("peekData", cl);
 315                         return null;
 316                     }
 317                 });
 318         } catch (java.security.PrivilegedActionException e) {
 319             oldImpl = true;
 320         }
 321     }
 322 
 323     static Class<?> implClass = null;
 324 
 325     void createImpl() throws SocketException {
 326         if (impl == null) {
 327             if (factory != null) {
 328                 impl = factory.createDatagramSocketImpl();
 329                 checkOldImpl();
 330             } else {
 331                 boolean isMulticast = (this instanceof MulticastSocket) ? true : false;
 332                 impl = DefaultDatagramSocketImplFactory.createDatagramSocketImpl(isMulticast);
 333 
 334                 checkOldImpl();
 335             }
 336         }
 337         // creates a udp socket
 338         impl.create();
 339         created = true;
 340     }
 341 
 342     /**
 343      * Get the <code>DatagramSocketImpl</code> attached to this socket,


< prev index next >