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/blimp_message_pump.h" | 5 #include "blimp/net/blimp_message_pump.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "blimp/common/proto/blimp_message.pb.h" | 8 #include "blimp/common/proto/blimp_message.pb.h" |
9 #include "blimp/net/blimp_message_processor.h" | 9 #include "blimp/net/blimp_message_processor.h" |
10 #include "blimp/net/common.h" | 10 #include "blimp/net/common.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 buffer_->SetCapacity(kMaxPacketPayloadSizeBytes); | 33 buffer_->SetCapacity(kMaxPacketPayloadSizeBytes); |
34 ReadNextPacket(); | 34 ReadNextPacket(); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 void BlimpMessagePump::ReadNextPacket() { | 38 void BlimpMessagePump::ReadNextPacket() { |
39 DCHECK(processor_); | 39 DCHECK(processor_); |
40 buffer_->set_offset(0); | 40 buffer_->set_offset(0); |
41 read_packet_callback_.Reset(base::Bind( | 41 read_packet_callback_.Reset(base::Bind( |
42 &BlimpMessagePump::OnReadPacketComplete, base::Unretained(this))); | 42 &BlimpMessagePump::OnReadPacketComplete, base::Unretained(this))); |
43 int result = | 43 reader_->ReadPacket(buffer_.get(), read_packet_callback_.callback()); |
44 reader_->ReadPacket(buffer_.get(), read_packet_callback_.callback()); | |
45 if (result != net::ERR_IO_PENDING) { | |
46 // Read completed synchronously. | |
47 OnReadPacketComplete(result); | |
48 } | |
49 } | 44 } |
50 | 45 |
51 void BlimpMessagePump::OnReadPacketComplete(int result) { | 46 void BlimpMessagePump::OnReadPacketComplete(int result) { |
52 if (result > 0) { | 47 if (result == net::OK) { |
53 // The result is the size of the packet in bytes. | 48 // The result is the size of the packet in bytes. |
haibinlu
2015/11/25 19:10:33
so, ReadPacket no longer returns the size of the p
Kevin M
2015/11/30 19:25:14
The interface was changed in response to feedback
| |
54 scoped_ptr<BlimpMessage> message(new BlimpMessage); | 49 scoped_ptr<BlimpMessage> message(new BlimpMessage); |
55 bool parse_result = | 50 bool parse_result = |
56 message->ParseFromArray(buffer_->StartOfBuffer(), result); | 51 message->ParseFromArray(buffer_->StartOfBuffer(), buffer_->offset()); |
57 if (parse_result) { | 52 if (parse_result) { |
58 process_msg_callback_.Reset(base::Bind( | 53 process_msg_callback_.Reset(base::Bind( |
59 &BlimpMessagePump::OnProcessMessageComplete, base::Unretained(this))); | 54 &BlimpMessagePump::OnProcessMessageComplete, base::Unretained(this))); |
60 processor_->ProcessMessage(message.Pass(), | 55 processor_->ProcessMessage(message.Pass(), |
61 process_msg_callback_.callback()); | 56 process_msg_callback_.callback()); |
62 return; | 57 return; |
63 } | 58 } |
64 result = net::ERR_FAILED; | 59 result = net::ERR_FAILED; |
65 } | 60 } |
61 | |
62 // Error reporting. | |
63 DCHECK_NE(net::OK, result); | |
haibinlu
2015/11/25 19:10:33
is this obviously true?
Kevin M
2015/11/30 19:25:14
Yes - the only success case returns out of the fun
| |
66 if (error_observer_) | 64 if (error_observer_) |
67 error_observer_->OnConnectionError(result); | 65 error_observer_->OnConnectionError(result); |
68 } | 66 } |
69 | 67 |
70 void BlimpMessagePump::OnProcessMessageComplete(int result) { | 68 void BlimpMessagePump::OnProcessMessageComplete(int result) { |
71 // No error is expected from the message receiver. | 69 // No error is expected from the message receiver. |
72 DCHECK_EQ(result, net::OK); | 70 DCHECK_EQ(result, net::OK); |
Wez
2015/11/25 02:21:28
nit: DCHECK_EQ(net::OK, result)
Kevin M
2015/11/30 19:25:14
Done.
| |
73 ReadNextPacket(); | 71 ReadNextPacket(); |
74 } | 72 } |
75 | 73 |
76 } // namespace blimp | 74 } // namespace blimp |
OLD | NEW |