jdk/src/share/classes/sun/security/ssl/BaseSSLSocketImpl.java
changeset 14664 e71aa0962e70
parent 14194 971f46db533d
child 23883 9434a0a8208f
equal deleted inserted replaced
14663:49b7de969579 14664:e71aa0962e70
   100     /**
   100     /**
   101      * Returns the unique {@link java.nio.SocketChannel SocketChannel} object
   101      * Returns the unique {@link java.nio.SocketChannel SocketChannel} object
   102      * associated with this socket, if any.
   102      * associated with this socket, if any.
   103      * @see java.net.Socket#getChannel
   103      * @see java.net.Socket#getChannel
   104      */
   104      */
       
   105     @Override
   105     public final SocketChannel getChannel() {
   106     public final SocketChannel getChannel() {
   106         if (self == this) {
   107         if (self == this) {
   107             return super.getChannel();
   108             return super.getChannel();
   108         } else {
   109         } else {
   109             return self.getChannel();
   110             return self.getChannel();
   112 
   113 
   113     /**
   114     /**
   114      * Binds the address to the socket.
   115      * Binds the address to the socket.
   115      * @see java.net.Socket#bind
   116      * @see java.net.Socket#bind
   116      */
   117      */
       
   118     @Override
   117     public void bind(SocketAddress bindpoint) throws IOException {
   119     public void bind(SocketAddress bindpoint) throws IOException {
   118         /*
   120         /*
   119          * Bind to this socket
   121          * Bind to this socket
   120          */
   122          */
   121         if (self == this) {
   123         if (self == this) {
   129 
   131 
   130     /**
   132     /**
   131      * Returns the address of the endpoint this socket is connected to
   133      * Returns the address of the endpoint this socket is connected to
   132      * @see java.net.Socket#getLocalSocketAddress
   134      * @see java.net.Socket#getLocalSocketAddress
   133      */
   135      */
       
   136     @Override
   134     public SocketAddress getLocalSocketAddress() {
   137     public SocketAddress getLocalSocketAddress() {
   135         if (self == this) {
   138         if (self == this) {
   136             return super.getLocalSocketAddress();
   139             return super.getLocalSocketAddress();
   137         } else {
   140         } else {
   138             return self.getLocalSocketAddress();
   141             return self.getLocalSocketAddress();
   141 
   144 
   142     /**
   145     /**
   143      * Returns the address of the endpoint this socket is connected to
   146      * Returns the address of the endpoint this socket is connected to
   144      * @see java.net.Socket#getRemoteSocketAddress
   147      * @see java.net.Socket#getRemoteSocketAddress
   145      */
   148      */
       
   149     @Override
   146     public SocketAddress getRemoteSocketAddress() {
   150     public SocketAddress getRemoteSocketAddress() {
   147         if (self == this) {
   151         if (self == this) {
   148             return super.getRemoteSocketAddress();
   152             return super.getRemoteSocketAddress();
   149         } else {
   153         } else {
   150             return self.getRemoteSocketAddress();
   154             return self.getRemoteSocketAddress();
   162      * us.
   166      * us.
   163      *
   167      *
   164      * @param   endpoint the <code>SocketAddress</code>
   168      * @param   endpoint the <code>SocketAddress</code>
   165      * @throws  IOException if an error occurs during the connection
   169      * @throws  IOException if an error occurs during the connection
   166      */
   170      */
       
   171     @Override
   167     public final void connect(SocketAddress endpoint) throws IOException {
   172     public final void connect(SocketAddress endpoint) throws IOException {
   168         connect(endpoint, 0);
   173         connect(endpoint, 0);
   169     }
   174     }
   170 
   175 
   171     /**
   176     /**
   172      * Returns the connection state of the socket.
   177      * Returns the connection state of the socket.
   173      * @see java.net.Socket#isConnected
   178      * @see java.net.Socket#isConnected
   174      */
   179      */
       
   180     @Override
   175     public final boolean isConnected() {
   181     public final boolean isConnected() {
   176         if (self == this) {
   182         if (self == this) {
   177             return super.isConnected();
   183             return super.isConnected();
   178         } else {
   184         } else {
   179             return self.isConnected();
   185             return self.isConnected();
   182 
   188 
   183     /**
   189     /**
   184      * Returns the binding state of the socket.
   190      * Returns the binding state of the socket.
   185      * @see java.net.Socket#isBound
   191      * @see java.net.Socket#isBound
   186      */
   192      */
       
   193     @Override
   187     public final boolean isBound() {
   194     public final boolean isBound() {
   188         if (self == this) {
   195         if (self == this) {
   189             return super.isBound();
   196             return super.isBound();
   190         } else {
   197         } else {
   191             return self.isBound();
   198             return self.isBound();
   201      * spec. Thus when the method is called on an SSL socket, an
   208      * spec. Thus when the method is called on an SSL socket, an
   202      * UnsupportedOperationException will be thrown.
   209      * UnsupportedOperationException will be thrown.
   203      *
   210      *
   204      * @throws UnsupportedOperationException
   211      * @throws UnsupportedOperationException
   205      */
   212      */
       
   213     @Override
   206     public final void shutdownInput() throws IOException {
   214     public final void shutdownInput() throws IOException {
   207         throw new UnsupportedOperationException("The method shutdownInput()" +
   215         throw new UnsupportedOperationException("The method shutdownInput()" +
   208                    " is not supported in SSLSocket");
   216                    " is not supported in SSLSocket");
   209     }
   217     }
   210 
   218 
   213      * spec. Thus when the method is called on an SSL socket, an
   221      * spec. Thus when the method is called on an SSL socket, an
   214      * UnsupportedOperationException will be thrown.
   222      * UnsupportedOperationException will be thrown.
   215      *
   223      *
   216      * @throws UnsupportedOperationException
   224      * @throws UnsupportedOperationException
   217      */
   225      */
       
   226     @Override
   218     public final void shutdownOutput() throws IOException {
   227     public final void shutdownOutput() throws IOException {
   219         throw new UnsupportedOperationException("The method shutdownOutput()" +
   228         throw new UnsupportedOperationException("The method shutdownOutput()" +
   220                    " is not supported in SSLSocket");
   229                    " is not supported in SSLSocket");
   221 
   230 
   222     }
   231     }
   223 
   232 
   224     /**
   233     /**
   225      * Returns the input state of the socket
   234      * Returns the input state of the socket
   226      * @see java.net.Socket#isInputShutdown
   235      * @see java.net.Socket#isInputShutdown
   227      */
   236      */
       
   237     @Override
   228     public final boolean isInputShutdown() {
   238     public final boolean isInputShutdown() {
   229         if (self == this) {
   239         if (self == this) {
   230             return super.isInputShutdown();
   240             return super.isInputShutdown();
   231         } else {
   241         } else {
   232             return self.isInputShutdown();
   242             return self.isInputShutdown();
   235 
   245 
   236     /**
   246     /**
   237      * Returns the output state of the socket
   247      * Returns the output state of the socket
   238      * @see java.net.Socket#isOutputShutdown
   248      * @see java.net.Socket#isOutputShutdown
   239      */
   249      */
       
   250     @Override
   240     public final boolean isOutputShutdown() {
   251     public final boolean isOutputShutdown() {
   241         if (self == this) {
   252         if (self == this) {
   242             return super.isOutputShutdown();
   253             return super.isOutputShutdown();
   243         } else {
   254         } else {
   244             return self.isOutputShutdown();
   255             return self.isOutputShutdown();
   250      * as possible, in case the application forgets to do so.
   261      * as possible, in case the application forgets to do so.
   251      * This allows SSL connections to be implicitly reclaimed,
   262      * This allows SSL connections to be implicitly reclaimed,
   252      * rather than forcing them to be explicitly reclaimed at
   263      * rather than forcing them to be explicitly reclaimed at
   253      * the penalty of prematurly killing SSL sessions.
   264      * the penalty of prematurly killing SSL sessions.
   254      */
   265      */
       
   266     @Override
   255     protected final void finalize() throws Throwable {
   267     protected final void finalize() throws Throwable {
   256         try {
   268         try {
   257             close();
   269             close();
   258         } catch (IOException e1) {
   270         } catch (IOException e1) {
   259             try {
   271             try {
   279     //
   291     //
   280 
   292 
   281     /**
   293     /**
   282      * Returns the address of the remote peer for this connection.
   294      * Returns the address of the remote peer for this connection.
   283      */
   295      */
       
   296     @Override
   284     public final InetAddress getInetAddress() {
   297     public final InetAddress getInetAddress() {
   285         if (self == this) {
   298         if (self == this) {
   286             return super.getInetAddress();
   299             return super.getInetAddress();
   287         } else {
   300         } else {
   288             return self.getInetAddress();
   301             return self.getInetAddress();
   293      * Gets the local address to which the socket is bound.
   306      * Gets the local address to which the socket is bound.
   294      *
   307      *
   295      * @return the local address to which the socket is bound.
   308      * @return the local address to which the socket is bound.
   296      * @since   JDK1.1
   309      * @since   JDK1.1
   297      */
   310      */
       
   311     @Override
   298     public final InetAddress getLocalAddress() {
   312     public final InetAddress getLocalAddress() {
   299         if (self == this) {
   313         if (self == this) {
   300             return super.getLocalAddress();
   314             return super.getLocalAddress();
   301         } else {
   315         } else {
   302             return self.getLocalAddress();
   316             return self.getLocalAddress();
   304     }
   318     }
   305 
   319 
   306     /**
   320     /**
   307      * Returns the number of the remote port that this connection uses.
   321      * Returns the number of the remote port that this connection uses.
   308      */
   322      */
       
   323     @Override
   309     public final int getPort() {
   324     public final int getPort() {
   310         if (self == this) {
   325         if (self == this) {
   311             return super.getPort();
   326             return super.getPort();
   312         } else {
   327         } else {
   313             return self.getPort();
   328             return self.getPort();
   315     }
   330     }
   316 
   331 
   317     /**
   332     /**
   318      * Returns the number of the local port that this connection uses.
   333      * Returns the number of the local port that this connection uses.
   319      */
   334      */
       
   335     @Override
   320     public final int getLocalPort() {
   336     public final int getLocalPort() {
   321         if (self == this) {
   337         if (self == this) {
   322             return super.getLocalPort();
   338             return super.getLocalPort();
   323         } else {
   339         } else {
   324             return self.getLocalPort();
   340             return self.getLocalPort();
   331 
   347 
   332     /**
   348     /**
   333      * Enables or disables the Nagle optimization.
   349      * Enables or disables the Nagle optimization.
   334      * @see java.net.Socket#setTcpNoDelay
   350      * @see java.net.Socket#setTcpNoDelay
   335      */
   351      */
       
   352     @Override
   336     public final void setTcpNoDelay(boolean value) throws SocketException {
   353     public final void setTcpNoDelay(boolean value) throws SocketException {
   337         if (self == this) {
   354         if (self == this) {
   338             super.setTcpNoDelay(value);
   355             super.setTcpNoDelay(value);
   339         } else {
   356         } else {
   340             self.setTcpNoDelay(value);
   357             self.setTcpNoDelay(value);
   346      * relates to low-level buffering of TCP traffic, delaying the
   363      * relates to low-level buffering of TCP traffic, delaying the
   347      * traffic to promote better throughput.
   364      * traffic to promote better throughput.
   348      *
   365      *
   349      * @see java.net.Socket#getTcpNoDelay
   366      * @see java.net.Socket#getTcpNoDelay
   350      */
   367      */
       
   368     @Override
   351     public final boolean getTcpNoDelay() throws SocketException {
   369     public final boolean getTcpNoDelay() throws SocketException {
   352         if (self == this) {
   370         if (self == this) {
   353             return super.getTcpNoDelay();
   371             return super.getTcpNoDelay();
   354         } else {
   372         } else {
   355             return self.getTcpNoDelay();
   373             return self.getTcpNoDelay();
   358 
   376 
   359     /**
   377     /**
   360      * Assigns the socket's linger timeout.
   378      * Assigns the socket's linger timeout.
   361      * @see java.net.Socket#setSoLinger
   379      * @see java.net.Socket#setSoLinger
   362      */
   380      */
       
   381     @Override
   363     public final void setSoLinger(boolean flag, int linger)
   382     public final void setSoLinger(boolean flag, int linger)
   364             throws SocketException {
   383             throws SocketException {
   365         if (self == this) {
   384         if (self == this) {
   366             super.setSoLinger(flag, linger);
   385             super.setSoLinger(flag, linger);
   367         } else {
   386         } else {
   371 
   390 
   372     /**
   391     /**
   373      * Returns the socket's linger timeout.
   392      * Returns the socket's linger timeout.
   374      * @see java.net.Socket#getSoLinger
   393      * @see java.net.Socket#getSoLinger
   375      */
   394      */
       
   395     @Override
   376     public final int getSoLinger() throws SocketException {
   396     public final int getSoLinger() throws SocketException {
   377         if (self == this) {
   397         if (self == this) {
   378             return super.getSoLinger();
   398             return super.getSoLinger();
   379         } else {
   399         } else {
   380             return self.getSoLinger();
   400             return self.getSoLinger();
   386      * @see java.net.Socket#sendUrgentData
   406      * @see java.net.Socket#sendUrgentData
   387      * At this point, there seems to be no specific requirement to support
   407      * At this point, there seems to be no specific requirement to support
   388      * this for an SSLSocket. An implementation can be provided if a need
   408      * this for an SSLSocket. An implementation can be provided if a need
   389      * arises in future.
   409      * arises in future.
   390      */
   410      */
       
   411     @Override
   391     public final void sendUrgentData(int data) throws SocketException {
   412     public final void sendUrgentData(int data) throws SocketException {
   392         throw new SocketException("This method is not supported "
   413         throw new SocketException("This method is not supported "
   393                         + "by SSLSockets");
   414                         + "by SSLSockets");
   394     }
   415     }
   395 
   416 
   399      * discarded.
   420      * discarded.
   400      * @see java.net.Socket#setOOBInline
   421      * @see java.net.Socket#setOOBInline
   401      * Setting OOBInline does not have any effect on SSLSocket,
   422      * Setting OOBInline does not have any effect on SSLSocket,
   402      * since currently we don't support sending urgent data.
   423      * since currently we don't support sending urgent data.
   403      */
   424      */
       
   425     @Override
   404     public final void setOOBInline(boolean on) throws SocketException {
   426     public final void setOOBInline(boolean on) throws SocketException {
   405         throw new SocketException("This method is ineffective, since"
   427         throw new SocketException("This method is ineffective, since"
   406                 + " sending urgent data is not supported by SSLSockets");
   428                 + " sending urgent data is not supported by SSLSockets");
   407     }
   429     }
   408 
   430 
   409     /**
   431     /**
   410      * Tests if OOBINLINE is enabled.
   432      * Tests if OOBINLINE is enabled.
   411      * @see java.net.Socket#getOOBInline
   433      * @see java.net.Socket#getOOBInline
   412      */
   434      */
       
   435     @Override
   413     public final boolean getOOBInline() throws SocketException {
   436     public final boolean getOOBInline() throws SocketException {
   414         throw new SocketException("This method is ineffective, since"
   437         throw new SocketException("This method is ineffective, since"
   415                 + " sending urgent data is not supported by SSLSockets");
   438                 + " sending urgent data is not supported by SSLSockets");
   416     }
   439     }
   417 
   440 
   418     /**
   441     /**
   419      * Returns the socket timeout.
   442      * Returns the socket timeout.
   420      * @see java.net.Socket#getSoTimeout
   443      * @see java.net.Socket#getSoTimeout
   421      */
   444      */
       
   445     @Override
   422     public final int getSoTimeout() throws SocketException {
   446     public final int getSoTimeout() throws SocketException {
   423         if (self == this) {
   447         if (self == this) {
   424             return super.getSoTimeout();
   448             return super.getSoTimeout();
   425         } else {
   449         } else {
   426             return self.getSoTimeout();
   450             return self.getSoTimeout();
   427         }
   451         }
   428     }
   452     }
   429 
   453 
       
   454     @Override
   430     public final void setSendBufferSize(int size) throws SocketException {
   455     public final void setSendBufferSize(int size) throws SocketException {
   431         if (self == this) {
   456         if (self == this) {
   432             super.setSendBufferSize(size);
   457             super.setSendBufferSize(size);
   433         } else {
   458         } else {
   434             self.setSendBufferSize(size);
   459             self.setSendBufferSize(size);
   435         }
   460         }
   436     }
   461     }
   437 
   462 
       
   463     @Override
   438     public final int getSendBufferSize() throws SocketException {
   464     public final int getSendBufferSize() throws SocketException {
   439         if (self == this) {
   465         if (self == this) {
   440             return super.getSendBufferSize();
   466             return super.getSendBufferSize();
   441         } else {
   467         } else {
   442             return self.getSendBufferSize();
   468             return self.getSendBufferSize();
   443         }
   469         }
   444     }
   470     }
   445 
   471 
       
   472     @Override
   446     public final void setReceiveBufferSize(int size) throws SocketException {
   473     public final void setReceiveBufferSize(int size) throws SocketException {
   447         if (self == this) {
   474         if (self == this) {
   448             super.setReceiveBufferSize(size);
   475             super.setReceiveBufferSize(size);
   449         } else {
   476         } else {
   450             self.setReceiveBufferSize(size);
   477             self.setReceiveBufferSize(size);
   451         }
   478         }
   452     }
   479     }
   453 
   480 
       
   481     @Override
   454     public final int getReceiveBufferSize() throws SocketException {
   482     public final int getReceiveBufferSize() throws SocketException {
   455         if (self == this) {
   483         if (self == this) {
   456             return super.getReceiveBufferSize();
   484             return super.getReceiveBufferSize();
   457         } else {
   485         } else {
   458             return self.getReceiveBufferSize();
   486             return self.getReceiveBufferSize();
   461 
   489 
   462     /**
   490     /**
   463      * Enable/disable SO_KEEPALIVE.
   491      * Enable/disable SO_KEEPALIVE.
   464      * @see java.net.Socket#setKeepAlive
   492      * @see java.net.Socket#setKeepAlive
   465      */
   493      */
       
   494     @Override
   466     public final void setKeepAlive(boolean on) throws SocketException {
   495     public final void setKeepAlive(boolean on) throws SocketException {
   467         if (self == this) {
   496         if (self == this) {
   468             super.setKeepAlive(on);
   497             super.setKeepAlive(on);
   469         } else {
   498         } else {
   470             self.setKeepAlive(on);
   499             self.setKeepAlive(on);
   473 
   502 
   474     /**
   503     /**
   475      * Tests if SO_KEEPALIVE is enabled.
   504      * Tests if SO_KEEPALIVE is enabled.
   476      * @see java.net.Socket#getKeepAlive
   505      * @see java.net.Socket#getKeepAlive
   477      */
   506      */
       
   507     @Override
   478     public final boolean getKeepAlive() throws SocketException {
   508     public final boolean getKeepAlive() throws SocketException {
   479         if (self == this) {
   509         if (self == this) {
   480             return super.getKeepAlive();
   510             return super.getKeepAlive();
   481         } else {
   511         } else {
   482             return self.getKeepAlive();
   512             return self.getKeepAlive();
   486     /**
   516     /**
   487      * Sets traffic class or type-of-service octet in the IP header for
   517      * Sets traffic class or type-of-service octet in the IP header for
   488      * packets sent from this Socket.
   518      * packets sent from this Socket.
   489      * @see java.net.Socket#setTrafficClass
   519      * @see java.net.Socket#setTrafficClass
   490      */
   520      */
       
   521     @Override
   491     public final void setTrafficClass(int tc) throws SocketException {
   522     public final void setTrafficClass(int tc) throws SocketException {
   492         if (self == this) {
   523         if (self == this) {
   493             super.setTrafficClass(tc);
   524             super.setTrafficClass(tc);
   494         } else {
   525         } else {
   495             self.setTrafficClass(tc);
   526             self.setTrafficClass(tc);
   499     /**
   530     /**
   500      * Gets traffic class or type-of-service in the IP header for packets
   531      * Gets traffic class or type-of-service in the IP header for packets
   501      * sent from this Socket.
   532      * sent from this Socket.
   502      * @see java.net.Socket#getTrafficClass
   533      * @see java.net.Socket#getTrafficClass
   503      */
   534      */
       
   535     @Override
   504     public final int getTrafficClass() throws SocketException {
   536     public final int getTrafficClass() throws SocketException {
   505         if (self == this) {
   537         if (self == this) {
   506             return super.getTrafficClass();
   538             return super.getTrafficClass();
   507         } else {
   539         } else {
   508             return self.getTrafficClass();
   540             return self.getTrafficClass();
   511 
   543 
   512     /**
   544     /**
   513      * Enable/disable SO_REUSEADDR.
   545      * Enable/disable SO_REUSEADDR.
   514      * @see java.net.Socket#setReuseAddress
   546      * @see java.net.Socket#setReuseAddress
   515      */
   547      */
       
   548     @Override
   516     public final void setReuseAddress(boolean on) throws SocketException {
   549     public final void setReuseAddress(boolean on) throws SocketException {
   517         if (self == this) {
   550         if (self == this) {
   518             super.setReuseAddress(on);
   551             super.setReuseAddress(on);
   519         } else {
   552         } else {
   520             self.setReuseAddress(on);
   553             self.setReuseAddress(on);
   523 
   556 
   524     /**
   557     /**
   525      * Tests if SO_REUSEADDR is enabled.
   558      * Tests if SO_REUSEADDR is enabled.
   526      * @see java.net.Socket#getReuseAddress
   559      * @see java.net.Socket#getReuseAddress
   527      */
   560      */
       
   561     @Override
   528     public final boolean getReuseAddress() throws SocketException {
   562     public final boolean getReuseAddress() throws SocketException {
   529         if (self == this) {
   563         if (self == this) {
   530             return super.getReuseAddress();
   564             return super.getReuseAddress();
   531         } else {
   565         } else {
   532             return self.getReuseAddress();
   566             return self.getReuseAddress();
   536     /**
   570     /**
   537      * Sets performance preferences for this socket.
   571      * Sets performance preferences for this socket.
   538      *
   572      *
   539      * @see java.net.Socket#setPerformancePreferences(int, int, int)
   573      * @see java.net.Socket#setPerformancePreferences(int, int, int)
   540      */
   574      */
       
   575     @Override
   541     public void setPerformancePreferences(int connectionTime,
   576     public void setPerformancePreferences(int connectionTime,
   542             int latency, int bandwidth) {
   577             int latency, int bandwidth) {
   543         if (self == this) {
   578         if (self == this) {
   544             super.setPerformancePreferences(
   579             super.setPerformancePreferences(
   545                 connectionTime, latency, bandwidth);
   580                 connectionTime, latency, bandwidth);