jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
changeset 8817 5351579c46a9
parent 7668 d4a77089c587
child 9035 1255eb81cc2f
equal deleted inserted replaced
8816:29f983feda95 8817:5351579c46a9
    30 import java.io.OutputStream;
    30 import java.io.OutputStream;
    31 import java.io.FileDescriptor;
    31 import java.io.FileDescriptor;
    32 
    32 
    33 import sun.net.ConnectionResetException;
    33 import sun.net.ConnectionResetException;
    34 import sun.net.NetHooks;
    34 import sun.net.NetHooks;
       
    35 import sun.net.ResourceManager;
    35 
    36 
    36 /**
    37 /**
    37  * Default Socket Implementation. This implementation does
    38  * Default Socket Implementation. This implementation does
    38  * not implement any security checks.
    39  * not implement any security checks.
    39  * Note this class should <b>NOT</b> be public.
    40  * Note this class should <b>NOT</b> be public.
    66     private int CONNECTION_RESET_PENDING = 1;
    67     private int CONNECTION_RESET_PENDING = 1;
    67     private int CONNECTION_RESET = 2;
    68     private int CONNECTION_RESET = 2;
    68     private int resetState;
    69     private int resetState;
    69     private final Object resetLock = new Object();
    70     private final Object resetLock = new Object();
    70 
    71 
       
    72    /* whether this Socket is a stream (TCP) socket or not (UDP)
       
    73     */
       
    74     private boolean stream;
       
    75 
    71     /**
    76     /**
    72      * Load net library into runtime.
    77      * Load net library into runtime.
    73      */
    78      */
    74     static {
    79     static {
    75         java.security.AccessController.doPrivileged(
    80         java.security.AccessController.doPrivileged(
    80      * Creates a socket with a boolean that specifies whether this
    85      * Creates a socket with a boolean that specifies whether this
    81      * is a stream socket (true) or an unconnected UDP socket (false).
    86      * is a stream socket (true) or an unconnected UDP socket (false).
    82      */
    87      */
    83     protected synchronized void create(boolean stream) throws IOException {
    88     protected synchronized void create(boolean stream) throws IOException {
    84         fd = new FileDescriptor();
    89         fd = new FileDescriptor();
    85         socketCreate(stream);
    90         this.stream = stream;
       
    91         if (!stream) {
       
    92             ResourceManager.beforeUdpCreate();
       
    93             try {
       
    94                 socketCreate(false);
       
    95             } catch (IOException ioe) {
       
    96                 ResourceManager.afterUdpClose();
       
    97                 fd = null;
       
    98                 throw ioe;
       
    99             }
       
   100         } else {
       
   101             socketCreate(true);
       
   102         }
    86         if (socket != null)
   103         if (socket != null)
    87             socket.setCreated();
   104             socket.setCreated();
    88         if (serverSocket != null)
   105         if (serverSocket != null)
    89             serverSocket.setCreated();
   106             serverSocket.setCreated();
    90     }
   107     }
   477      * Closes the socket.
   494      * Closes the socket.
   478      */
   495      */
   479     protected void close() throws IOException {
   496     protected void close() throws IOException {
   480         synchronized(fdLock) {
   497         synchronized(fdLock) {
   481             if (fd != null) {
   498             if (fd != null) {
       
   499                 if (!stream) {
       
   500                     ResourceManager.afterUdpClose();
       
   501                 }
   482                 if (fdUseCount == 0) {
   502                 if (fdUseCount == 0) {
   483                     if (closePending) {
   503                     if (closePending) {
   484                         return;
   504                         return;
   485                     }
   505                     }
   486                     closePending = true;
   506                     closePending = true;