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

Side by Side Diff: remoting/host/websocket_connection.h

Issue 11358190: Add simple WebSocket server implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
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_HOST_WEBSOCKET_CONNECTION_H_
6 #define REMOTING_HOST_WEBSOCKET_CONNECTION_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "remoting/base/socket_reader.h"
15 #include "remoting/protocol/buffered_socket_writer.h"
16
17 namespace net {
18 class StreamSocket;
19 } // namespace net
20
21 namespace remoting {
22
23 class WebsocketConnection {
24 public:
25 typedef base::Callback<void (bool connected)> ConnectedCallback;
26 class Delegate {
27 public:
28 virtual void OnWebsocketMessage(const std::string& message) = 0;
29 virtual void OnWebsocketClosed() = 0;
30 };
31
32 // Creates new web-socket using. |socket| specifies accepted transport socket.
33 // |connected_callback| is called when handshake finishes or connection fails.
Wez 2012/11/15 02:28:37 Please reword this comment. :)
Sergey Ulanov 2012/11/15 21:01:03 Just removed it. No, I wasn't drunk when writing i
Wez 2012/11/20 05:44:09 :D
34 WebsocketConnection();
35 virtual ~WebsocketConnection();
36
37 // Initialize WebSocket connection for the specified |socket|.
Wez 2012/11/15 02:28:37 nit: You're calling it WebSocket here, but the cla
Sergey Ulanov 2012/11/15 21:01:03 WebSocket is the name of the protocol. For type na
Wez 2012/11/20 05:44:09 I think in this case WebSocket fits the style guid
Sergey Ulanov 2012/11/21 01:40:24 Ok. Renamed everything to WebSocket.
38 // |connected_callback| is called after handshake headers have been received
39 // from the client and parsed or when the connection terminated.
40 void Start(scoped_ptr<net::StreamSocket> socket,
41 ConnectedCallback connected_callback);
42
43 const std::string& request_path() { return request_path_; }
44 const std::string& request_host() { return request_host_; }
45 const std::string& origin() { return origin_; }
Wez 2012/11/15 02:28:37 nit: Add a short comment to explain these getters.
Sergey Ulanov 2012/11/15 21:01:03 Done.
46
47 void Accept(Delegate* delegate);
48 void Reject();
49
50 void SendText(const std::string& text);
Wez 2012/11/15 02:28:37 If this implementation only supports text frames,
Sergey Ulanov 2012/11/15 21:01:03 Done. According to RFC the only difference between
51 void Close();
Wez 2012/11/15 02:28:37 nit: Add short comments to explain these methods.
Sergey Ulanov 2012/11/15 21:01:03 Done.
52
53 private:
54 enum State {
55 READING_HEADERS,
56 HEADERS_READ,
57 ACCEPTED,
58 CLOSED,
59 };
60
61 enum WebsocketOpcode {
62 OPCODE_CONTINUATION = 0,
63 OPCODE_TEXT_FRAME = 1,
64 OPCODE_BINARY_FRAME = 2,
65 OPCODE_CLOSE = 8,
66 OPCODE_PING = 9,
67 OPCODE_PONG = 10,
68 };
69
70 void CloseOnError();
71 void OnSocketReadResult(scoped_refptr<net::IOBuffer> data, int size);
72 bool ParseHeaders();
73 void ProcessData();
74
75 void OnSocketWriteError(int error);
76 void SendFragment(WebsocketOpcode opcode,
77 const char* payload, int payload_length);
78
79 void UnmaskPayload(const char* mask, char* payload, int payload_length);
Wez 2012/11/15 02:28:37 Again, short comments for each method, please.
Sergey Ulanov 2012/11/15 21:01:03 Done.
80
81 scoped_ptr<net::StreamSocket> socket_;
82 ConnectedCallback connected_callback_;
83 Delegate* delegate_;
84 SocketReader reader_;
85 protocol::BufferedSocketWriter writer_;
86 State state_;
87 std::string headers_;
88
89 std::string request_path_;
90 std::string request_host_;
91 std::string origin_;
92 std::string websocket_key_;
93
94 std::string current_packet_;
Wez 2012/11/15 02:28:37 nit: Add a comment to this field, esp given the si
Sergey Ulanov 2012/11/15 21:01:03 Done. Also renamed it to |received_data_|
95
96 // Used to assemble fragmented message.
97 bool receiving_message_;
98 std::string current_message_;
99
100 base::WeakPtrFactory<WebsocketConnection> weak_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(WebsocketConnection);
103 };
104
105 } // namespace remoting
106
107 #endif // REMOTING_HOST_WEBSOCKET_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/websocket_connection.cc » ('j') | remoting/host/websocket_listener.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698