OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/net/stream_packet_writer.h" | 5 #include "blimp/net/stream_packet_writer.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 StreamPacketWriter::~StreamPacketWriter() {} | 48 StreamPacketWriter::~StreamPacketWriter() {} |
49 | 49 |
50 void StreamPacketWriter::WritePacket(scoped_refptr<net::DrainableIOBuffer> data, | 50 void StreamPacketWriter::WritePacket(scoped_refptr<net::DrainableIOBuffer> data, |
51 const net::CompletionCallback& callback) { | 51 const net::CompletionCallback& callback) { |
52 DCHECK_EQ(WriteState::IDLE, write_state_); | 52 DCHECK_EQ(WriteState::IDLE, write_state_); |
53 DCHECK(data); | 53 DCHECK(data); |
54 CHECK(data->BytesRemaining()); | 54 CHECK(data->BytesRemaining()); |
55 | 55 |
56 write_state_ = WriteState::HEADER; | 56 write_state_ = WriteState::HEADER; |
57 header_buffer_->SetOffset(0); | 57 header_buffer_->SetOffset(0); |
58 *reinterpret_cast<uint32*>(header_buffer_->data()) = | 58 *reinterpret_cast<uint32_t*>(header_buffer_->data()) = |
59 base::HostToNet32(data->BytesRemaining()); | 59 base::HostToNet32(data->BytesRemaining()); |
60 payload_buffer_ = data; | 60 payload_buffer_ = data; |
61 | 61 |
62 int result = DoWriteLoop(net::OK); | 62 int result = DoWriteLoop(net::OK); |
63 if (result != net::ERR_IO_PENDING) { | 63 if (result != net::ERR_IO_PENDING) { |
64 // Release the payload buffer, since the write operation has completed | 64 // Release the payload buffer, since the write operation has completed |
65 // synchronously. | 65 // synchronously. |
66 payload_buffer_ = nullptr; | 66 payload_buffer_ = nullptr; |
67 | 67 |
68 // Adapt synchronous completion to an asynchronous style. | 68 // Adapt synchronous completion to an asynchronous style. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 // If the write finished, either successfully or by error, inform the | 142 // If the write finished, either successfully or by error, inform the |
143 // caller. | 143 // caller. |
144 if (result != net::ERR_IO_PENDING) { | 144 if (result != net::ERR_IO_PENDING) { |
145 payload_buffer_ = nullptr; | 145 payload_buffer_ = nullptr; |
146 base::ResetAndReturn(&callback_).Run(result); | 146 base::ResetAndReturn(&callback_).Run(result); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 } // namespace blimp | 150 } // namespace blimp |
OLD | NEW |