diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 18:57:40 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 18:57:40 +0000 |
commit | f308683a147c096c4d4536e995ea906169af2040 (patch) | |
tree | 75c7e0783bc84ed257d465779dfeac21021b469c /net/tools | |
parent | 58bb1b8ba0f99a2973f55a8c91241d7d6d3f9f87 (diff) | |
download | chromium_src-f308683a147c096c4d4536e995ea906169af2040.zip chromium_src-f308683a147c096c4d4536e995ea906169af2040.tar.gz chromium_src-f308683a147c096c4d4536e995ea906169af2040.tar.bz2 |
Don't use large SSL_Write() calls, as they lead to large SSL records
which can span multiple packets. Since the entire SSL record must be
received before any of it can be handed up to the app, this delays
the time at which the client can start processing the data.
BUG=none
TEST=self
Review URL: http://codereview.chromium.org/5941002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r-- | net/tools/flip_server/flip_in_mem_edsm_server.cc | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/net/tools/flip_server/flip_in_mem_edsm_server.cc b/net/tools/flip_server/flip_in_mem_edsm_server.cc index 4faa6d4..1969e0c 100644 --- a/net/tools/flip_server/flip_in_mem_edsm_server.cc +++ b/net/tools/flip_server/flip_in_mem_edsm_server.cc @@ -953,24 +953,40 @@ class SMConnection: public SMConnectionInterface, } } - int Send(const char* bytes, int len, int flags) { + int Send(const char* data, int len, int flags) { ssize_t bytes_written = 0; if (ssl_) { - bytes_written = SSL_write(ssl_, bytes, len); - if (bytes_written < 0) { - switch(SSL_get_error(ssl_, bytes_written)) { - case SSL_ERROR_WANT_READ: - case SSL_ERROR_WANT_WRITE: - case SSL_ERROR_WANT_ACCEPT: - case SSL_ERROR_WANT_CONNECT: - return -2; - default: - PrintSslError(); - break; + // Write smallish chunks to SSL so that we don't have large + // multi-packet TLS records to receive before being able to handle + // the data. + while(len > 0) { + const int kMaxTLSRecordSize = 1460; + const char* ptr = &(data[bytes_written]); + int chunksize = std::min(len, kMaxTLSRecordSize); + int rv = SSL_write(ssl_, ptr, chunksize); + if (rv <= 0) { + switch(SSL_get_error(ssl_, rv)) { + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_ACCEPT: + case SSL_ERROR_WANT_CONNECT: + rv = -2; + break; + default: + PrintSslError(); + break; + } + // If we wrote some data, return that count. Otherwise + // return the stall error. + return bytes_written > 0 ? bytes_written : rv; } + bytes_written += rv; + len -= rv; + if (rv != chunksize) + break; // If we couldn't write everything, we're implicitly stalled } } else { - bytes_written = send(fd_, bytes, len, flags); + bytes_written = send(fd_, data, len, flags); } return bytes_written; } |