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

Side by Side Diff: remoting/protocol/channel_multiplexer.h

Issue 10830046: Implement ChannelMultiplexer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/channel_factory.h ('k') | remoting/protocol/channel_multiplexer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 the channel upon which to multiplex.
21 ChannelMultiplexer(ChannelFactory* factory,
22 const std::string& base_channel_name);
23 virtual ~ChannelMultiplexer();
24
25 // ChannelFactory interface.
26 virtual void CreateStreamChannel(
27 const std::string& name,
28 const StreamChannelCallback& callback) OVERRIDE;
29 virtual void CreateDatagramChannel(
30 const std::string& name,
31 const DatagramChannelCallback& callback) OVERRIDE;
32 virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
33
34 private:
35 struct PendingChannel;
36 class MuxChannel;
37 class MuxSocket;
38 friend class MuxChannel;
39
40 // Callback for |base_channel_| creation.
41 void OnBaseChannelReady(scoped_ptr<net::StreamSocket> socket);
42
43 // Helper method used to create channels.
44 MuxChannel* GetOrCreateChannel(const std::string& name);
45
46 // Callbacks for |writer_| and |reader_|.
47 void OnWriteFailed(int error);
48 void OnIncomingPacket(scoped_ptr<MultiplexPacket> packet,
49 const base::Closure& done_task);
50
51 // Called by MuxChannel.
52 bool DoWrite(scoped_ptr<MultiplexPacket> packet,
53 const base::Closure& done_task);
54
55 // Factory used to create |base_channel_|. Set to NULL once creation is
56 // finished or failed.
57 ChannelFactory* base_channel_factory_;
58
59 // Name of the underlying channel.
60 std::string base_channel_name_;
61
62 // The channel over which to multiplex.
63 scoped_ptr<net::StreamSocket> base_channel_;
64
65 // List of requested channels while we are waiting for |base_channel_|.
66 std::list<PendingChannel> pending_channels_;
67
68 int next_channel_id_;
69 std::map<std::string, MuxChannel*> channels_;
70
71 // Channels are added to |channels_by_receive_id_| only after we receive
72 // receive_id from the remote peer.
73 std::map<int, MuxChannel*> channels_by_receive_id_;
74
75 BufferedSocketWriter writer_;
76 ProtobufMessageReader<MultiplexPacket> reader_;
77
78 // Flag used by OnWriteFailed() to detect when the multiplexer is destroyed.
79 bool* destroyed_flag_;
80
81 DISALLOW_COPY_AND_ASSIGN(ChannelMultiplexer);
82 };
83
84 } // namespace protocol
85 } // namespace remoting
86
87
88 #endif // REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_
OLDNEW
« no previous file with comments | « remoting/protocol/channel_factory.h ('k') | remoting/protocol/channel_multiplexer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698