| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
| 6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
| 7 | 7 |
| 8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 return result; | 571 return result; |
| 572 } | 572 } |
| 573 if (!socket_.get() || !socket_->IsConnected()) { | 573 if (!socket_.get() || !socket_->IsConnected()) { |
| 574 Finish(); | 574 Finish(); |
| 575 return ERR_CONNECTION_CLOSED; | 575 return ERR_CONNECTION_CLOSED; |
| 576 } | 576 } |
| 577 | 577 |
| 578 next_state_ = STATE_READ_WRITE; | 578 next_state_ = STATE_READ_WRITE; |
| 579 | 579 |
| 580 if (!read_buf_) { | 580 if (!read_buf_) { |
| 581 // No read pending. |
| 581 read_buf_ = new IOBuffer(kReadBufferSize); | 582 read_buf_ = new IOBuffer(kReadBufferSize); |
| 582 result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_); | 583 result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_); |
| 583 if (result > 0) { | 584 if (result > 0) { |
| 584 DidReceiveData(result); | 585 DidReceiveData(result); |
| 585 result = OK; | 586 return OK; |
| 586 } else if (result == 0) { | 587 } else if (result == 0) { |
| 587 // 0 indicates end-of-file, so socket was closed. | 588 // 0 indicates end-of-file, so socket was closed. |
| 588 Finish(); | 589 Finish(); |
| 589 return ERR_CONNECTION_CLOSED; | 590 return ERR_CONNECTION_CLOSED; |
| 590 } | 591 } |
| 592 // If read is pending, try write as well. |
| 593 // Otherwise, return the result and do next loop. |
| 594 if (result != ERR_IO_PENDING) |
| 595 return result; |
| 591 } | 596 } |
| 597 // Read is pending. |
| 598 DCHECK(read_buf_); |
| 599 |
| 592 if (write_buf_ && !current_write_buf_) { | 600 if (write_buf_ && !current_write_buf_) { |
| 601 // No write pending. |
| 593 current_write_buf_ = new DrainableIOBuffer(write_buf_, write_buf_size_); | 602 current_write_buf_ = new DrainableIOBuffer(write_buf_, write_buf_size_); |
| 594 current_write_buf_->SetOffset(write_buf_offset_); | 603 current_write_buf_->SetOffset(write_buf_offset_); |
| 595 result = socket_->Write(current_write_buf_, | 604 result = socket_->Write(current_write_buf_, |
| 596 current_write_buf_->BytesRemaining(), | 605 current_write_buf_->BytesRemaining(), |
| 597 &write_callback_); | 606 &write_callback_); |
| 598 if (result > 0) { | 607 if (result > 0) { |
| 599 DidSendData(result); | 608 DidSendData(result); |
| 600 result = OK; | 609 return OK; |
| 601 } | 610 } |
| 611 return result; |
| 602 } | 612 } |
| 603 | 613 |
| 604 // We arrived here when Write is performed and finished. | 614 // We arrived here when both operation is pending. |
| 605 if (result == OK) | 615 return ERR_IO_PENDING; |
| 606 return ERR_IO_PENDING; | |
| 607 return result; | |
| 608 } | 616 } |
| 609 | 617 |
| 610 int SocketStream::HandleCertificateError(int result) { | 618 int SocketStream::HandleCertificateError(int result) { |
| 611 // TODO(ukai): handle cert error properly. | 619 // TODO(ukai): handle cert error properly. |
| 612 switch (result) { | 620 switch (result) { |
| 613 case ERR_CERT_COMMON_NAME_INVALID: | 621 case ERR_CERT_COMMON_NAME_INVALID: |
| 614 case ERR_CERT_DATE_INVALID: | 622 case ERR_CERT_DATE_INVALID: |
| 615 case ERR_CERT_AUTHORITY_INVALID: | 623 case ERR_CERT_AUTHORITY_INVALID: |
| 616 result = OK; | 624 result = OK; |
| 617 break; | 625 break; |
| 618 default: | 626 default: |
| 619 break; | 627 break; |
| 620 } | 628 } |
| 621 return result; | 629 return result; |
| 622 } | 630 } |
| 623 | 631 |
| 624 bool SocketStream::is_secure() const { | 632 bool SocketStream::is_secure() const { |
| 625 return url_.SchemeIs("wss"); | 633 return url_.SchemeIs("wss"); |
| 626 } | 634 } |
| 627 | 635 |
| 628 SSLConfigService* SocketStream::ssl_config_service() const { | 636 SSLConfigService* SocketStream::ssl_config_service() const { |
| 629 return context_->ssl_config_service(); | 637 return context_->ssl_config_service(); |
| 630 } | 638 } |
| 631 | 639 |
| 632 ProxyService* SocketStream::proxy_service() const { | 640 ProxyService* SocketStream::proxy_service() const { |
| 633 return context_->proxy_service(); | 641 return context_->proxy_service(); |
| 634 } | 642 } |
| 635 | 643 |
| 636 } // namespace net | 644 } // namespace net |
| OLD | NEW |