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 12 matching lines...) Expand all Loading... | |
23 base::Unretained(this))), | 23 base::Unretained(this))), |
24 read_callback_(base::Bind(&BlimpMessagePump::OnReadPacketComplete, | 24 read_callback_(base::Bind(&BlimpMessagePump::OnReadPacketComplete, |
25 base::Unretained(this))) { | 25 base::Unretained(this))) { |
26 DCHECK(reader_); | 26 DCHECK(reader_); |
27 buffer_->SetCapacity(kMaxPacketPayloadSizeBytes); | 27 buffer_->SetCapacity(kMaxPacketPayloadSizeBytes); |
28 } | 28 } |
29 | 29 |
30 BlimpMessagePump::~BlimpMessagePump() {} | 30 BlimpMessagePump::~BlimpMessagePump() {} |
31 | 31 |
32 void BlimpMessagePump::SetMessageProcessor(BlimpMessageProcessor* processor) { | 32 void BlimpMessagePump::SetMessageProcessor(BlimpMessageProcessor* processor) { |
33 DVLOG(1) << "SetMessageProcessor, processor=" << processor; | |
33 if (processor && !processor_) { | 34 if (processor && !processor_) { |
34 processor_ = processor; | 35 processor_ = processor; |
35 ReadNextPacket(); | 36 ReadNextPacket(); |
36 } else { | 37 } else { |
37 // Don't allow |processor_| to be cleared while there's a read inflight. | 38 // Don't allow |processor_| to be cleared while there's a read inflight. |
38 if (processor) { | 39 if (processor) { |
39 DCHECK(!processor_ || !read_inflight_); | 40 DCHECK(!processor_ || !read_inflight_); |
40 } | 41 } |
41 processor_ = processor; | 42 processor_ = processor; |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 void BlimpMessagePump::ReadNextPacket() { | 46 void BlimpMessagePump::ReadNextPacket() { |
47 DVLOG(2) << "ReadNextPacket"; | |
46 DCHECK(processor_); | 48 DCHECK(processor_); |
47 DCHECK(!read_inflight_); | 49 DCHECK(!read_inflight_); |
48 read_inflight_ = true; | 50 read_inflight_ = true; |
49 buffer_->set_offset(0); | 51 buffer_->set_offset(0); |
50 reader_->ReadPacket(buffer_.get(), read_callback_.callback()); | 52 reader_->ReadPacket(buffer_.get(), read_callback_.callback()); |
51 } | 53 } |
52 | 54 |
53 void BlimpMessagePump::OnReadPacketComplete(int result) { | 55 void BlimpMessagePump::OnReadPacketComplete(int result) { |
56 DVLOG(2) << "OnReadPacketComplete, result=" << result; | |
54 DCHECK(read_inflight_); | 57 DCHECK(read_inflight_); |
55 read_inflight_ = false; | 58 read_inflight_ = false; |
56 if (result == net::OK) { | 59 if (result == net::OK) { |
57 scoped_ptr<BlimpMessage> message(new BlimpMessage); | 60 scoped_ptr<BlimpMessage> message(new BlimpMessage); |
58 if (message->ParseFromArray(buffer_->StartOfBuffer(), buffer_->offset())) { | 61 if (message->ParseFromArray(buffer_->StartOfBuffer(), buffer_->offset())) { |
59 processor_->ProcessMessage(std::move(message), | 62 processor_->ProcessMessage(std::move(message), |
60 process_msg_callback_.callback()); | 63 process_msg_callback_.callback()); |
61 } else { | 64 } else { |
62 result = net::ERR_FAILED; | 65 result = net::ERR_FAILED; |
63 } | 66 } |
64 } | 67 } |
65 | 68 |
66 if (result != net::OK) { | 69 if (result != net::OK) { |
67 error_observer_->OnConnectionError(result); | 70 error_observer_->OnConnectionError(result); |
68 } | 71 } |
69 } | 72 } |
70 | 73 |
71 void BlimpMessagePump::OnProcessMessageComplete(int result) { | 74 void BlimpMessagePump::OnProcessMessageComplete(int result) { |
72 // No error is expected from the message receiver. | 75 DVLOG(2) << "OnProcessMessageComplete, result=" << result; |
73 DCHECK_EQ(net::OK, result); | 76 |
77 if (result != net::OK) { | |
haibinlu
2015/12/29 00:51:45
what causes message process error?
and this is not
Kevin M
2015/12/30 23:08:49
The demux can return ERR_NOT_IMPLEMENTED if there
| |
78 error_observer_->OnConnectionError(result); | |
79 return; | |
80 } | |
81 | |
74 if (processor_) | 82 if (processor_) |
75 ReadNextPacket(); | 83 ReadNextPacket(); |
76 } | 84 } |
77 | 85 |
78 } // namespace blimp | 86 } // namespace blimp |
OLD | NEW |