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

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

Issue 11366155: SSLClientSocket::IsConnected should care for internal buffers (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Split _win fix to another CL Created 7 years, 11 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 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived 5 // This file includes code SSLClientSocketNSS::DoVerifyCertComplete() derived
6 // from AuthCertificateCallback() in 6 // from AuthCertificateCallback() in
7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp. 7 // mozilla/security/manager/ssl/src/nsNSSCallbacks.cpp.
8 8
9 /* ***** BEGIN LICENSE BLOCK ***** 9 /* ***** BEGIN LICENSE BLOCK *****
10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 10 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // any time. 630 // any time.
631 const HandshakeState& state() const { return network_handshake_state_; } 631 const HandshakeState& state() const { return network_handshake_state_; }
632 632
633 // Called on the network task runner. 633 // Called on the network task runner.
634 // Read() and Write() mirror the net::Socket functions of the same name. 634 // Read() and Write() mirror the net::Socket functions of the same name.
635 // If ERR_IO_PENDING is returned, |callback| will be invoked on the network 635 // If ERR_IO_PENDING is returned, |callback| will be invoked on the network
636 // task runner at a later point, unless the caller calls Detach(). 636 // task runner at a later point, unless the caller calls Detach().
637 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); 637 int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
638 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); 638 int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
639 639
640 // Called on the network task runner.
641 bool HasPendingAsyncOperation();
642 bool HasUnhandledData();
wtc 2013/01/14 20:50:08 It may be good to stress that this is unhandled re
Takashi Toyoshima 2013/01/15 13:46:03 Done.
643
640 private: 644 private:
641 friend class base::RefCountedThreadSafe<Core>; 645 friend class base::RefCountedThreadSafe<Core>;
642 ~Core(); 646 ~Core();
643 647
644 enum State { 648 enum State {
645 STATE_NONE, 649 STATE_NONE,
646 STATE_HANDSHAKE, 650 STATE_HANDSHAKE,
647 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, 651 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE,
648 }; 652 };
649 653
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 bool DoTransportIO(); 732 bool DoTransportIO();
729 int BufferRecv(); 733 int BufferRecv();
730 int BufferSend(); 734 int BufferSend();
731 735
732 void OnRecvComplete(int result); 736 void OnRecvComplete(int result);
733 void OnSendComplete(int result); 737 void OnSendComplete(int result);
734 738
735 void DoConnectCallback(int result); 739 void DoConnectCallback(int result);
736 void DoReadCallback(int result); 740 void DoReadCallback(int result);
737 void DoWriteCallback(int result); 741 void DoWriteCallback(int result);
742 void UpdateNSSStatus(int amount_in_read_buffer,
743 bool operation_is_read,
744 const base::Closure& callback);
738 745
739 // Client channel ID handler. 746 // Client channel ID handler.
740 static SECStatus ClientChannelIDHandler( 747 static SECStatus ClientChannelIDHandler(
741 void* arg, 748 void* arg,
742 PRFileDesc* socket, 749 PRFileDesc* socket,
743 SECKEYPublicKey **out_public_key, 750 SECKEYPublicKey **out_public_key,
744 SECKEYPrivateKey **out_private_key); 751 SECKEYPrivateKey **out_private_key);
745 752
746 // ImportChannelIDKeys is a helper function for turning a DER-encoded cert and 753 // ImportChannelIDKeys is a helper function for turning a DER-encoded cert and
747 // key into a SECKEYPublicKey and SECKEYPrivateKey. Returns OK upon success 754 // key into a SECKEYPublicKey and SECKEYPrivateKey. Returns OK upon success
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 // Uses PostOrRunCallback and |weak_net_log_| to try and log a 794 // Uses PostOrRunCallback and |weak_net_log_| to try and log a
788 // SSL_CLIENT_CERT_PROVIDED event, with the indicated count. 795 // SSL_CLIENT_CERT_PROVIDED event, with the indicated count.
789 void AddCertProvidedEvent(int cert_count); 796 void AddCertProvidedEvent(int cert_count);
790 797
791 // Sets the handshake state |channel_id_sent| flag and logs the 798 // Sets the handshake state |channel_id_sent| flag and logs the
792 // SSL_CHANNEL_ID_PROVIDED event. 799 // SSL_CHANNEL_ID_PROVIDED event.
793 void SetChannelIDProvided(); 800 void SetChannelIDProvided();
794 801
795 //////////////////////////////////////////////////////////////////////////// 802 ////////////////////////////////////////////////////////////////////////////
796 // Members that are ONLY accessed on the network task runner: 803 // Members that are ONLY accessed on the network task runner:
797 //////////////////////////////////////////////////////////////////////////// 804 ////////////////////////////////////////////////////////////////////////////
Takashi Toyoshima 2013/01/15 13:46:03 From line 802 to 804. This comment declares that f
798 805
799 // True if the owning SSLClientSocketNSS has called Detach(). No further 806 // True if the owning SSLClientSocketNSS has called Detach(). No further
800 // callbacks will be invoked nor access to members owned by the network 807 // callbacks will be invoked nor access to members owned by the network
801 // task runner. 808 // task runner.
802 bool detached_; 809 bool detached_;
803 810
804 // The underlying transport to use for network IO. 811 // The underlying transport to use for network IO.
805 ClientSocketHandle* transport_; 812 ClientSocketHandle* transport_;
806 base::WeakPtrFactory<BoundNetLog> weak_net_log_factory_; 813 base::WeakPtrFactory<BoundNetLog> weak_net_log_factory_;
807 814
808 // The current handshake state. Mirrors |nss_handshake_state_|. 815 // The current handshake state. Mirrors |nss_handshake_state_|.
809 HandshakeState network_handshake_state_; 816 HandshakeState network_handshake_state_;
810 817
811 // The service for retrieving Channel ID keys. May be NULL. 818 // The service for retrieving Channel ID keys. May be NULL.
812 ServerBoundCertService* server_bound_cert_service_; 819 ServerBoundCertService* server_bound_cert_service_;
813 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; 820 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_;
814 821
822 // The information about NSS task runner status.
wtc 2013/01/14 20:50:08 Nit: I think "status" can be removed from this com
Takashi Toyoshima 2013/01/15 13:46:03 OK, I remove the last "status". We have a comment
823 int unhandled_buffer_size_;
824 bool waiting_read_;
825 bool waiting_write_;
wtc 2013/01/14 20:50:08 It may be a good idea to name these members nss_wa
Takashi Toyoshima 2013/01/15 13:46:03 Done.
826
815 //////////////////////////////////////////////////////////////////////////// 827 ////////////////////////////////////////////////////////////////////////////
816 // Members that are ONLY accessed on the NSS task runner: 828 // Members that are ONLY accessed on the NSS task runner:
817 //////////////////////////////////////////////////////////////////////////// 829 ////////////////////////////////////////////////////////////////////////////
818 HostPortPair host_and_port_; 830 HostPortPair host_and_port_;
819 SSLConfig ssl_config_; 831 SSLConfig ssl_config_;
820 832
821 // NSS SSL socket. 833 // NSS SSL socket.
822 PRFileDesc* nss_fd_; 834 PRFileDesc* nss_fd_;
823 835
824 // Buffers for the network end of the SSL state machine 836 // Buffers for the network end of the SSL state machine
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 ClientSocketHandle* transport, 897 ClientSocketHandle* transport,
886 const HostPortPair& host_and_port, 898 const HostPortPair& host_and_port,
887 const SSLConfig& ssl_config, 899 const SSLConfig& ssl_config,
888 BoundNetLog* net_log, 900 BoundNetLog* net_log,
889 ServerBoundCertService* server_bound_cert_service) 901 ServerBoundCertService* server_bound_cert_service)
890 : detached_(false), 902 : detached_(false),
891 transport_(transport), 903 transport_(transport),
892 weak_net_log_factory_(net_log), 904 weak_net_log_factory_(net_log),
893 server_bound_cert_service_(server_bound_cert_service), 905 server_bound_cert_service_(server_bound_cert_service),
894 domain_bound_cert_request_handle_(NULL), 906 domain_bound_cert_request_handle_(NULL),
907 unhandled_buffer_size_(0),
908 waiting_read_(false),
909 waiting_write_(false),
895 host_and_port_(host_and_port), 910 host_and_port_(host_and_port),
896 ssl_config_(ssl_config), 911 ssl_config_(ssl_config),
897 nss_fd_(NULL), 912 nss_fd_(NULL),
898 nss_bufs_(NULL), 913 nss_bufs_(NULL),
899 next_handshake_state_(STATE_NONE), 914 next_handshake_state_(STATE_NONE),
900 channel_id_xtn_negotiated_(false), 915 channel_id_xtn_negotiated_(false),
901 channel_id_needed_(false), 916 channel_id_needed_(false),
902 client_auth_cert_needed_(false), 917 client_auth_cert_needed_(false),
903 handshake_callback_called_(false), 918 handshake_callback_called_(false),
904 transport_recv_busy_(false), 919 transport_recv_busy_(false),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 return posted ? ERR_IO_PENDING : ERR_ABORTED; 1112 return posted ? ERR_IO_PENDING : ERR_ABORTED;
1098 } 1113 }
1099 1114
1100 DCHECK(OnNSSTaskRunner()); 1115 DCHECK(OnNSSTaskRunner());
1101 DCHECK(handshake_callback_called_); 1116 DCHECK(handshake_callback_called_);
1102 DCHECK_EQ(STATE_NONE, next_handshake_state_); 1117 DCHECK_EQ(STATE_NONE, next_handshake_state_);
1103 DCHECK(user_read_callback_.is_null()); 1118 DCHECK(user_read_callback_.is_null());
1104 DCHECK(user_connect_callback_.is_null()); 1119 DCHECK(user_connect_callback_.is_null());
1105 DCHECK(!user_read_buf_); 1120 DCHECK(!user_read_buf_);
1106 DCHECK(nss_bufs_); 1121 DCHECK(nss_bufs_);
1122 DCHECK(!waiting_read_);
1107 1123
1108 user_read_buf_ = buf; 1124 user_read_buf_ = buf;
1109 user_read_buf_len_ = buf_len; 1125 user_read_buf_len_ = buf_len;
1126 waiting_read_ = true;
1110 1127
1111 int rv = DoReadLoop(OK); 1128 int rv = DoReadLoop(OK);
1112 if (rv == ERR_IO_PENDING) { 1129 if (rv == ERR_IO_PENDING) {
1113 user_read_callback_ = callback; 1130 user_read_callback_ = callback;
wtc 2013/01/14 20:50:08 It may be clearer to first set waiting_read_ to fa
Takashi Toyoshima 2013/01/15 13:46:03 Done.
1114 } else { 1131 } else {
1115 user_read_buf_ = NULL; 1132 user_read_buf_ = NULL;
1116 user_read_buf_len_ = 0; 1133 user_read_buf_len_ = 0;
1134 waiting_read_ = false;
1117 1135
1118 if (!OnNetworkTaskRunner()) { 1136 if (!OnNetworkTaskRunner()) {
1119 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); 1137 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv));
1120 return ERR_IO_PENDING; 1138 return ERR_IO_PENDING;
1121 } 1139 }
1122 } 1140 }
1123 1141
1124 return rv; 1142 return rv;
1125 } 1143 }
1126 1144
(...skipping 12 matching lines...) Expand all
1139 return rv; 1157 return rv;
1140 } 1158 }
1141 1159
1142 DCHECK(OnNSSTaskRunner()); 1160 DCHECK(OnNSSTaskRunner());
1143 DCHECK(handshake_callback_called_); 1161 DCHECK(handshake_callback_called_);
1144 DCHECK_EQ(STATE_NONE, next_handshake_state_); 1162 DCHECK_EQ(STATE_NONE, next_handshake_state_);
1145 DCHECK(user_write_callback_.is_null()); 1163 DCHECK(user_write_callback_.is_null());
1146 DCHECK(user_connect_callback_.is_null()); 1164 DCHECK(user_connect_callback_.is_null());
1147 DCHECK(!user_write_buf_); 1165 DCHECK(!user_write_buf_);
1148 DCHECK(nss_bufs_); 1166 DCHECK(nss_bufs_);
1167 DCHECK(!waiting_write_);
1149 1168
1150 user_write_buf_ = buf; 1169 user_write_buf_ = buf;
1151 user_write_buf_len_ = buf_len; 1170 user_write_buf_len_ = buf_len;
1171 waiting_write_ = true;
1152 1172
1153 int rv = DoWriteLoop(OK); 1173 int rv = DoWriteLoop(OK);
1154 if (rv == ERR_IO_PENDING) { 1174 if (rv == ERR_IO_PENDING) {
1155 user_write_callback_ = callback; 1175 user_write_callback_ = callback;
1156 } else { 1176 } else {
1157 user_write_buf_ = NULL; 1177 user_write_buf_ = NULL;
1158 user_write_buf_len_ = 0; 1178 user_write_buf_len_ = 0;
1179 waiting_write_ = false;
1159 1180
1160 if (!OnNetworkTaskRunner()) { 1181 if (!OnNetworkTaskRunner()) {
1161 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv)); 1182 PostOrRunCallback(FROM_HERE, base::Bind(callback, rv));
1162 return ERR_IO_PENDING; 1183 return ERR_IO_PENDING;
1163 } 1184 }
1164 } 1185 }
1165 1186
1166 return rv; 1187 return rv;
1167 } 1188 }
1168 1189
1190 bool SSLClientSocketNSS::Core::HasPendingAsyncOperation() {
1191 DCHECK(OnNetworkTaskRunner());
1192 return waiting_read_ || waiting_write_;
1193 }
1194
1195 bool SSLClientSocketNSS::Core::HasUnhandledData() {
1196 DCHECK(OnNetworkTaskRunner());
1197 return unhandled_buffer_size_ != 0;
1198 }
1199
1169 bool SSLClientSocketNSS::Core::OnNSSTaskRunner() const { 1200 bool SSLClientSocketNSS::Core::OnNSSTaskRunner() const {
1170 return nss_task_runner_->RunsTasksOnCurrentThread(); 1201 return nss_task_runner_->RunsTasksOnCurrentThread();
1171 } 1202 }
1172 1203
1173 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const { 1204 bool SSLClientSocketNSS::Core::OnNetworkTaskRunner() const {
1174 return network_task_runner_->RunsTasksOnCurrentThread(); 1205 return network_task_runner_->RunsTasksOnCurrentThread();
1175 } 1206 }
1176 1207
1177 // static 1208 // static
1178 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler( 1209 SECStatus SSLClientSocketNSS::Core::OwnAuthCertHandler(
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 unsigned int len1, len2; 2189 unsigned int len1, len2;
2159 memio_GetWriteParams(nss_bufs_, &buf1, &len1, &buf2, &len2); 2190 memio_GetWriteParams(nss_bufs_, &buf1, &len1, &buf2, &len2);
2160 const unsigned int len = len1 + len2; 2191 const unsigned int len = len1 + len2;
2161 2192
2162 int rv = 0; 2193 int rv = 0;
2163 if (len) { 2194 if (len) {
2164 scoped_refptr<IOBuffer> send_buffer(new IOBuffer(len)); 2195 scoped_refptr<IOBuffer> send_buffer(new IOBuffer(len));
2165 memcpy(send_buffer->data(), buf1, len1); 2196 memcpy(send_buffer->data(), buf1, len1);
2166 memcpy(send_buffer->data() + len1, buf2, len2); 2197 memcpy(send_buffer->data() + len1, buf2, len2);
2167 2198
2168 if (OnNetworkTaskRunner()) { 2199 if (OnNetworkTaskRunner()) {
Takashi Toyoshima 2013/01/15 13:46:03 This comment is not related to this CL. At the he
wtc 2013/01/16 00:34:16 The OnNetworkTaskRunner() test here means "if the
Takashi Toyoshima 2013/01/16 07:16:03 Ah, sorry I mistakenly read this line 2199 as On*N
2169 rv = DoBufferSend(send_buffer, len); 2200 rv = DoBufferSend(send_buffer, len);
2170 } else { 2201 } else {
2171 bool posted = network_task_runner_->PostTask( 2202 bool posted = network_task_runner_->PostTask(
2172 FROM_HERE, 2203 FROM_HERE,
2173 base::Bind(IgnoreResult(&Core::DoBufferSend), this, send_buffer, 2204 base::Bind(IgnoreResult(&Core::DoBufferSend), this, send_buffer,
2174 len)); 2205 len));
2175 rv = posted ? ERR_IO_PENDING : ERR_ABORTED; 2206 rv = posted ? ERR_IO_PENDING : ERR_ABORTED;
2176 } 2207 }
2177 2208
2178 if (rv == ERR_IO_PENDING) { 2209 if (rv == ERR_IO_PENDING) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 PostOrRunCallback(FROM_HERE, c); 2281 PostOrRunCallback(FROM_HERE, c);
2251 } 2282 }
2252 2283
2253 void SSLClientSocketNSS::Core::DoReadCallback(int rv) { 2284 void SSLClientSocketNSS::Core::DoReadCallback(int rv) {
2254 DCHECK(OnNSSTaskRunner()); 2285 DCHECK(OnNSSTaskRunner());
2255 DCHECK_NE(ERR_IO_PENDING, rv); 2286 DCHECK_NE(ERR_IO_PENDING, rv);
2256 DCHECK(!user_read_callback_.is_null()); 2287 DCHECK(!user_read_callback_.is_null());
2257 2288
2258 user_read_buf_ = NULL; 2289 user_read_buf_ = NULL;
2259 user_read_buf_len_ = 0; 2290 user_read_buf_len_ = 0;
2260 base::Closure c = base::Bind( 2291 char* buf;
2261 base::ResetAndReturn(&user_read_callback_), 2292 int amount_in_read_buffer = memio_GetReadParams(nss_bufs_, &buf);
2262 rv); 2293 // This will invoke the user callback with |rv| as result.
2263 PostOrRunCallback(FROM_HERE, c); 2294 base::Closure user_cb = base::Bind(
2295 base::ResetAndReturn(&user_read_callback_), rv);
2296 // This is used to curry the |amount_int_read_buffer| and |user_cb| back to
2297 // the network task runner.
2298 base::Closure task = base::Bind(
2299 &Core::UpdateNSSStatus,
2300 this,
2301 amount_in_read_buffer,
2302 true, // Operation is read.
2303 user_cb);
2304 PostOrRunCallback(FROM_HERE, task);
2264 } 2305 }
2265 2306
2266 void SSLClientSocketNSS::Core::DoWriteCallback(int rv) { 2307 void SSLClientSocketNSS::Core::DoWriteCallback(int rv) {
2267 DCHECK(OnNSSTaskRunner()); 2308 DCHECK(OnNSSTaskRunner());
2268 DCHECK_NE(ERR_IO_PENDING, rv); 2309 DCHECK_NE(ERR_IO_PENDING, rv);
2269 DCHECK(!user_write_callback_.is_null()); 2310 DCHECK(!user_write_callback_.is_null());
2270 2311
2271 // Since Run may result in Write being called, clear |user_write_callback_| 2312 // Since Run may result in Write being called, clear |user_write_callback_|
2272 // up front. 2313 // up front.
2273 user_write_buf_ = NULL; 2314 user_write_buf_ = NULL;
2274 user_write_buf_len_ = 0; 2315 user_write_buf_len_ = 0;
2275 base::Closure c = base::Bind( 2316 char* buf;
2276 base::ResetAndReturn(&user_write_callback_), 2317 // Update buffer status because DoWriteLoop called DoTransportIO which may
2277 rv); 2318 // perform read operations.
2278 PostOrRunCallback(FROM_HERE, c); 2319 int amount_in_read_buffer = memio_GetReadParams(nss_bufs_, &buf);
2320 // This will invoke the user callback with |rv| as result.
2321 base::Closure user_cb = base::Bind(
2322 base::ResetAndReturn(&user_write_callback_), rv);
2323 // This is used to curry the |amount_int_read_buffer| and |user_cb| back to
2324 // the network task runner.
2325 base::Closure task = base::Bind(
2326 &Core::UpdateNSSStatus,
2327 this,
2328 amount_in_read_buffer,
2329 false, // Operation is not read, but write.
2330 user_cb);
2331 PostOrRunCallback(FROM_HERE, task);
2332 }
2333
2334 void SSLClientSocketNSS::Core::UpdateNSSStatus(
wtc 2013/01/14 20:50:08 Document this method either here or in the declara
Takashi Toyoshima 2013/01/15 13:46:03 OK. I use "UpdateNSSTaskRunnerStatus" for now. I m
2335 int amount_in_read_buffer,
2336 bool operation_is_read,
2337 const base::Closure& callback) {
2338 DCHECK(OnNetworkTaskRunner());
2339 DCHECK(!callback.is_null());
2340 DCHECK((operation_is_read && waiting_read_) ||
2341 (!operation_is_read && waiting_write_));
2342
2343 unhandled_buffer_size_ = amount_in_read_buffer;
2344 if (operation_is_read)
2345 waiting_read_ = false;
2346 else
2347 waiting_write_ = false;
2348 callback.Run();
2279 } 2349 }
2280 2350
2281 SECStatus SSLClientSocketNSS::Core::ClientChannelIDHandler( 2351 SECStatus SSLClientSocketNSS::Core::ClientChannelIDHandler(
2282 void* arg, 2352 void* arg,
2283 PRFileDesc* socket, 2353 PRFileDesc* socket,
2284 SECKEYPublicKey **out_public_key, 2354 SECKEYPublicKey **out_public_key,
2285 SECKEYPrivateKey **out_private_key) { 2355 SECKEYPrivateKey **out_private_key) {
2286 Core* core = reinterpret_cast<Core*>(arg); 2356 Core* core = reinterpret_cast<Core*>(arg);
2287 DCHECK(core->OnNSSTaskRunner()); 2357 DCHECK(core->OnNSSTaskRunner());
2288 2358
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2891 } 2961 }
2892 2962
2893 bool SSLClientSocketNSS::IsConnected() const { 2963 bool SSLClientSocketNSS::IsConnected() const {
2894 // Ideally, we should also check if we have received the close_notify alert 2964 // Ideally, we should also check if we have received the close_notify alert
2895 // message from the server, and return false in that case. We're not doing 2965 // message from the server, and return false in that case. We're not doing
2896 // that, so this function may return a false positive. Since the upper 2966 // that, so this function may return a false positive. Since the upper
2897 // layer (HttpNetworkTransaction) needs to handle a persistent connection 2967 // layer (HttpNetworkTransaction) needs to handle a persistent connection
2898 // closed by the server when we send a request anyway, a false positive in 2968 // closed by the server when we send a request anyway, a false positive in
2899 // exchange for simpler code is a good trade-off. 2969 // exchange for simpler code is a good trade-off.
2900 EnterFunction(""); 2970 EnterFunction("");
2901 bool ret = completed_handshake_ && transport_->socket()->IsConnected(); 2971 bool ret;
2972
2973 if (!completed_handshake_)
2974 ret = false;
2975 else if (core_->HasPendingAsyncOperation())
2976 ret = true;
2977 else if (core_->HasUnhandledData())
Ryan Sleevi 2013/01/09 19:01:52 BUG: I think there's a bug here. This fails to con
Takashi Toyoshima 2013/01/10 07:46:29 OK, I'll restore ssl_recv_eof_, then remove above
Takashi Toyoshima 2013/01/15 13:46:03 Try to fix this in the next CL.
2978 ret = true;
2979 else
2980 ret = transport_->socket()->IsConnected();
wtc 2013/01/14 20:50:08 I would probably write this as a single conditiona
Takashi Toyoshima 2013/01/15 13:46:03 Done.
Takashi Toyoshima 2013/01/15 13:46:03 Done.
2981
2902 LeaveFunction(""); 2982 LeaveFunction("");
2903 return ret; 2983 return ret;
2904 } 2984 }
2905 2985
2906 bool SSLClientSocketNSS::IsConnectedAndIdle() const { 2986 bool SSLClientSocketNSS::IsConnectedAndIdle() const {
2907 // Unlike IsConnected, this method doesn't return a false positive. 2987 // Unlike IsConnected, this method doesn't return a false positive.
2908 // 2988 //
2909 // Strictly speaking, we should check if we have received the close_notify 2989 // Strictly speaking, we should check if we have received the close_notify
2910 // alert message from the server, and return false in that case. Although 2990 // alert message from the server, and return false in that case. Although
2911 // the close_notify alert message means EOF in the SSL layer, it is just 2991 // the close_notify alert message means EOF in the SSL layer, it is just
2912 // bytes to the transport layer below, so 2992 // bytes to the transport layer below, so
2913 // transport_->socket()->IsConnectedAndIdle() returns the desired false 2993 // transport_->socket()->IsConnectedAndIdle() returns the desired false
2914 // when we receive close_notify. 2994 // when we receive close_notify.
2915 EnterFunction(""); 2995 EnterFunction("");
2916 bool ret = completed_handshake_ && transport_->socket()->IsConnectedAndIdle(); 2996 bool ret;
2997
2998 if (!completed_handshake_)
2999 ret = false;
3000 else if (core_->HasPendingAsyncOperation())
3001 ret = true; // This is probably wrong, but mirrors TCP.
3002 else if (core_->HasUnhandledData())
Ryan Sleevi 2013/01/09 19:01:52 Same here. Design wise, you can probably simplify
Takashi Toyoshima 2013/01/10 07:46:29 I tried to keep EnterFunction() and LeaveFunction(
Ryan Sleevi 2013/01/10 08:01:23 Just substitute the return for ret = ... & elseifs
Takashi Toyoshima 2013/01/10 08:17:14 Ah, I see. You mean that I should reuse IsConnecte
Takashi Toyoshima 2013/01/15 13:46:03 I applied Wan-Teh's suggestion after applying Ryan
3003 ret = false;
3004 else
3005 ret = transport_->socket()->IsConnectedAndIdle();
3006
2917 LeaveFunction(""); 3007 LeaveFunction("");
2918 return ret; 3008 return ret;
2919 } 3009 }
2920 3010
2921 int SSLClientSocketNSS::GetPeerAddress(IPEndPoint* address) const { 3011 int SSLClientSocketNSS::GetPeerAddress(IPEndPoint* address) const {
2922 return transport_->socket()->GetPeerAddress(address); 3012 return transport_->socket()->GetPeerAddress(address);
2923 } 3013 }
2924 3014
2925 int SSLClientSocketNSS::GetLocalAddress(IPEndPoint* address) const { 3015 int SSLClientSocketNSS::GetLocalAddress(IPEndPoint* address) const {
2926 return transport_->socket()->GetLocalAddress(address); 3016 return transport_->socket()->GetLocalAddress(address);
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
3460 EnsureThreadIdAssigned(); 3550 EnsureThreadIdAssigned();
3461 base::AutoLock auto_lock(lock_); 3551 base::AutoLock auto_lock(lock_);
3462 return valid_thread_id_ == base::PlatformThread::CurrentId(); 3552 return valid_thread_id_ == base::PlatformThread::CurrentId();
3463 } 3553 }
3464 3554
3465 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const { 3555 ServerBoundCertService* SSLClientSocketNSS::GetServerBoundCertService() const {
3466 return server_bound_cert_service_; 3556 return server_bound_cert_service_;
3467 } 3557 }
3468 3558
3469 } // namespace net 3559 } // namespace net
OLDNEW
« net/data/websocket/README ('K') | « net/data/websocket/split_frame_check.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698