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/tcp_client_socket.h" | 5 #include "net/socket/tcp_client_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 &write_socket_watcher_, &write_watcher_)) { | 567 &write_socket_watcher_, &write_watcher_)) { |
568 DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno; | 568 DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno; |
569 return MapSystemError(errno); | 569 return MapSystemError(errno); |
570 } | 570 } |
571 | 571 |
572 write_buf_ = buf; | 572 write_buf_ = buf; |
573 write_buf_len_ = buf_len; | 573 write_buf_len_ = buf_len; |
574 old_write_callback_ = callback; | 574 old_write_callback_ = callback; |
575 return ERR_IO_PENDING; | 575 return ERR_IO_PENDING; |
576 } | 576 } |
| 577 int TCPClientSocketLibevent::Write(IOBuffer* buf, |
| 578 int buf_len, |
| 579 const CompletionCallback& callback) { |
| 580 DCHECK(CalledOnValidThread()); |
| 581 DCHECK_NE(kInvalidSocket, socket_); |
| 582 DCHECK(!waiting_connect()); |
| 583 DCHECK(!old_write_callback_ && write_callback_.is_null()); |
| 584 // Synchronous operation not supported |
| 585 DCHECK(!callback.is_null()); |
| 586 DCHECK_GT(buf_len, 0); |
| 587 |
| 588 int nwrite = InternalWrite(buf, buf_len); |
| 589 if (nwrite >= 0) { |
| 590 base::StatsCounter write_bytes("tcp.write_bytes"); |
| 591 write_bytes.Add(nwrite); |
| 592 if (nwrite > 0) |
| 593 use_history_.set_was_used_to_convey_data(); |
| 594 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, nwrite, |
| 595 buf->data()); |
| 596 return nwrite; |
| 597 } |
| 598 if (errno != EAGAIN && errno != EWOULDBLOCK) |
| 599 return MapSystemError(errno); |
| 600 |
| 601 if (!MessageLoopForIO::current()->WatchFileDescriptor( |
| 602 socket_, true, MessageLoopForIO::WATCH_WRITE, |
| 603 &write_socket_watcher_, &write_watcher_)) { |
| 604 DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno; |
| 605 return MapSystemError(errno); |
| 606 } |
| 607 |
| 608 write_buf_ = buf; |
| 609 write_buf_len_ = buf_len; |
| 610 write_callback_ = callback; |
| 611 return ERR_IO_PENDING; |
| 612 } |
577 | 613 |
578 int TCPClientSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) { | 614 int TCPClientSocketLibevent::InternalWrite(IOBuffer* buf, int buf_len) { |
579 int nwrite; | 615 int nwrite; |
580 if (use_tcp_fastopen_ && !tcp_fastopen_connected_) { | 616 if (use_tcp_fastopen_ && !tcp_fastopen_connected_) { |
581 // We have a limited amount of data to send in the SYN packet. | 617 // We have a limited amount of data to send in the SYN packet. |
582 int kMaxFastOpenSendLength = 1420; | 618 int kMaxFastOpenSendLength = 1420; |
583 | 619 |
584 buf_len = std::min(kMaxFastOpenSendLength, buf_len); | 620 buf_len = std::min(kMaxFastOpenSendLength, buf_len); |
585 | 621 |
586 int flags = 0x20000000; // Magic flag to enable TCP_FASTOPEN | 622 int flags = 0x20000000; // Magic flag to enable TCP_FASTOPEN |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 848 |
813 int64 TCPClientSocketLibevent::NumBytesRead() const { | 849 int64 TCPClientSocketLibevent::NumBytesRead() const { |
814 return num_bytes_read_; | 850 return num_bytes_read_; |
815 } | 851 } |
816 | 852 |
817 base::TimeDelta TCPClientSocketLibevent::GetConnectTimeMicros() const { | 853 base::TimeDelta TCPClientSocketLibevent::GetConnectTimeMicros() const { |
818 return connect_time_micros_; | 854 return connect_time_micros_; |
819 } | 855 } |
820 | 856 |
821 } // namespace net | 857 } // namespace net |
OLD | NEW |