Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(996)

Side by Side Diff: net/socket/ssl_client_socket_impl.cc

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Fix tests for real Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "net/socket/ssl_client_socket_impl.h" 5 #include "net/socket/ssl_client_socket_impl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } else { 870 } else {
871 if (rv > 0) 871 if (rv > 0)
872 was_ever_used_ = true; 872 was_ever_used_ = true;
873 user_read_buf_ = NULL; 873 user_read_buf_ = NULL;
874 user_read_buf_len_ = 0; 874 user_read_buf_len_ = 0;
875 } 875 }
876 876
877 return rv; 877 return rv;
878 } 878 }
879 879
880 int SSLClientSocketImpl::ReadIfReady(IOBuffer* buf,
881 int buf_len,
882 const CompletionCallback& callback) {
883 // Reuse Read() but do not hold on to |buf| and |buf_len|.
884 int rv = Read(buf, buf_len, callback);
885 user_read_buf_ = nullptr;
886 user_read_buf_len_ = 0;
davidben 2017/02/01 22:25:57 Hrm. Rather than let Read() set up some state and
xunjieli 2017/02/03 16:35:33 Done.
887 return rv;
888 }
889
880 int SSLClientSocketImpl::Write(IOBuffer* buf, 890 int SSLClientSocketImpl::Write(IOBuffer* buf,
881 int buf_len, 891 int buf_len,
882 const CompletionCallback& callback) { 892 const CompletionCallback& callback) {
883 user_write_buf_ = buf; 893 user_write_buf_ = buf;
884 user_write_buf_len_ = buf_len; 894 user_write_buf_len_ = buf_len;
885 895
886 int rv = DoPayloadWrite(); 896 int rv = DoPayloadWrite();
887 897
888 if (rv == ERR_IO_PENDING) { 898 if (rv == ERR_IO_PENDING) {
889 user_write_callback_ = callback; 899 user_write_callback_ = callback;
890 } else { 900 } else {
891 if (rv > 0) 901 if (rv > 0)
892 was_ever_used_ = true; 902 was_ever_used_ = true;
893 user_write_buf_ = NULL; 903 user_write_buf_ = NULL;
894 user_write_buf_len_ = 0; 904 user_write_buf_len_ = 0;
895 } 905 }
896 906
897 return rv; 907 return rv;
898 } 908 }
899 909
900 int SSLClientSocketImpl::SetReceiveBufferSize(int32_t size) { 910 int SSLClientSocketImpl::SetReceiveBufferSize(int32_t size) {
901 return transport_->socket()->SetReceiveBufferSize(size); 911 return transport_->socket()->SetReceiveBufferSize(size);
902 } 912 }
903 913
904 int SSLClientSocketImpl::SetSendBufferSize(int32_t size) { 914 int SSLClientSocketImpl::SetSendBufferSize(int32_t size) {
905 return transport_->socket()->SetSendBufferSize(size); 915 return transport_->socket()->SetSendBufferSize(size);
906 } 916 }
907 917
908 void SSLClientSocketImpl::OnReadReady() { 918 void SSLClientSocketImpl::OnReadReady(int rv) {
919 // If ReadIfReady() is called instead of Read().
davidben 2017/02/01 22:25:57 This logic might be better in RetryAllOperations()
xunjieli 2017/02/03 16:35:33 Done. Ah, there's a third case! Should have done a
920 if (!user_read_callback_.is_null() && user_read_buf_ == nullptr) {
921 base::ResetAndReturn(&user_read_callback_).Run(rv);
922 return;
davidben 2017/02/01 22:25:57 This return means we won't wake up other operation
xunjieli 2017/02/03 16:35:33 Acknowledged.
923 }
909 // During a renegotiation, either Read or Write calls may be blocked on a 924 // During a renegotiation, either Read or Write calls may be blocked on a
910 // transport read. 925 // transport read.
911 RetryAllOperations(); 926 RetryAllOperations();
912 } 927 }
913 928
914 void SSLClientSocketImpl::OnWriteReady() { 929 void SSLClientSocketImpl::OnWriteReady(int rv) {
915 // During a renegotiation, either Read or Write calls may be blocked on a 930 // During a renegotiation, either Read or Write calls may be blocked on a
916 // transport read. 931 // transport read.
932 if (!user_read_callback_.is_null() && user_read_buf_ == nullptr) {
933 base::ResetAndReturn(&user_read_callback_).Run(rv);
934 return;
935 }
917 RetryAllOperations(); 936 RetryAllOperations();
918 } 937 }
919 938
920 int SSLClientSocketImpl::Init() { 939 int SSLClientSocketImpl::Init() {
921 DCHECK(!ssl_); 940 DCHECK(!ssl_);
922 941
923 #if defined(USE_NSS_CERTS) 942 #if defined(USE_NSS_CERTS)
924 if (ssl_config_.cert_io_enabled) { 943 if (ssl_config_.cert_io_enabled) {
925 // TODO(davidben): Move this out of SSLClientSocket. See 944 // TODO(davidben): Move this out of SSLClientSocket. See
926 // https://crbug.com/539520. 945 // https://crbug.com/539520.
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && 2059 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED &&
2041 !certificate_requested_) { 2060 !certificate_requested_) {
2042 net_error = ERR_SSL_PROTOCOL_ERROR; 2061 net_error = ERR_SSL_PROTOCOL_ERROR;
2043 } 2062 }
2044 } 2063 }
2045 2064
2046 return net_error; 2065 return net_error;
2047 } 2066 }
2048 2067
2049 } // namespace net 2068 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698