OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ | |
6 #define REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ | |
7 | |
8 #include "remoting/proto/mux.pb.h" | |
9 #include "remoting/protocol/buffered_socket_writer.h" | |
10 #include "remoting/protocol/channel_factory.h" | |
11 #include "remoting/protocol/message_reader.h" | |
12 | |
13 namespace remoting { | |
14 namespace protocol { | |
15 | |
16 class ChannelMultiplexer : public ChannelFactory { | |
17 public: | |
18 static const char kMuxChannelName[]; | |
19 | |
20 // |factory| is used to create underlying sockets. | |
Wez
2012/08/06 23:14:07
nit: You mean it's used to create the channel(s) u
Sergey Ulanov
2012/08/07 20:12:22
Done.
| |
21 ChannelMultiplexer(ChannelFactory* factory); | |
Wez
2012/08/06 23:14:07
nit: Allow the multiplex channel name (or channel
Sergey Ulanov
2012/08/07 20:12:22
Done.
| |
22 virtual ~ChannelMultiplexer(); | |
23 | |
24 virtual void CreateStreamChannel( | |
Wez
2012/08/06 23:14:07
nit: Precede with comment "ChannelFactory interfac
Sergey Ulanov
2012/08/07 20:12:22
Done.
| |
25 const std::string& name, | |
26 const StreamChannelCallback& callback) OVERRIDE; | |
27 virtual void CreateDatagramChannel( | |
28 const std::string& name, | |
29 const DatagramChannelCallback& callback) OVERRIDE; | |
30 | |
31 private: | |
32 struct PendingChannel; | |
33 class MuxChannel; | |
34 class MuxSocket; | |
35 friend class MuxChannel; | |
36 | |
37 void OnBaseChannelReady(scoped_ptr<net::StreamSocket> socket); | |
38 MuxChannel* GetOrCreateChannel(const std::string& name); | |
39 | |
40 void OnWriteFailed(int error); | |
41 void OnIncomingPacket(scoped_ptr<MuxPacket> packet, | |
42 const base::Closure& done_task); | |
43 // Called by MuxChannel. | |
Wez
2012/08/06 23:14:07
nit: Why is there a comment on this method, but no
Sergey Ulanov
2012/08/07 20:12:22
Done.
| |
44 void DoWrite(scoped_ptr<MuxPacket> packet, const base::Closure& done_task); | |
45 | |
46 // The underlying socket. | |
Wez
2012/08/06 23:14:07
nit: The channel over which to multiplex?
Sergey Ulanov
2012/08/07 20:12:22
Done.
| |
47 scoped_ptr<net::StreamSocket> base_channel_; | |
48 | |
49 // True if creation of |base_channel_| has failed. | |
50 bool base_channel_failed_; | |
51 | |
52 // List of requested channels while we are waiting for |base_channel_|. | |
53 std::list<PendingChannel> pending_channels_; | |
54 | |
55 int next_channel_id_; | |
56 std::map<std::string, MuxChannel*> channels_; | |
Wez
2012/08/06 23:14:07
nit: channels_by_name_
Sergey Ulanov
2012/08/07 20:12:22
I think the current naming is better because it ma
| |
57 std::map<int, MuxChannel*> channels_by_remote_id_; | |
Wez
2012/08/06 23:14:07
nit: channels_by_id_
Wez
2012/08/06 23:14:07
nit: Why map name->channel and id->channel rather
Sergey Ulanov
2012/08/07 20:12:22
that would be confusing because each channel has t
Sergey Ulanov
2012/08/07 20:12:22
initially, when a channel is created, we don't kno
Wez
2012/08/07 21:44:44
You've renamed the id in MuxChannel to receive_id,
Wez
2012/08/07 21:44:44
I see what you mean. I'm beginning to wonder wheth
Sergey Ulanov
2012/08/07 22:25:14
I renamed it to channels_by_receive_id_
| |
58 | |
59 BufferedSocketWriter writer_; | |
60 ProtobufMessageReader<MuxPacket> reader_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(ChannelMultiplexer); | |
63 }; | |
64 | |
65 } // namespace protocol | |
66 } // namespace remoting | |
67 | |
68 | |
69 #endif // REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_ | |
OLD | NEW |