< prev index next >

src/share/classes/sun/security/ssl/SSLSocketImpl.java

Print this page




 583      */
 584     private void bruteForceCloseInput(
 585             boolean hasCloseReceipt) throws IOException {
 586         if (hasCloseReceipt) {
 587             // It is not required for the initiator of the close to wait for
 588             // the responding close_notify alert before closing the read side
 589             // of the connection.  However, if the application protocol using
 590             // TLS provides that any data may be carried over the underlying
 591             // transport after the TLS connection is closed, the TLS
 592             // implementation MUST receive a "close_notify" alert before
 593             // indicating end-of-data to the application-layer.
 594             try {
 595                 this.shutdown();
 596             } finally {
 597                 if (!isInputShutdown()) {
 598                     shutdownInput(false);
 599                 }
 600             }
 601         } else {
 602             if (!conContext.isInboundClosed()) {






 603                 conContext.inputRecord.close();
 604             }

 605 
 606             if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
 607                 super.shutdownInput();
 608             }
 609         }
 610     }
 611 
 612     // Please don't synchronized this method.  Otherwise, the read and close
 613     // locks may be deadlocked.
 614     @Override
 615     public void shutdownInput() throws IOException {
 616         shutdownInput(true);
 617     }
 618 
 619     // It is not required to check the close_notify receipt unless an
 620     // application call shutdownInput() explicitly.
 621     private void shutdownInput(
 622             boolean checkCloseNotify) throws IOException {
 623         if (isInputShutdown()) {
 624             return;


 881         /**
 882          * Return whether we have reached end-of-file.
 883          *
 884          * If the socket is not connected, has been shutdown because of an error
 885          * or has been closed, throw an Exception.
 886          */
 887         private boolean checkEOF() throws IOException {
 888             if (conContext.isInboundClosed()) {
 889                 return true;
 890             } else if (conContext.isInputCloseNotified || conContext.isBroken) {
 891                 if (conContext.closeReason == null) {
 892                     return true;
 893                 } else {
 894                     throw new SSLException(
 895                         "Connection has closed: " + conContext.closeReason,
 896                         conContext.closeReason);
 897                 }
 898             }
 899 
 900             return false;
























 901         }
 902     }
 903 
 904     @Override
 905     public synchronized OutputStream getOutputStream() throws IOException {
 906         if (isClosed()) {
 907             throw new SocketException("Socket is closed");
 908         }
 909 
 910         if (!isConnected) {
 911             throw new SocketException("Socket is not connected");
 912         }
 913 
 914         if (conContext.isOutboundDone() || isOutputShutdown()) {
 915             throw new SocketException("Socket output is already shutdown");
 916         }
 917 
 918         return appOutput;
 919     }
 920 




 583      */
 584     private void bruteForceCloseInput(
 585             boolean hasCloseReceipt) throws IOException {
 586         if (hasCloseReceipt) {
 587             // It is not required for the initiator of the close to wait for
 588             // the responding close_notify alert before closing the read side
 589             // of the connection.  However, if the application protocol using
 590             // TLS provides that any data may be carried over the underlying
 591             // transport after the TLS connection is closed, the TLS
 592             // implementation MUST receive a "close_notify" alert before
 593             // indicating end-of-data to the application-layer.
 594             try {
 595                 this.shutdown();
 596             } finally {
 597                 if (!isInputShutdown()) {
 598                     shutdownInput(false);
 599                 }
 600             }
 601         } else {
 602             if (!conContext.isInboundClosed()) {
 603                 try {
 604                     // Try the best to use up the input records and close the
 605                     // socket gracefully, without impact the performance too
 606                     // much.
 607                     appInput.deplete();
 608                 } finally {
 609                     conContext.inputRecord.close();
 610                 }
 611             }
 612 
 613             if ((autoClose || !isLayered()) && !super.isInputShutdown()) {
 614                 super.shutdownInput();
 615             }
 616         }
 617     }
 618 
 619     // Please don't synchronized this method.  Otherwise, the read and close
 620     // locks may be deadlocked.
 621     @Override
 622     public void shutdownInput() throws IOException {
 623         shutdownInput(true);
 624     }
 625 
 626     // It is not required to check the close_notify receipt unless an
 627     // application call shutdownInput() explicitly.
 628     private void shutdownInput(
 629             boolean checkCloseNotify) throws IOException {
 630         if (isInputShutdown()) {
 631             return;


 888         /**
 889          * Return whether we have reached end-of-file.
 890          *
 891          * If the socket is not connected, has been shutdown because of an error
 892          * or has been closed, throw an Exception.
 893          */
 894         private boolean checkEOF() throws IOException {
 895             if (conContext.isInboundClosed()) {
 896                 return true;
 897             } else if (conContext.isInputCloseNotified || conContext.isBroken) {
 898                 if (conContext.closeReason == null) {
 899                     return true;
 900                 } else {
 901                     throw new SSLException(
 902                         "Connection has closed: " + conContext.closeReason,
 903                         conContext.closeReason);
 904                 }
 905             }
 906 
 907             return false;
 908         }
 909 
 910         /**
 911          * Try the best to use up the input records so as to close the
 912          * socket gracefully, without impact the performance too much.
 913          */
 914         private synchronized void deplete() {
 915             if (!conContext.isInboundClosed()) {
 916                 if (!(conContext.inputRecord instanceof SSLSocketInputRecord)) {
 917                     return;
 918                 }
 919 
 920                 SSLSocketInputRecord socketInputRecord =
 921                         (SSLSocketInputRecord)conContext.inputRecord;
 922                 try {
 923                     socketInputRecord.deplete(
 924                         conContext.isNegotiated && (getSoTimeout() > 0));
 925                 } catch (IOException ioe) {
 926                     if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
 927                         SSLLogger.warning(
 928                             "input stream close depletion failed", ioe);
 929                     }
 930                 }
 931             }
 932         }
 933     }
 934 
 935     @Override
 936     public synchronized OutputStream getOutputStream() throws IOException {
 937         if (isClosed()) {
 938             throw new SocketException("Socket is closed");
 939         }
 940 
 941         if (!isConnected) {
 942             throw new SocketException("Socket is not connected");
 943         }
 944 
 945         if (conContext.isOutboundDone() || isOutputShutdown()) {
 946             throw new SocketException("Socket output is already shutdown");
 947         }
 948 
 949         return appOutput;
 950     }
 951 


< prev index next >