Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle | 5 // OpenSSL binding for SSLClientSocket. The class layout and general principle |
| 6 // of operation is derived from SSLClientSocketNSS. | 6 // of operation is derived from SSLClientSocketNSS. |
| 7 | 7 |
| 8 #include "net/socket/ssl_client_socket_openssl.h" | 8 #include "net/socket/ssl_client_socket_openssl.h" |
| 9 | 9 |
| 10 #include <openssl/ssl.h> | 10 #include <openssl/ssl.h> |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 DCHECK_GE(send_buffer_->BytesRemaining(), 0); | 1037 DCHECK_GE(send_buffer_->BytesRemaining(), 0); |
| 1038 if (send_buffer_->BytesRemaining() <= 0) | 1038 if (send_buffer_->BytesRemaining() <= 0) |
| 1039 send_buffer_ = NULL; | 1039 send_buffer_ = NULL; |
| 1040 } | 1040 } |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 int SSLClientSocketOpenSSL::BufferRecv(void) { | 1043 int SSLClientSocketOpenSSL::BufferRecv(void) { |
| 1044 if (transport_recv_busy_) | 1044 if (transport_recv_busy_) |
| 1045 return ERR_IO_PENDING; | 1045 return ERR_IO_PENDING; |
| 1046 | 1046 |
| 1047 // Determine how much was requested from |transport_bio_| that was not | |
| 1048 // actually available. | |
| 1049 size_t requested = BIO_ctrl_get_read_request(transport_bio_); | |
| 1050 if (requested == 0) { | |
| 1051 // This is not a perfect match of error codes, as no operation is | |
| 1052 // actually pending. However, returning 0 would be interpreted as | |
| 1053 // a possible sign of EOF, which is also an inappropriate match. | |
| 1054 return ERR_IO_PENDING; | |
| 1055 } | |
|
Ryan Sleevi
2012/12/19 00:23:46
Note that the only time this is called is line 985
| |
| 1056 | |
| 1057 // Known Issue: While only reading |requested| data is the more correct | |
| 1058 // implementation, it has the downside of resulting in frequent reads: | |
|
wtc
2012/12/19 00:51:21
As long as the extra received data is not discarde
| |
| 1059 // One read for the SSL record header (~5 bytes) and one read for the SSL | |
| 1060 // record body. Rather than issuing these reads to the underlying socket | |
| 1061 // (and constantly allocating new IOBuffers), a single Read() request to | |
| 1062 // fill |transport_bio_| is issued. As long as an SSL client socket cannot | |
| 1063 // be gracefully shutdown (via SSL close alerts) and re-used for non-SSL | |
| 1064 // traffic, this over-subscribed Read()ing will not cause issues. | |
|
wtc
2012/12/19 00:51:21
SSLClientSocket does not support this usage. The D
Ryan Sleevi
2012/12/19 00:53:39
Correct. That's why I went this route, but added i
| |
| 1047 size_t max_write = BIO_ctrl_get_write_guarantee(transport_bio_); | 1065 size_t max_write = BIO_ctrl_get_write_guarantee(transport_bio_); |
| 1048 if (max_write > kMaxRecvBufferSize) | 1066 if (max_write > kMaxRecvBufferSize) |
| 1049 max_write = kMaxRecvBufferSize; | 1067 max_write = kMaxRecvBufferSize; |
| 1050 | 1068 |
| 1051 if (!max_write) | 1069 if (!max_write) |
| 1052 return ERR_IO_PENDING; | 1070 return ERR_IO_PENDING; |
| 1053 | 1071 |
| 1054 recv_buffer_ = new IOBuffer(max_write); | 1072 recv_buffer_ = new IOBuffer(max_write); |
| 1055 int rv = transport_->socket()->Read( | 1073 int rv = transport_->socket()->Read( |
| 1056 recv_buffer_, max_write, | 1074 recv_buffer_, max_write, |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, | 1340 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, |
| 1323 user_write_buf_->data()); | 1341 user_write_buf_->data()); |
| 1324 return rv; | 1342 return rv; |
| 1325 } | 1343 } |
| 1326 | 1344 |
| 1327 int err = SSL_get_error(ssl_, rv); | 1345 int err = SSL_get_error(ssl_, rv); |
| 1328 return MapOpenSSLError(err, err_tracer); | 1346 return MapOpenSSLError(err, err_tracer); |
| 1329 } | 1347 } |
| 1330 | 1348 |
| 1331 } // namespace net | 1349 } // namespace net |
| OLD | NEW |