jdk/src/share/classes/sun/security/ssl/AppOutputStream.java
changeset 12428 e9feb65d37fa
parent 10915 1e20964cebf3
child 14664 e71aa0962e70
equal deleted inserted replaced
12427:116544b5a04c 12428:e9feb65d37fa
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    89         // Always flush at the end of each application level record.
    89         // Always flush at the end of each application level record.
    90         // This lets application synchronize read and write streams
    90         // This lets application synchronize read and write streams
    91         // however they like; if we buffered here, they couldn't.
    91         // however they like; if we buffered here, they couldn't.
    92         try {
    92         try {
    93             do {
    93             do {
       
    94                 boolean holdRecord = false;
    94                 int howmuch;
    95                 int howmuch;
    95                 if (isFirstRecordOfThePayload && c.needToSplitPayload()) {
    96                 if (isFirstRecordOfThePayload && c.needToSplitPayload()) {
    96                     howmuch = Math.min(0x01, r.availableDataBytes());
    97                     howmuch = Math.min(0x01, r.availableDataBytes());
       
    98                      /*
       
    99                       * Nagle's algorithm (TCP_NODELAY) was coming into
       
   100                       * play here when writing short (split) packets.
       
   101                       * Signal to the OutputRecord code to internally
       
   102                       * buffer this small packet until the next outbound
       
   103                       * packet (of any type) is written.
       
   104                       */
       
   105                      if ((len != 1) && (howmuch == 1)) {
       
   106                          holdRecord = true;
       
   107                      }
    97                 } else {
   108                 } else {
    98                     howmuch = Math.min(len, r.availableDataBytes());
   109                     howmuch = Math.min(len, r.availableDataBytes());
    99                 }
   110                 }
   100 
   111 
   101                 if (isFirstRecordOfThePayload && howmuch != 0) {
   112                 if (isFirstRecordOfThePayload && howmuch != 0) {
   106                 if (howmuch > 0) {
   117                 if (howmuch > 0) {
   107                     r.write(b, off, howmuch);
   118                     r.write(b, off, howmuch);
   108                     off += howmuch;
   119                     off += howmuch;
   109                     len -= howmuch;
   120                     len -= howmuch;
   110                 }
   121                 }
   111                 c.writeRecord(r);
   122                 c.writeRecord(r, holdRecord);
   112                 c.checkWrite();
   123                 c.checkWrite();
   113             } while (len > 0);
   124             } while (len > 0);
   114         } catch (Exception e) {
   125         } catch (Exception e) {
   115             // shutdown and rethrow (wrapped) exception as appropriate
   126             // shutdown and rethrow (wrapped) exception as appropriate
   116             c.handleException(e);
   127             c.handleException(e);