src/java.base/share/classes/java/net/DatagramPacket.java
branchdatagramsocketimpl-branch
changeset 58688 2b1e684c3ce6
parent 58679 9c3209ff7550
equal deleted inserted replaced
58680:7e9e2f10a050 58688:2b1e684c3ce6
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package java.net;
    26 package java.net;
    27 
    27 
       
    28 import jdk.internal.access.JavaNetDatagramPacketAccess;
       
    29 import jdk.internal.access.SharedSecrets;
       
    30 
    28 /**
    31 /**
    29  * This class represents a datagram packet.
    32  * This class represents a datagram packet.
    30  * <p>
    33  * <p>
    31  * Datagram packets are used to implement a connectionless packet
    34  * Datagram packets are used to implement a connectionless packet
    32  * delivery service. Each message is routed from one machine to
    35  * delivery service. Each message is routed from one machine to
   365      * @see #setData
   368      * @see #setData
   366      *
   369      *
   367      * @since 1.1
   370      * @since 1.1
   368      */
   371      */
   369     public synchronized void setLength(int length) {
   372     public synchronized void setLength(int length) {
       
   373         setLengthField(length);
       
   374         this.bufLength = this.length;
       
   375     }
       
   376 
       
   377     private synchronized void setLengthField(int length) {
   370         if ((length + offset) > buf.length || length < 0 ||
   378         if ((length + offset) > buf.length || length < 0 ||
   371             (length + offset) < 0) {
   379                 (length + offset) < 0) {
   372             throw new IllegalArgumentException("illegal length");
   380             throw new IllegalArgumentException("illegal length");
   373         }
   381         }
   374         this.length = length;
   382         this.length = length;
   375         this.bufLength = this.length;
   383     }
       
   384 
       
   385     private synchronized int getBufLength() {
       
   386         return bufLength;
       
   387     }
       
   388 
       
   389     static {
       
   390         SharedSecrets.setJavaNetDatagrtamPacketAccess(
       
   391             new JavaNetDatagramPacketAccess() {
       
   392                 @Override
       
   393                 public int getBufLengthField(DatagramPacket packet) {
       
   394                     return packet.getBufLength();
       
   395                 }
       
   396 
       
   397                 @Override
       
   398                 public void setLengthField(DatagramPacket packet, int length) {
       
   399                     packet.setLengthField(length);
       
   400                 }
       
   401             }
       
   402         );
   376     }
   403     }
   377 
   404 
   378     /**
   405     /**
   379      * Perform class load-time initializations.
   406      * Perform class load-time initializations.
   380      */
   407      */