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

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

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/ssl_client_socket_openssl.h ('k') | net/socket/ssl_client_socket_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 ClientSocketHandle* transport_socket, 383 ClientSocketHandle* transport_socket,
384 const HostPortPair& host_and_port, 384 const HostPortPair& host_and_port,
385 const SSLConfig& ssl_config, 385 const SSLConfig& ssl_config,
386 const SSLClientSocketContext& context) 386 const SSLClientSocketContext& context)
387 : ALLOW_THIS_IN_INITIALIZER_LIST(buffer_send_callback_( 387 : ALLOW_THIS_IN_INITIALIZER_LIST(buffer_send_callback_(
388 this, &SSLClientSocketOpenSSL::BufferSendComplete)), 388 this, &SSLClientSocketOpenSSL::BufferSendComplete)),
389 ALLOW_THIS_IN_INITIALIZER_LIST(buffer_recv_callback_( 389 ALLOW_THIS_IN_INITIALIZER_LIST(buffer_recv_callback_(
390 this, &SSLClientSocketOpenSSL::BufferRecvComplete)), 390 this, &SSLClientSocketOpenSSL::BufferRecvComplete)),
391 transport_send_busy_(false), 391 transport_send_busy_(false),
392 transport_recv_busy_(false), 392 transport_recv_busy_(false),
393 user_connect_callback_(NULL), 393 old_user_connect_callback_(NULL),
394 user_read_callback_(NULL), 394 user_read_callback_(NULL),
395 user_write_callback_(NULL), 395 user_write_callback_(NULL),
396 completed_handshake_(false), 396 completed_handshake_(false),
397 client_auth_cert_needed_(false), 397 client_auth_cert_needed_(false),
398 cert_verifier_(context.cert_verifier), 398 cert_verifier_(context.cert_verifier),
399 ssl_(NULL), 399 ssl_(NULL),
400 transport_bio_(NULL), 400 transport_bio_(NULL),
401 transport_(transport_socket), 401 transport_(transport_socket),
402 host_and_port_(host_and_port), 402 host_and_port_(host_and_port),
403 ssl_config_(ssl_config), 403 ssl_config_(ssl_config),
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, result); 641 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, result);
642 return result; 642 return result;
643 } 643 }
644 644
645 // Set SSL to client mode. Handshake happens in the loop below. 645 // Set SSL to client mode. Handshake happens in the loop below.
646 SSL_set_connect_state(ssl_); 646 SSL_set_connect_state(ssl_);
647 647
648 GotoState(STATE_HANDSHAKE); 648 GotoState(STATE_HANDSHAKE);
649 int rv = DoHandshakeLoop(net::OK); 649 int rv = DoHandshakeLoop(net::OK);
650 if (rv == ERR_IO_PENDING) { 650 if (rv == ERR_IO_PENDING) {
651 old_user_connect_callback_ = callback;
652 } else {
653 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv);
654 }
655
656 return rv > OK ? OK : rv;
657 }
658 int SSLClientSocketOpenSSL::Connect(const CompletionCallback& callback) {
659 net_log_.BeginEvent(NetLog::TYPE_SSL_CONNECT, NULL);
660
661 // Set up new ssl object.
662 if (!Init()) {
663 int result = ERR_UNEXPECTED;
664 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, result);
665 return result;
666 }
667
668 // Set SSL to client mode. Handshake happens in the loop below.
669 SSL_set_connect_state(ssl_);
670
671 GotoState(STATE_HANDSHAKE);
672 int rv = DoHandshakeLoop(net::OK);
673 if (rv == ERR_IO_PENDING) {
651 user_connect_callback_ = callback; 674 user_connect_callback_ = callback;
652 } else { 675 } else {
653 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); 676 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv);
654 } 677 }
655 678
656 return rv > OK ? OK : rv; 679 return rv > OK ? OK : rv;
657 } 680 }
658 681
659 void SSLClientSocketOpenSSL::Disconnect() { 682 void SSLClientSocketOpenSSL::Disconnect() {
660 if (ssl_) { 683 if (ssl_) {
661 SSL_free(ssl_); 684 SSL_free(ssl_);
662 ssl_ = NULL; 685 ssl_ = NULL;
663 } 686 }
664 if (transport_bio_) { 687 if (transport_bio_) {
665 BIO_free_all(transport_bio_); 688 BIO_free_all(transport_bio_);
666 transport_bio_ = NULL; 689 transport_bio_ = NULL;
667 } 690 }
668 691
669 // Shut down anything that may call us back. 692 // Shut down anything that may call us back.
670 verifier_.reset(); 693 verifier_.reset();
671 transport_->socket()->Disconnect(); 694 transport_->socket()->Disconnect();
672 695
673 // Null all callbacks, delete all buffers. 696 // Null all callbacks, delete all buffers.
674 transport_send_busy_ = false; 697 transport_send_busy_ = false;
675 send_buffer_ = NULL; 698 send_buffer_ = NULL;
676 transport_recv_busy_ = false; 699 transport_recv_busy_ = false;
677 recv_buffer_ = NULL; 700 recv_buffer_ = NULL;
678 701
679 user_connect_callback_ = NULL; 702 old_user_connect_callback_ = NULL;
703 user_connect_callback_.Reset();
680 user_read_callback_ = NULL; 704 user_read_callback_ = NULL;
681 user_write_callback_ = NULL; 705 user_write_callback_ = NULL;
682 user_read_buf_ = NULL; 706 user_read_buf_ = NULL;
683 user_read_buf_len_ = 0; 707 user_read_buf_len_ = 0;
684 user_write_buf_ = NULL; 708 user_write_buf_ = NULL;
685 user_write_buf_len_ = 0; 709 user_write_buf_len_ = 0;
686 710
687 server_cert_verify_result_.Reset(); 711 server_cert_verify_result_.Reset();
688 completed_handshake_ = false; 712 completed_handshake_ = false;
689 713
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 DCHECK(recv_buffer_); 1034 DCHECK(recv_buffer_);
1011 int ret = BIO_write(transport_bio_, recv_buffer_->data(), result); 1035 int ret = BIO_write(transport_bio_, recv_buffer_->data(), result);
1012 // A write into a memory BIO should always succeed. 1036 // A write into a memory BIO should always succeed.
1013 CHECK_EQ(result, ret); 1037 CHECK_EQ(result, ret);
1014 } 1038 }
1015 recv_buffer_ = NULL; 1039 recv_buffer_ = NULL;
1016 transport_recv_busy_ = false; 1040 transport_recv_busy_ = false;
1017 } 1041 }
1018 1042
1019 void SSLClientSocketOpenSSL::DoConnectCallback(int rv) { 1043 void SSLClientSocketOpenSSL::DoConnectCallback(int rv) {
1020 OldCompletionCallback* c = user_connect_callback_; 1044 if (old_user_connect_callback_) {
1021 user_connect_callback_ = NULL; 1045 OldCompletionCallback* c = old_user_connect_callback_;
1022 c->Run(rv > OK ? OK : rv); 1046 old_user_connect_callback_ = NULL;
1047 c->Run(rv > OK ? OK : rv);
1048 } else {
1049 CompletionCallback c = user_connect_callback_;
1050 user_connect_callback_.Reset();
1051 c.Run(rv > OK ? OK : rv);
1052 }
1023 } 1053 }
1024 1054
1025 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) { 1055 void SSLClientSocketOpenSSL::OnHandshakeIOComplete(int result) {
1026 int rv = DoHandshakeLoop(result); 1056 int rv = DoHandshakeLoop(result);
1027 if (rv != ERR_IO_PENDING) { 1057 if (rv != ERR_IO_PENDING) {
1028 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv); 1058 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SSL_CONNECT, rv);
1029 DoConnectCallback(rv); 1059 DoConnectCallback(rv);
1030 } 1060 }
1031 } 1061 }
1032 1062
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv, 1275 net_log_.AddByteTransferEvent(NetLog::TYPE_SSL_SOCKET_BYTES_SENT, rv,
1246 user_write_buf_->data()); 1276 user_write_buf_->data());
1247 return rv; 1277 return rv;
1248 } 1278 }
1249 1279
1250 int err = SSL_get_error(ssl_, rv); 1280 int err = SSL_get_error(ssl_, rv);
1251 return MapOpenSSLError(err, err_tracer); 1281 return MapOpenSSLError(err, err_tracer);
1252 } 1282 }
1253 1283
1254 } // namespace net 1284 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/ssl_client_socket_openssl.h ('k') | net/socket/ssl_client_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698