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

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

Issue 11366155: SSLClientSocket::IsConnected should care for internal buffers (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: add unit test Created 8 years 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_win.h" 5 #include "net/socket/ssl_client_socket_win.h"
6 6
7 #include <schnlsp.h> 7 #include <schnlsp.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 695
696 // TODO(wtc): reset more members? 696 // TODO(wtc): reset more members?
697 bytes_decrypted_ = 0; 697 bytes_decrypted_ = 0;
698 bytes_received_ = 0; 698 bytes_received_ = 0;
699 writing_first_token_ = false; 699 writing_first_token_ = false;
700 renegotiating_ = false; 700 renegotiating_ = false;
701 need_more_data_ = false; 701 need_more_data_ = false;
702 } 702 }
703 703
704 bool SSLClientSocketWin::IsConnected() const { 704 bool SSLClientSocketWin::IsConnected() const {
705 if (!completed_handshake())
706 return false;
707
708 // Return true if buffered incoming data is not consumed.
709 if (bytes_received_ || bytes_decrypted_)
710 return true;
711
705 // Ideally, we should also check if we have received the close_notify alert 712 // Ideally, we should also check if we have received the close_notify alert
706 // message from the server, and return false in that case. We're not doing 713 // message from the server, and return false in that case. We're not doing
707 // that, so this function may return a false positive. Since the upper 714 // that, so this function may return a false positive. Since the upper
708 // layer (HttpNetworkTransaction) needs to handle a persistent connection 715 // layer (HttpNetworkTransaction) needs to handle a persistent connection
709 // closed by the server when we send a request anyway, a false positive in 716 // closed by the server when we send a request anyway, a false positive in
710 // exchange for simpler code is a good trade-off. 717 // exchange for simpler code is a good trade-off.
711 return completed_handshake() && transport_->socket()->IsConnected(); 718 return transport_->socket()->IsConnected();
712 } 719 }
713 720
714 bool SSLClientSocketWin::IsConnectedAndIdle() const { 721 bool SSLClientSocketWin::IsConnectedAndIdle() const {
722 if (!completed_handshake())
723 return false;
724
725 // Return false if buffered incoming data is not consumed.
726 if (bytes_received_ || bytes_decrypted_)
727 return false;
728
715 // Unlike IsConnected, this method doesn't return a false positive. 729 // Unlike IsConnected, this method doesn't return a false positive.
716 // 730 //
717 // Strictly speaking, we should check if we have received the close_notify 731 // Strictly speaking, we should check if we have received the close_notify
718 // alert message from the server, and return false in that case. Although 732 // alert message from the server, and return false in that case. Although
719 // the close_notify alert message means EOF in the SSL layer, it is just 733 // the close_notify alert message means EOF in the SSL layer, it is just
720 // bytes to the transport layer below, so 734 // bytes to the transport layer below, so
721 // transport_->socket()->IsConnectedAndIdle() returns the desired false 735 // transport_->socket()->IsConnectedAndIdle() returns the desired false
722 // when we receive close_notify. 736 // when we receive close_notify.
723 return completed_handshake() && transport_->socket()->IsConnectedAndIdle(); 737 return transport_->socket()->IsConnectedAndIdle();
724 } 738 }
725 739
726 int SSLClientSocketWin::GetPeerAddress(IPEndPoint* address) const { 740 int SSLClientSocketWin::GetPeerAddress(IPEndPoint* address) const {
727 return transport_->socket()->GetPeerAddress(address); 741 return transport_->socket()->GetPeerAddress(address);
728 } 742 }
729 743
730 int SSLClientSocketWin::GetLocalAddress(IPEndPoint* address) const { 744 int SSLClientSocketWin::GetLocalAddress(IPEndPoint* address) const {
731 return transport_->socket()->GetLocalAddress(address); 745 return transport_->socket()->GetLocalAddress(address);
732 } 746 }
733 747
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2_CA); 1629 UpdateConnectionTypeHistograms(CONNECTION_SSL_MD2_CA);
1616 } 1630 }
1617 1631
1618 void SSLClientSocketWin::FreeSendBuffer() { 1632 void SSLClientSocketWin::FreeSendBuffer() {
1619 SECURITY_STATUS status = FreeContextBuffer(send_buffer_.pvBuffer); 1633 SECURITY_STATUS status = FreeContextBuffer(send_buffer_.pvBuffer);
1620 DCHECK(status == SEC_E_OK); 1634 DCHECK(status == SEC_E_OK);
1621 memset(&send_buffer_, 0, sizeof(send_buffer_)); 1635 memset(&send_buffer_, 0, sizeof(send_buffer_));
1622 } 1636 }
1623 1637
1624 } // namespace net 1638 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698