OLD | NEW |
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 #include "net/socket/ssl_server_socket_nss.h" | 5 #include "net/socket/ssl_server_socket_nss.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 OnRecvComplete(result); | 528 OnRecvComplete(result); |
529 } | 529 } |
530 | 530 |
531 // Do network I/O between the given buffer and the given socket. | 531 // Do network I/O between the given buffer and the given socket. |
532 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) | 532 // Return true if some I/O performed, false otherwise (error or ERR_IO_PENDING) |
533 bool SSLServerSocketNSS::DoTransportIO() { | 533 bool SSLServerSocketNSS::DoTransportIO() { |
534 bool network_moved = false; | 534 bool network_moved = false; |
535 if (nss_bufs_ != NULL) { | 535 if (nss_bufs_ != NULL) { |
536 int nsent = BufferSend(); | 536 int nsent = BufferSend(); |
537 int nreceived = BufferRecv(); | 537 int nreceived = BufferRecv(); |
538 network_moved = (nsent > 0 || nreceived >= 0); | 538 network_moved = (nsent > 0 || nreceived > 0); |
539 } | 539 } |
540 return network_moved; | 540 return network_moved; |
541 } | 541 } |
542 | 542 |
543 int SSLServerSocketNSS::DoPayloadRead() { | 543 int SSLServerSocketNSS::DoPayloadRead() { |
544 DCHECK(user_read_buf_); | 544 DCHECK(user_read_buf_); |
545 DCHECK_GT(user_read_buf_len_, 0); | 545 DCHECK_GT(user_read_buf_len_, 0); |
546 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); | 546 int rv = PR_Read(nss_fd_, user_read_buf_->data(), user_read_buf_len_); |
547 if (rv >= 0) | 547 if (rv >= 0) |
548 return rv; | 548 return rv; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 make_scoped_refptr(new SSLErrorParams(rv, 0))); | 616 make_scoped_refptr(new SSLErrorParams(rv, 0))); |
617 return rv; | 617 return rv; |
618 } | 618 } |
619 | 619 |
620 bool network_moved; | 620 bool network_moved; |
621 int rv; | 621 int rv; |
622 do { | 622 do { |
623 rv = DoPayloadRead(); | 623 rv = DoPayloadRead(); |
624 network_moved = DoTransportIO(); | 624 network_moved = DoTransportIO(); |
625 } while (rv == ERR_IO_PENDING && network_moved); | 625 } while (rv == ERR_IO_PENDING && network_moved); |
| 626 |
| 627 do { |
| 628 network_moved = DoTransportIO(); |
| 629 } while (network_moved); |
| 630 |
626 return rv; | 631 return rv; |
627 } | 632 } |
628 | 633 |
629 int SSLServerSocketNSS::DoWriteLoop(int result) { | 634 int SSLServerSocketNSS::DoWriteLoop(int result) { |
630 DCHECK(completed_handshake_); | 635 DCHECK(completed_handshake_); |
631 DCHECK(next_handshake_state_ == STATE_NONE); | 636 DCHECK(next_handshake_state_ == STATE_NONE); |
632 | 637 |
633 if (result < 0) | 638 if (result < 0) |
634 return result; | 639 return result; |
635 | 640 |
636 if (!nss_bufs_) { | 641 if (!nss_bufs_) { |
637 LOG(DFATAL) << "!nss_bufs_"; | 642 LOG(DFATAL) << "!nss_bufs_"; |
638 int rv = ERR_UNEXPECTED; | 643 int rv = ERR_UNEXPECTED; |
639 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, | 644 net_log_.AddEvent(NetLog::TYPE_SSL_WRITE_ERROR, |
640 make_scoped_refptr(new SSLErrorParams(rv, 0))); | 645 make_scoped_refptr(new SSLErrorParams(rv, 0))); |
641 return rv; | 646 return rv; |
642 } | 647 } |
643 | 648 |
644 bool network_moved; | 649 bool network_moved; |
645 int rv; | 650 int rv; |
646 do { | 651 do { |
647 rv = DoPayloadWrite(); | 652 rv = DoPayloadWrite(); |
648 network_moved = DoTransportIO(); | 653 network_moved = DoTransportIO(); |
649 } while (rv == ERR_IO_PENDING && network_moved); | 654 } while (rv == ERR_IO_PENDING && network_moved); |
| 655 |
| 656 do { |
| 657 network_moved = DoTransportIO(); |
| 658 } while (network_moved); |
| 659 |
650 return rv; | 660 return rv; |
651 } | 661 } |
652 | 662 |
653 int SSLServerSocketNSS::DoHandshake() { | 663 int SSLServerSocketNSS::DoHandshake() { |
654 int net_error = net::OK; | 664 int net_error = net::OK; |
655 SECStatus rv = SSL_ForceHandshake(nss_fd_); | 665 SECStatus rv = SSL_ForceHandshake(nss_fd_); |
656 | 666 |
657 if (rv == SECSuccess) { | 667 if (rv == SECSuccess) { |
658 completed_handshake_ = true; | 668 completed_handshake_ = true; |
659 } else { | 669 } else { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 // We must call EnsureOCSPInit() here, on the IO thread, to get the IO loop | 751 // We must call EnsureOCSPInit() here, on the IO thread, to get the IO loop |
742 // by MessageLoopForIO::current(). | 752 // by MessageLoopForIO::current(). |
743 // X509Certificate::Verify() runs on a worker thread of CertVerifier. | 753 // X509Certificate::Verify() runs on a worker thread of CertVerifier. |
744 EnsureOCSPInit(); | 754 EnsureOCSPInit(); |
745 #endif | 755 #endif |
746 | 756 |
747 return OK; | 757 return OK; |
748 } | 758 } |
749 | 759 |
750 } // namespace net | 760 } // namespace net |
OLD | NEW |