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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 // Synchronous operation not supported | 428 // Synchronous operation not supported |
429 DCHECK(callback); | 429 DCHECK(callback); |
430 DCHECK_GT(buf_len, 0); | 430 DCHECK_GT(buf_len, 0); |
431 | 431 |
432 int nread = HANDLE_EINTR(read(socket_, buf->data(), buf_len)); | 432 int nread = HANDLE_EINTR(read(socket_, buf->data(), buf_len)); |
433 if (nread >= 0) { | 433 if (nread >= 0) { |
434 base::StatsCounter read_bytes("tcp.read_bytes"); | 434 base::StatsCounter read_bytes("tcp.read_bytes"); |
435 read_bytes.Add(nread); | 435 read_bytes.Add(nread); |
436 if (nread > 0) | 436 if (nread > 0) |
437 use_history_.set_was_used_to_convey_data(); | 437 use_history_.set_was_used_to_convey_data(); |
438 LogByteTransfer( | 438 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread, |
439 net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, nread, buf->data()); | 439 buf->data()); |
440 return nread; | 440 return nread; |
441 } | 441 } |
442 if (errno != EAGAIN && errno != EWOULDBLOCK) { | 442 if (errno != EAGAIN && errno != EWOULDBLOCK) { |
443 DVLOG(1) << "read failed, errno " << errno; | 443 DVLOG(1) << "read failed, errno " << errno; |
444 return MapSystemError(errno); | 444 return MapSystemError(errno); |
445 } | 445 } |
446 | 446 |
447 if (!MessageLoopForIO::current()->WatchFileDescriptor( | 447 if (!MessageLoopForIO::current()->WatchFileDescriptor( |
448 socket_, true, MessageLoopForIO::WATCH_READ, | 448 socket_, true, MessageLoopForIO::WATCH_READ, |
449 &read_socket_watcher_, &read_watcher_)) { | 449 &read_socket_watcher_, &read_watcher_)) { |
(...skipping 17 matching lines...) Expand all Loading... |
467 // Synchronous operation not supported | 467 // Synchronous operation not supported |
468 DCHECK(callback); | 468 DCHECK(callback); |
469 DCHECK_GT(buf_len, 0); | 469 DCHECK_GT(buf_len, 0); |
470 | 470 |
471 int nwrite = InternalWrite(buf, buf_len); | 471 int nwrite = InternalWrite(buf, buf_len); |
472 if (nwrite >= 0) { | 472 if (nwrite >= 0) { |
473 base::StatsCounter write_bytes("tcp.write_bytes"); | 473 base::StatsCounter write_bytes("tcp.write_bytes"); |
474 write_bytes.Add(nwrite); | 474 write_bytes.Add(nwrite); |
475 if (nwrite > 0) | 475 if (nwrite > 0) |
476 use_history_.set_was_used_to_convey_data(); | 476 use_history_.set_was_used_to_convey_data(); |
477 LogByteTransfer( | 477 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, nwrite, |
478 net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, nwrite, buf->data()); | 478 buf->data()); |
479 return nwrite; | 479 return nwrite; |
480 } | 480 } |
481 if (errno != EAGAIN && errno != EWOULDBLOCK) | 481 if (errno != EAGAIN && errno != EWOULDBLOCK) |
482 return MapSystemError(errno); | 482 return MapSystemError(errno); |
483 | 483 |
484 if (!MessageLoopForIO::current()->WatchFileDescriptor( | 484 if (!MessageLoopForIO::current()->WatchFileDescriptor( |
485 socket_, true, MessageLoopForIO::WATCH_WRITE, | 485 socket_, true, MessageLoopForIO::WATCH_WRITE, |
486 &write_socket_watcher_, &write_watcher_)) { | 486 &write_socket_watcher_, &write_watcher_)) { |
487 DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno; | 487 DVLOG(1) << "WatchFileDescriptor failed on write, errno " << errno; |
488 return MapSystemError(errno); | 488 return MapSystemError(errno); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 bytes_transferred = HANDLE_EINTR(read(socket_, read_buf_->data(), | 622 bytes_transferred = HANDLE_EINTR(read(socket_, read_buf_->data(), |
623 read_buf_len_)); | 623 read_buf_len_)); |
624 | 624 |
625 int result; | 625 int result; |
626 if (bytes_transferred >= 0) { | 626 if (bytes_transferred >= 0) { |
627 result = bytes_transferred; | 627 result = bytes_transferred; |
628 base::StatsCounter read_bytes("tcp.read_bytes"); | 628 base::StatsCounter read_bytes("tcp.read_bytes"); |
629 read_bytes.Add(bytes_transferred); | 629 read_bytes.Add(bytes_transferred); |
630 if (bytes_transferred > 0) | 630 if (bytes_transferred > 0) |
631 use_history_.set_was_used_to_convey_data(); | 631 use_history_.set_was_used_to_convey_data(); |
632 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, result, | 632 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, result, |
633 read_buf_->data()); | 633 read_buf_->data()); |
634 } else { | 634 } else { |
635 result = MapSystemError(errno); | 635 result = MapSystemError(errno); |
636 } | 636 } |
637 | 637 |
638 if (result != ERR_IO_PENDING) { | 638 if (result != ERR_IO_PENDING) { |
639 read_buf_ = NULL; | 639 read_buf_ = NULL; |
640 read_buf_len_ = 0; | 640 read_buf_len_ = 0; |
641 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); | 641 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); |
642 DCHECK(ok); | 642 DCHECK(ok); |
643 DoReadCallback(result); | 643 DoReadCallback(result); |
644 } | 644 } |
645 } | 645 } |
646 | 646 |
647 void TCPClientSocketLibevent::DidCompleteWrite() { | 647 void TCPClientSocketLibevent::DidCompleteWrite() { |
648 int bytes_transferred; | 648 int bytes_transferred; |
649 bytes_transferred = HANDLE_EINTR(write(socket_, write_buf_->data(), | 649 bytes_transferred = HANDLE_EINTR(write(socket_, write_buf_->data(), |
650 write_buf_len_)); | 650 write_buf_len_)); |
651 | 651 |
652 int result; | 652 int result; |
653 if (bytes_transferred >= 0) { | 653 if (bytes_transferred >= 0) { |
654 result = bytes_transferred; | 654 result = bytes_transferred; |
655 base::StatsCounter write_bytes("tcp.write_bytes"); | 655 base::StatsCounter write_bytes("tcp.write_bytes"); |
656 write_bytes.Add(bytes_transferred); | 656 write_bytes.Add(bytes_transferred); |
657 if (bytes_transferred > 0) | 657 if (bytes_transferred > 0) |
658 use_history_.set_was_used_to_convey_data(); | 658 use_history_.set_was_used_to_convey_data(); |
659 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, result, | 659 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, result, |
660 write_buf_->data()); | 660 write_buf_->data()); |
661 } else { | 661 } else { |
662 result = MapSystemError(errno); | 662 result = MapSystemError(errno); |
663 } | 663 } |
664 | 664 |
665 if (result != ERR_IO_PENDING) { | 665 if (result != ERR_IO_PENDING) { |
666 write_buf_ = NULL; | 666 write_buf_ = NULL; |
667 write_buf_len_ = 0; | 667 write_buf_len_ = 0; |
668 write_socket_watcher_.StopWatchingFileDescriptor(); | 668 write_socket_watcher_.StopWatchingFileDescriptor(); |
669 DoWriteCallback(result); | 669 DoWriteCallback(result); |
670 } | 670 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 710 |
711 bool TCPClientSocketLibevent::WasEverUsed() const { | 711 bool TCPClientSocketLibevent::WasEverUsed() const { |
712 return use_history_.was_used_to_convey_data(); | 712 return use_history_.was_used_to_convey_data(); |
713 } | 713 } |
714 | 714 |
715 bool TCPClientSocketLibevent::UsingTCPFastOpen() const { | 715 bool TCPClientSocketLibevent::UsingTCPFastOpen() const { |
716 return use_tcp_fastopen_; | 716 return use_tcp_fastopen_; |
717 } | 717 } |
718 | 718 |
719 } // namespace net | 719 } // namespace net |
OLD | NEW |