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

Side by Side Diff: ppapi/cpp/websocket.h

Issue 9813011: Websocket documentation change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« ppapi/api/ppb_websocket.idl ('K') | « ppapi/c/ppb_websocket.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. A <code>PP_ERROR_BADARGUMENT</code>
dmichael (off chromium) 2012/03/23 20:48:15 I don't think we want an article here (or in the o
jond 2012/03/23 21:42:07 Actually, looking at it again, I think I should le
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 /// A <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 /// A <code>PP_ERROR_BADARGUMENT</code> corresponds to a JavaScript
92 /// SyntaxError 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 /// A <code>PP_ERROR_NOACCESS</code> corresponds to InvalidAccessError in the
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 /// A <code>PP_ERROR_FAILED</code> corresponds to the JavaScript
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. A <code>PP_ERROR_BADARGUMENT</code> corresponds to the
140 /// JavaScript SyntaxError in the WebSocket API specification.
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 <code>Var</code>'s data is an empty
162 /// Currently its data is always an empty string. 180 /// string. Returns a <code>PP_VARTYPE_UNDEFINED</code> if called on an
181 /// invalid resource. Currently the <code>Var</code>'s data for valid
182 /// resources are always an empty string.
163 Var GetExtensions(); 183 Var GetExtensions();
164 184
165 /// GetProtocol() returns the sub-protocol chosen by the server for the 185 /// GetProtocol() returns the sub-protocol chosen by the server for the
166 /// specified WebSocket connection. 186 /// specified WebSocket connection.
167 /// 187 ///
168 /// @return Returns a <code>Var</code> of string type. If called before the 188 /// @return Returns a <code>Var</code> of string type. If called before the
169 /// connection is established, it contains the empty string. 189 /// connection is established, the <code>Var</code> contains the empty
190 /// string. Returns a code>PP_VARTYPE_UNDEFINED</code> if called on an
191 /// invalid resource.
170 Var GetProtocol(); 192 Var GetProtocol();
171 193
172 /// GetReadyState() returns the ready state of the specified WebSocket 194 /// GetReadyState() returns the ready state of the specified WebSocket
173 /// connection. 195 /// connection.
174 /// 196 ///
175 /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID</code> if called 197 /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID</code> if called
176 /// before connect() is called. 198 /// before Connect() is called, or if this function is called on an
199 /// invalid resource.
177 PP_WebSocketReadyState GetReadyState(); 200 PP_WebSocketReadyState GetReadyState();
178 201
179 /// GetURL() returns the URL associated with specified WebSocket connection. 202 /// GetURL() returns the URL associated with specified WebSocket connection.
180 /// 203 ///
181 /// @return Returns a <code>Var</code> of string type. If called before the 204 /// @return Returns a <code>Var</code> of string type. If called before the
182 /// connection is established, it contains the empty string. 205 /// connection is established, the <code>Var</code> contains the empty
206 /// string. Returns a <code>PP_VARTYPE_UNDEFINED</code> if this function
207 /// is called on an invalid resource.
183 Var GetURL(); 208 Var GetURL();
184 }; 209 };
185 210
186 } // namespace pp 211 } // namespace pp
187 212
188 #endif // PPAPI_CPP_WEBSOCKET_H_ 213 #endif // PPAPI_CPP_WEBSOCKET_H_
OLDNEW
« ppapi/api/ppb_websocket.idl ('K') | « ppapi/c/ppb_websocket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698