OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base/ssl_client_socket_nss.h" | 5 #include "net/base/ssl_client_socket_nss.h" |
6 | 6 |
7 #include <nspr.h> | 7 #include <nspr.h> |
8 #include <nss.h> | 8 #include <nss.h> |
9 #include <secerr.h> | 9 #include <secerr.h> |
10 // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=455424 | 10 // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=455424 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (nss_fd_ != NULL) { | 158 if (nss_fd_ != NULL) { |
159 PR_Close(nss_fd_); | 159 PR_Close(nss_fd_); |
160 nss_fd_ = NULL; | 160 nss_fd_ = NULL; |
161 } | 161 } |
162 completed_handshake_ = false; | 162 completed_handshake_ = false; |
163 transport_->Disconnect(); | 163 transport_->Disconnect(); |
164 LeaveFunction(""); | 164 LeaveFunction(""); |
165 } | 165 } |
166 | 166 |
167 bool SSLClientSocketNSS::IsConnected() const { | 167 bool SSLClientSocketNSS::IsConnected() const { |
| 168 // Ideally, we should also check if we have received the close_notify alert |
| 169 // message from the server, and return false in that case. We're not doing |
| 170 // that, so this function may return a false positive. Since the upper |
| 171 // layer (HttpNetworkTransaction) needs to handle a persistent connection |
| 172 // closed by the server when we send a request anyway, a false positive in |
| 173 // exchange for simpler code is a good trade-off. |
168 EnterFunction(""); | 174 EnterFunction(""); |
169 bool ret = completed_handshake_ && transport_->IsConnected(); | 175 bool ret = completed_handshake_ && transport_->IsConnected(); |
170 LeaveFunction(""); | 176 LeaveFunction(""); |
171 return ret; | 177 return ret; |
172 } | 178 } |
173 | 179 |
| 180 bool SSLClientSocketNSS::IsConnectedAndIdle() const { |
| 181 // Unlike IsConnected, this method doesn't return a false positive. |
| 182 // |
| 183 // Strictly speaking, we should check if we have received the close_notify |
| 184 // alert message from the server, and return false in that case. Although |
| 185 // the close_notify alert message means EOF in the SSL layer, it is just |
| 186 // bytes to the transport layer below, so transport_->IsConnectedAndIdle() |
| 187 // returns the desired false when we receive close_notify. |
| 188 EnterFunction(""); |
| 189 bool ret = completed_handshake_ && transport_->IsConnectedAndIdle(); |
| 190 LeaveFunction(""); |
| 191 return ret; |
| 192 } |
| 193 |
174 int SSLClientSocketNSS::Read(char* buf, int buf_len, | 194 int SSLClientSocketNSS::Read(char* buf, int buf_len, |
175 CompletionCallback* callback) { | 195 CompletionCallback* callback) { |
176 EnterFunction(buf_len); | 196 EnterFunction(buf_len); |
177 DCHECK(completed_handshake_); | 197 DCHECK(completed_handshake_); |
178 DCHECK(next_state_ == STATE_NONE); | 198 DCHECK(next_state_ == STATE_NONE); |
179 DCHECK(!user_callback_); | 199 DCHECK(!user_callback_); |
180 DCHECK(!user_buf_); | 200 DCHECK(!user_buf_); |
181 | 201 |
182 user_buf_ = buf; | 202 user_buf_ = buf; |
183 user_buf_len_ = buf_len; | 203 user_buf_len_ = buf_len; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 GotoState(STATE_PAYLOAD_WRITE); | 579 GotoState(STATE_PAYLOAD_WRITE); |
560 return ERR_IO_PENDING; | 580 return ERR_IO_PENDING; |
561 } | 581 } |
562 user_buf_ = NULL; | 582 user_buf_ = NULL; |
563 LeaveFunction(""); | 583 LeaveFunction(""); |
564 return NetErrorFromNSPRError(prerr); | 584 return NetErrorFromNSPRError(prerr); |
565 } | 585 } |
566 | 586 |
567 } // namespace net | 587 } // namespace net |
568 | 588 |
OLD | NEW |