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

Side by Side Diff: net/tools/quic/quic_simple_server_packet_writer.cc

Issue 2180003004: Remove inability to call QuicSimpleServerPacketWriter::WritePacket directly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months 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
« no previous file with comments | « net/tools/quic/quic_simple_server_packet_writer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/tools/quic/quic_simple_server_packet_writer.h" 5 #include "net/tools/quic/quic_simple_server_packet_writer.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
(...skipping 27 matching lines...) Expand all
38 if (result.status != WRITE_STATUS_BLOCKED) { 38 if (result.status != WRITE_STATUS_BLOCKED) {
39 callback_.Reset(); 39 callback_.Reset();
40 } 40 }
41 return result; 41 return result;
42 } 42 }
43 43
44 void QuicSimpleServerPacketWriter::OnWriteComplete(int rv) { 44 void QuicSimpleServerPacketWriter::OnWriteComplete(int rv) {
45 DCHECK_NE(rv, ERR_IO_PENDING); 45 DCHECK_NE(rv, ERR_IO_PENDING);
46 write_blocked_ = false; 46 write_blocked_ = false;
47 WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv); 47 WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv);
48 base::ResetAndReturn(&callback_).Run(result); 48 if (!callback_.is_null()) {
49 base::ResetAndReturn(&callback_).Run(result);
50 }
49 blocked_writer_->OnCanWrite(); 51 blocked_writer_->OnCanWrite();
50 } 52 }
51 53
52 bool QuicSimpleServerPacketWriter::IsWriteBlockedDataBuffered() const { 54 bool QuicSimpleServerPacketWriter::IsWriteBlockedDataBuffered() const {
53 // UDPServerSocket::SendTo buffers the data until the Write is permitted. 55 // UDPServerSocket::SendTo buffers the data until the Write is permitted.
54 return true; 56 return true;
55 } 57 }
56 58
57 bool QuicSimpleServerPacketWriter::IsWriteBlocked() const { 59 bool QuicSimpleServerPacketWriter::IsWriteBlocked() const {
58 return write_blocked_; 60 return write_blocked_;
59 } 61 }
60 62
61 void QuicSimpleServerPacketWriter::SetWritable() { 63 void QuicSimpleServerPacketWriter::SetWritable() {
62 write_blocked_ = false; 64 write_blocked_ = false;
63 } 65 }
64 66
65 WriteResult QuicSimpleServerPacketWriter::WritePacket( 67 WriteResult QuicSimpleServerPacketWriter::WritePacket(
66 const char* buffer, 68 const char* buffer,
67 size_t buf_len, 69 size_t buf_len,
68 const IPAddress& self_address, 70 const IPAddress& self_address,
69 const IPEndPoint& peer_address, 71 const IPEndPoint& peer_address,
70 PerPacketOptions* options) { 72 PerPacketOptions* options) {
71 scoped_refptr<StringIOBuffer> buf( 73 scoped_refptr<StringIOBuffer> buf(
72 new StringIOBuffer(std::string(buffer, buf_len))); 74 new StringIOBuffer(std::string(buffer, buf_len)));
73 DCHECK(!IsWriteBlocked()); 75 DCHECK(!IsWriteBlocked());
74 DCHECK(!callback_.is_null());
75 int rv; 76 int rv;
76 if (buf_len <= static_cast<size_t>(std::numeric_limits<int>::max())) { 77 if (buf_len <= static_cast<size_t>(std::numeric_limits<int>::max())) {
77 rv = socket_->SendTo( 78 rv = socket_->SendTo(
78 buf.get(), static_cast<int>(buf_len), peer_address, 79 buf.get(), static_cast<int>(buf_len), peer_address,
79 base::Bind(&QuicSimpleServerPacketWriter::OnWriteComplete, 80 base::Bind(&QuicSimpleServerPacketWriter::OnWriteComplete,
80 weak_factory_.GetWeakPtr())); 81 weak_factory_.GetWeakPtr()));
81 } else { 82 } else {
82 rv = ERR_MSG_TOO_BIG; 83 rv = ERR_MSG_TOO_BIG;
83 } 84 }
84 WriteStatus status = WRITE_STATUS_OK; 85 WriteStatus status = WRITE_STATUS_OK;
85 if (rv < 0) { 86 if (rv < 0) {
86 if (rv != ERR_IO_PENDING) { 87 if (rv != ERR_IO_PENDING) {
87 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.WriteError", -rv); 88 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.WriteError", -rv);
88 status = WRITE_STATUS_ERROR; 89 status = WRITE_STATUS_ERROR;
89 } else { 90 } else {
90 status = WRITE_STATUS_BLOCKED; 91 status = WRITE_STATUS_BLOCKED;
91 write_blocked_ = true; 92 write_blocked_ = true;
92 } 93 }
93 } 94 }
94 return WriteResult(status, rv); 95 return WriteResult(status, rv);
95 } 96 }
96 97
97 QuicByteCount QuicSimpleServerPacketWriter::GetMaxPacketSize( 98 QuicByteCount QuicSimpleServerPacketWriter::GetMaxPacketSize(
98 const IPEndPoint& peer_address) const { 99 const IPEndPoint& peer_address) const {
99 return kMaxPacketSize; 100 return kMaxPacketSize;
100 } 101 }
101 102
102 } // namespace net 103 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_packet_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698