OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef PPAPI_CPP_WEBSOCKET_H_ | 5 #ifndef PPAPI_CPP_WEBSOCKET_H_ |
6 #define PPAPI_CPP_WEBSOCKET_H_ | 6 #define PPAPI_CPP_WEBSOCKET_H_ |
7 | 7 |
8 #include "ppapi/c/ppb_websocket.h" | 8 #include "ppapi/c/ppb_websocket.h" |
9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
10 | 10 |
11 /// @file | 11 /// @file |
12 /// This file defines the WebSocket interface. | 12 /// This file defines the WebSocket interface providing bi-directional, |
13 /// full-duplex, communications over a single TCP socket. | |
13 | 14 |
14 namespace pp { | 15 namespace pp { |
15 | 16 |
16 class CompletionCallback; | 17 class CompletionCallback; |
17 class InstanceHandle; | 18 class InstanceHandle; |
18 class Var; | 19 class Var; |
19 | 20 |
20 /// The <code>WebSocket</code> class | 21 /// The <code>WebSocket</code> class providing bi-directional, |
22 /// full-duplex, communications over a single TCP socket. | |
21 class WebSocket : public Resource { | 23 class WebSocket : public Resource { |
22 public: | 24 public: |
23 /// Constructs a WebSocket object. | 25 /// Constructs a WebSocket object. |
24 /// | 26 /// |
25 /// @param[in] instance The instance with which this resource will be | 27 /// @param[in] instance The instance with which this resource will be |
26 /// associated. | 28 /// associated. |
27 explicit WebSocket(const InstanceHandle& instance); | 29 explicit WebSocket(const InstanceHandle& instance); |
28 | 30 |
29 /// Destructs a WebSocket object. | 31 /// Destructs a WebSocket object. |
30 virtual ~WebSocket(); | 32 virtual ~WebSocket(); |
31 | 33 |
32 /// Connect() connects to the specified WebSocket server. Caller can call | 34 /// Connect() connects to the specified WebSocket server. You can call this |
33 /// this method at most once. | 35 /// function once for an object. |
34 /// | 36 /// |
35 /// @param[in] url A <code>Var</code> of string type representing a WebSocket | 37 /// @param[in] url A <code>Var</code> of string type representing a WebSocket |
36 /// server URL. | 38 /// server URL. |
37 /// @param[in] protocols A pointer to an array of string type | 39 /// |
38 /// <code>Var</code> specifying sub-protocols. Each <code>Var</code> | 40 /// @param[in] protocols A pointer to an array of <code>Var</code> of string |
39 /// represents one sub-protocol. This argument can be null only if | 41 /// type specifying sub-protocols. Each <code>Var</code> represents one |
42 /// sub-protocol. This argument can be null only if | |
40 /// <code>protocol_count</code> is 0. | 43 /// <code>protocol_count</code> is 0. |
44 /// | |
41 /// @param[in] protocol_count The number of sub-protocols in | 45 /// @param[in] protocol_count The number of sub-protocols in |
42 /// <code>protocols</code>. | 46 /// <code>protocols</code>. |
43 /// @param[in] callback A <code>CompletionCallback</code> which is called | 47 /// |
48 /// @param[in] callback A <code>CompletionCallback</code> called | |
44 /// when a connection is established or an error occurs in establishing | 49 /// when a connection is established or an error occurs in establishing |
45 /// connection. | 50 /// connection. |
46 /// | 51 /// |
47 /// @return An int32_t containing an error code from | 52 /// @return An int32_t containing an error code from |
48 /// <code>pp_errors.h</code>. | 53 /// <code>pp_errors.h</code>. |
49 /// Returns <code>PP_ERROR_BADARGUMENT</code> if specified <code>url</code>, | 54 /// Returns <code>PP_ERROR_BADARGUMENT</code> if specified <code>url</code>, |
50 /// or <code>protocols</code> contains invalid string as | 55 /// or <code>protocols</code> contains invalid string as defined in |
51 /// <code>The WebSocket API specification</code> defines. It corresponds to | 56 /// the WebSocket API specification. <code>PP_ERROR_BADARGUMENT</code> |
52 /// SyntaxError of the specification. | 57 /// corresponds to a SyntaxError in the WebSocket API specification. |
53 /// Returns <code>PP_ERROR_NOACCESS</code> if the protocol specified in the | 58 /// Returns <code>PP_ERROR_NOACCESS</code> if the protocol specified in the |
54 /// <code>url</code> is not a secure protocol, but the origin of the caller | 59 /// <code>url</code> is not a secure protocol, but the origin of the caller |
55 /// has a secure scheme. Also returns it if the port specified in the | 60 /// has a secure scheme. Also returns <code>PP_ERROR_NOACCESS</code> if the |
56 /// <code>url</code> is a port to which the user agent is configured to block | 61 /// port specified in the <code>url</code> is a port that the user agent is |
57 /// access because the port is a well-known port like SMTP. It corresponds to | 62 /// configured to block access to because it is a well-known port like SMTP. |
58 /// SecurityError of the specification. | 63 /// <code>PP_ERROR_NOACCESS</code> corresponds to SecurityError of the |
59 /// Returns <code>PP_ERROR_INPROGRESS</code> if the call is not the first | 64 /// specification. |
60 /// time. | 65 /// Returns <code>PP_ERROR_INPROGRESS</code> if this is not the first call to |
66 /// Connect(). | |
61 int32_t Connect(const Var& url, const Var protocols[], | 67 int32_t Connect(const Var& url, const Var protocols[], |
62 uint32_t protocol_count, const CompletionCallback& callback); | 68 uint32_t protocol_count, const CompletionCallback& callback); |
63 | 69 |
64 /// Close() closes the specified WebSocket connection by specifying | 70 /// Close() closes the specified WebSocket connection by specifying |
65 /// <code>code</code> and <code>reason</code>. | 71 /// <code>code</code> and <code>reason</code>. |
66 /// | 72 /// |
67 /// @param[in] code The WebSocket close code. Ignored if it is 0. | 73 /// @param[in] code The WebSocket close code. This is ignored if it is 0. |
68 /// @param[in] reason A <code>Var</code> of string type which represents the | 74 /// <code>PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE</code> must be used for the |
69 /// WebSocket close reason. Ignored if it is undefined type. | 75 /// usual case. To indicate some specific error cases, codes in the range |
70 /// @param[in] callback A <code>CompletionCallback</code> which is called | 76 /// <code>PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN</code> to |
71 /// when the connection is closed or an error occurs in closing the | 77 /// <code>PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MAX</code>, and in the range |
72 /// connection. | 78 /// <code>PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MIN</code> to |
79 /// <code>PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX</code> are available. | |
80 /// | |
81 /// @param[in] reason A <code>Var</code> of string type representing the | |
82 /// close reason. This is ignored if it is an undefined type. | |
83 /// | |
84 /// @param[in] callback A <code>CompletionCallback</code> called when the | |
85 /// connection is closed or an error occurs in closing the connection. | |
73 /// | 86 /// |
74 /// @return An int32_t containing an error code from | 87 /// @return An int32_t containing an error code from |
75 /// <code>pp_errors.h</code>. | 88 /// <code>pp_errors.h</code>. |
76 /// Returns <code>PP_ERROR_BADARGUMENT</code> if <code>reason</code> contains | 89 /// Returns <code>PP_ERROR_BADARGUMENT</code> if <code>reason</code> contains |
77 /// an invalid character as a UTF-8 string, or longer than 123 bytes. It | 90 /// an invalid character as a UTF-8 string, or is longer than 123 bytes. |
78 /// corresponds to JavaScript SyntaxError of the specification. | 91 /// <code>PP_ERROR_BADARGUMENT</code> corresponds to a JavaScript SyntaxError |
92 /// in the WebSocket API specification. | |
79 /// Returns <code>PP_ERROR_NOACCESS</code> if the code is not an integer | 93 /// Returns <code>PP_ERROR_NOACCESS</code> if the code is not an integer |
80 /// equal to 1000 or in the range 3000 to 4999. It corresponds to | 94 /// equal to 1000 or in the range 3000 to 4999. |
81 /// InvalidAccessError of the specification. Returns | 95 /// <code>PP_ERROR_NOACCESS</code> corresponds to InvalidAccessError in the |
Takashi Toyoshima
2012/03/21 17:36:40
It's my original fault, but I need 'a' before Inva
jond
2012/03/23 19:31:52
Done.
dmichael (off chromium)
2012/03/23 20:48:15
I'm pretty sure toyoshim meant you need "an" befor
jond
2012/03/23 21:42:07
I'm going to leave it off.
On 2012/03/23 20:48:15
Takashi Toyoshima
2012/03/26 08:14:05
Agreed.
Actually, the article is too difficult to
jond
2012/03/26 15:53:49
Done.
| |
82 /// <code>PP_ERROR_INPROGRESS</code> if the call is not the first time. | 96 /// WebSocket API specification. Returns <code>PP_ERROR_INPROGRESS</code> |
97 /// if this is not the first call to Close(). | |
83 int32_t Close(uint16_t code, const Var& reason, | 98 int32_t Close(uint16_t code, const Var& reason, |
84 const CompletionCallback& callback); | 99 const CompletionCallback& callback); |
85 | 100 |
86 /// ReceiveMessage() receives a message from the WebSocket server. | 101 /// ReceiveMessage() receives a message from the WebSocket server. |
87 /// This interface only returns a single message. That is, this interface | 102 /// This interface only returns a single message. That is, this interface |
88 /// must be called at least N times to receive N messages, no matter how | 103 /// must be called at least N times to receive N messages, no matter the size |
89 /// small each message is. | 104 /// of each message. |
90 /// | 105 /// |
91 /// @param[out] message The received message is copied to provided | 106 /// @param[out] message The received message is copied to provided |
92 /// <code>message</code>. The <code>message</code> must remain valid until | 107 /// <code>message</code>. The <code>message</code> must remain valid until |
93 /// the ReceiveMessage operation completes. It will be a <code>Var</code> of | 108 /// ReceiveMessage() completes. Its received <code>Var</code> will be of |
94 /// string or ArrayBuffer types on receiving. | 109 /// string or ArrayBuffer type. |
95 /// @param[in] callback A <code>CompletionCallback</code> which is called | 110 /// |
96 /// when the receiving message is completed. It is ignored if ReceiveMessage | 111 /// @param[in] callback A <code>CompletionCallback</code> called when |
112 /// ReceiveMessage() completes. This callback is ignored if ReceiveMessage() | |
97 /// completes synchronously and returns <code>PP_OK</code>. | 113 /// completes synchronously and returns <code>PP_OK</code>. |
98 /// | 114 /// |
99 /// @return An int32_t containing an error code from | 115 /// @return An int32_t containing an error code from |
100 /// <code>pp_errors.h</code>. | 116 /// <code>pp_errors.h</code>. |
101 /// If an error is detected or connection is closed, returns | 117 /// If an error is detected or connection is closed, ReceiveMessage() returns |
102 /// <code>PP_ERROR_FAILED</code> after all buffered messages are received. | 118 /// <code>PP_ERROR_FAILED</code> after all buffered messages are received. |
103 /// Until buffered message become empty, continues to returns | 119 /// Until buffered message become empty, ReceiveMessage() continues to return |
104 /// <code>PP_OK</code> as if connection is still established without errors. | 120 /// <code>PP_OK</code> as if connection is still established without errors. |
105 int32_t ReceiveMessage(Var* message, | 121 int32_t ReceiveMessage(Var* message, |
106 const CompletionCallback& callback); | 122 const CompletionCallback& callback); |
107 | 123 |
108 /// Send() sends a message to the WebSocket server. | 124 /// SendMessage() sends a message to the WebSocket server. |
109 /// | 125 /// |
110 /// @param[in] data A message to send. The message is copied to internal | 126 /// @param[in] message A message to send. The message is copied to an internal |
111 /// buffer. So caller can free <code>data</code> safely after returning | 127 /// buffer, so the caller can free <code>message</code> safely after returning |
112 /// from the function. It must be a <code>Var</code> of string or ArrayBuffer | 128 /// from the function. This <code>Var</code> must be of string or |
113 /// types. | 129 /// ArrayBuffer types. |
114 /// | 130 /// |
115 /// @return An int32_t containing an error code from | 131 /// @return An int32_t containing an error code from |
116 /// <code>pp_errors.h</code>. | 132 /// <code>pp_errors.h</code>. |
117 /// Returns <code>PP_ERROR_FAILED</code> if the ReadyState is | 133 /// Returns <code>PP_ERROR_FAILED</code> if the ReadyState is |
118 /// <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code>. It corresponds JavaScript | 134 /// <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code>. |
119 /// InvalidStateError of the specification. | 135 /// <code>PP_ERROR_FAILED</code> corresponds to the JavaScript |
Takashi Toyoshima
2012/03/21 17:36:40
the -> a ?
jond
2012/03/23 19:31:52
Done.
dmichael (off chromium)
2012/03/23 20:48:15
toyoshim was suggesting you change "the" to "a". M
jond
2012/03/23 21:42:07
Done.
| |
120 /// Returns <code>PP_ERROR_BADARGUMENT</code> if provided | 136 /// InvalidStateError in the WebSocket API specification. |
121 /// <code>message</code> of string type contains an invalid character as a | 137 /// Returns <code>PP_ERROR_BADARGUMENT</code> if the provided |
122 /// UTF-8 string. It corresponds to JavaScript SyntaxError of the | 138 /// <code>message</code> contains an invalid character as a |
123 /// specification. | 139 /// UTF-8 string. <code>PP_ERROR_BADARGUMENT</code> corresponds to the |
140 /// JavaScript SyntaxError in the WebSocket API specification. | |
Takashi Toyoshima
2012/03/21 17:36:40
ditto
jond
2012/03/23 19:31:52
Done.
| |
124 /// Otherwise, returns <code>PP_OK</code>, but it doesn't necessarily mean | 141 /// Otherwise, returns <code>PP_OK</code>, but it doesn't necessarily mean |
125 /// that the server received the message. | 142 /// that the server received the message. |
126 int32_t SendMessage(const Var& message); | 143 int32_t SendMessage(const Var& message); |
127 | 144 |
128 /// GetBufferedAmount() returns the number of bytes of text and binary | 145 /// GetBufferedAmount() returns the number of bytes of text and binary |
129 /// messages that have been queued for the WebSocket connection to send but | 146 /// messages that have been queued for the WebSocket connection to send, but |
130 /// have not been transmitted to the network yet. | 147 /// have not been transmitted to the network yet. |
131 /// | 148 /// |
132 /// @return Returns the number of bytes. | 149 /// @return Returns the number of bytes. |
133 uint64_t GetBufferedAmount(); | 150 uint64_t GetBufferedAmount(); |
134 | 151 |
135 /// GetCloseCode() returns the connection close code for the WebSocket | 152 /// GetCloseCode() returns the connection close code for the WebSocket |
136 /// connection. | 153 /// connection. |
137 /// | 154 /// |
138 /// @return Returns 0 if called before the close code is set. | 155 /// @return Returns 0 if called before the close code is set. |
139 uint16_t GetCloseCode(); | 156 uint16_t GetCloseCode(); |
140 | 157 |
141 /// GetCloseReason() returns the connection close reason for the WebSocket | 158 /// GetCloseReason() returns the connection close reason for the WebSocket |
142 /// connection. | 159 /// connection. |
143 /// | 160 /// |
144 /// @return Returns a <code>Var</code> of string type. If called before the | 161 /// @return Returns a <code>Var</code> of string type. If called before the |
145 /// close reason is set, it contains an empty string. | 162 /// close reason is set, the return value contains an empty string. Returns a |
163 /// <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. | |
146 Var GetCloseReason(); | 164 Var GetCloseReason(); |
147 | 165 |
148 /// GetCloseWasClean() returns if the connection was closed cleanly for the | 166 /// GetCloseWasClean() returns if the connection was closed cleanly for the |
149 /// specified WebSocket connection. | 167 /// specified WebSocket connection. |
150 /// | 168 /// |
151 /// @return Returns <code>false</code> if called before the connection is | 169 /// @return Returns <code>false</code> if called before the connection is |
152 /// closed, or called on an invalid resource. Otherwise, returns | 170 /// closed, called on an invalid resource, or closed for abnormal reasons. |
153 /// <code>true</code> if the connection was closed cleanly, or returns | 171 /// Otherwise, returns <code>true</code> if the connection was closed |
154 /// <code>false</code> if the connection was closed for abnormal reasons. | 172 /// cleanly. |
155 bool GetCloseWasClean(); | 173 bool GetCloseWasClean(); |
156 | 174 |
157 /// GetExtensions() returns the extensions selected by the server for the | 175 /// GetExtensions() returns the extensions selected by the server for the |
158 /// specified WebSocket connection. | 176 /// specified WebSocket connection. |
159 /// | 177 /// |
160 /// @return Returns a <code>Var</code> of string type. If called before the | 178 /// @return Returns a <code>Var</code> of string type. If called before the |
161 /// connection is established, its data is an empty string. | 179 /// connection is established, the var's data is an empty string.Returns a |
Takashi Toyoshima
2012/03/21 17:36:40
<code>Var</code>'s is better?
This term 'Var' is c
jond
2012/03/23 19:31:52
Done.
| |
162 /// Currently its data is always an empty string. | 180 /// <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. |
181 /// Currently the var's data for valid resources are always an empty string. | |
Takashi Toyoshima
2012/03/21 17:36:40
ditto
jond
2012/03/23 19:31:52
Done.
| |
163 Var GetExtensions(); | 182 Var GetExtensions(); |
164 | 183 |
165 /// GetProtocol() returns the sub-protocol chosen by the server for the | 184 /// GetProtocol() returns the sub-protocol chosen by the server for the |
166 /// specified WebSocket connection. | 185 /// specified WebSocket connection. |
167 /// | 186 /// |
168 /// @return Returns a <code>Var</code> of string type. If called before the | 187 /// @return Returns a <code>Var</code> of string type. If called before the |
169 /// connection is established, it contains the empty string. | 188 /// connection is established, the var contains the empty string. Returns a |
Takashi Toyoshima
2012/03/21 17:36:40
ditto
jond
2012/03/23 19:31:52
Done.
| |
189 // <code>PP_VARTYPE_UNDEFINED</code> if called on an invalid resource. | |
170 Var GetProtocol(); | 190 Var GetProtocol(); |
171 | 191 |
172 /// GetReadyState() returns the ready state of the specified WebSocket | 192 /// GetReadyState() returns the ready state of the specified WebSocket |
173 /// connection. | 193 /// connection. |
174 /// | 194 /// |
175 /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID</code> if called | 195 /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID</code> if called |
176 /// before connect() is called. | 196 /// before Connect() is called, or if this function is called on an |
197 /// invalid resource. | |
177 PP_WebSocketReadyState GetReadyState(); | 198 PP_WebSocketReadyState GetReadyState(); |
178 | 199 |
179 /// GetURL() returns the URL associated with specified WebSocket connection. | 200 /// GetURL() returns the URL associated with specified WebSocket connection. |
180 /// | 201 /// |
181 /// @return Returns a <code>Var</code> of string type. If called before the | 202 /// @return Returns a <code>Var</code> of string type. If called before the |
182 /// connection is established, it contains the empty string. | 203 /// connection is established, the var contains the empty string. Returns a |
Takashi Toyoshima
2012/03/21 17:36:40
ditto
jond
2012/03/23 19:31:52
Done.
| |
204 /// <code>PP_VARTYPE_UNDEFINED</code> if this function is called on an | |
205 /// invalid resource. | |
183 Var GetURL(); | 206 Var GetURL(); |
184 }; | 207 }; |
185 | 208 |
186 } // namespace pp | 209 } // namespace pp |
187 | 210 |
188 #endif // PPAPI_CPP_WEBSOCKET_H_ | 211 #endif // PPAPI_CPP_WEBSOCKET_H_ |
OLD | NEW |