OLD | NEW |
---|---|
1 /* Copyright 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright 2013 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 | 5 |
6 /** | 6 /** |
7 * This file defines the <code>PPB_UDPSocket_Dev</code> interface. | 7 * This file defines the <code>PPB_UDPSocket_Dev</code> interface. |
8 * TODO(yzshen): Tidy up the document. | |
9 */ | 8 */ |
10 | 9 |
11 [generate_thunk] | 10 [generate_thunk] |
12 | 11 |
13 label Chrome { | 12 label Chrome { |
14 M29 = 0.1 | 13 M29 = 0.1 |
15 }; | 14 }; |
16 | 15 |
16 /** | |
17 * Option types used by <code>SetOption()</code>. | |
18 */ | |
17 [assert_size(4)] | 19 [assert_size(4)] |
18 enum PP_UDPSocket_Option_Dev { | 20 enum PP_UDPSocket_Option_Dev { |
19 // Allows the socket to share the local address to which it will be bound with | 21 /** |
20 // other processes. Value's type should be PP_VARTYPE_BOOL. | 22 * Allows the socket to share the local address to which it will be bound with |
23 * other processes. Value's type should be <code>PP_VARTYPE_BOOL</code>. | |
24 * This option can only be set before calling <code>Bind()</code>. | |
25 */ | |
21 PP_UDPSOCKET_OPTION_ADDRESS_REUSE = 0, | 26 PP_UDPSOCKET_OPTION_ADDRESS_REUSE = 0, |
22 | 27 |
23 // Allows sending and receiving packets to and from broadcast addresses. | 28 /** |
24 // Value's type should be PP_VARTYPE_BOOL. | 29 * Allows sending and receiving packets to and from broadcast addresses. |
30 * Value's type should be <code>PP_VARTYPE_BOOL</code>. | |
31 * This option can only be set before calling <code>Bind()</code>. | |
32 */ | |
25 PP_UDPSOCKET_OPTION_BROADCAST = 1, | 33 PP_UDPSOCKET_OPTION_BROADCAST = 1, |
26 | 34 |
27 // Specifies the total per-socket buffer space reserved for sends. Value's | 35 /** |
28 // type should be PP_VARTYPE_INT32. | 36 * Specifies the total per-socket buffer space reserved for sends. Value's |
29 // Note: This is only treated as a hint for the browser to set the buffer | 37 * type should be <code>PP_VARTYPE_INT32</code>. |
30 // size. Even if SetOption() reports that this option has been successfully | 38 * This option can only be set after a successful <code>Bind()</code> call. |
31 // set, the browser doesn't guarantee it will conform to it. | 39 * |
40 * Note: This is only treated as a hint for the browser to set the buffer | |
41 * size. Even if <code>SetOption()</code> reports that this option has been | |
42 * successfully set, the browser doesn't guarantee it will conform to it. | |
43 */ | |
32 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE = 2, | 44 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE = 2, |
33 | 45 |
34 // Specifies the total per-socket buffer space reserved for receives. Value's | 46 /** |
35 // type should be PP_VARTYPE_INT32. | 47 * Specifies the total per-socket buffer space reserved for receives. Value's |
36 // Note: This is only treated as a hint for the browser to set the buffer | 48 * type should be <code>PP_VARTYPE_INT32</code>. |
37 // size. Even if SetOption() reports that this option has been successfully | 49 * This option can only be set after a successful <code>Bind()</code> call. |
38 // set, the browser doesn't guarantee it will conform to it. | 50 * |
51 * Note: This is only treated as a hint for the browser to set the buffer | |
52 * size. Even if <code>SetOption()</code> reports that this option has been | |
53 * successfully set, the browser doesn't guarantee it will conform to it. | |
54 */ | |
39 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE = 3 | 55 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE = 3 |
40 }; | 56 }; |
41 | 57 |
58 /** | |
59 * The <code>PPB_UDPSocket_Dev</code> interface provides UDP socket operations. | |
60 * | |
61 * Permissions: Apps permission <code>socket</code> with subrule | |
62 * <code>udp-bind</code> is required for <code>Bind()</code>; subrule | |
63 * <code>udp-send-to</code> is required for <code>SendTo()</code>. | |
64 * For more details about network communication permissions, please see: | |
65 * http://developer.chrome.com/apps/app_network.html | |
66 */ | |
42 interface PPB_UDPSocket_Dev { | 67 interface PPB_UDPSocket_Dev { |
43 /** | 68 /** |
44 * Creates a UDP socket resource. | 69 * Creates a UDP socket resource. |
70 * | |
71 * @param[in] instance A <code>PP_Instance</code> identifying one instance of | |
72 * a module. | |
73 * | |
74 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0 | |
75 * on failure. | |
45 */ | 76 */ |
46 PP_Resource Create([in] PP_Instance instance); | 77 PP_Resource Create([in] PP_Instance instance); |
47 | 78 |
48 /** | 79 /** |
49 * Determines if a given resource is a UDP socket. | 80 * Determines if a given resource is a UDP socket. |
81 * | |
82 * @param[in] resource A <code>PP_Resource</code> to check. | |
83 * | |
84 * @return <code>PP_TRUE</code> if the input is a | |
85 * <code>PPB_UDPSocket_Dev</code> resource; <code>PP_FALSE</code> | |
86 * otherwise. | |
50 */ | 87 */ |
51 PP_Bool IsUDPSocket([in] PP_Resource resource); | 88 PP_Bool IsUDPSocket([in] PP_Resource resource); |
52 | 89 |
53 /** | 90 /** |
54 * Binds to the address given by |addr|, which is a PPB_NetAddress_Dev | 91 * Binds to the given address. |
bbudge
2013/06/20 17:38:27
s/Binds/Binds the socket/
yzshen1
2013/06/20 20:27:45
Done.
| |
55 * resource. | 92 * |
93 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP | |
94 * socket. | |
95 * @param[in] addr A <code>PPB_NetAddress_Dev</code> resource. | |
96 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
97 * completion. | |
98 * | |
99 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
100 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have | |
101 * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned | |
102 * if the address is already in use. | |
56 */ | 103 */ |
57 int32_t Bind([in] PP_Resource udp_socket, | 104 int32_t Bind([in] PP_Resource udp_socket, |
58 [in] PP_Resource addr, | 105 [in] PP_Resource addr, |
59 [in] PP_CompletionCallback callback); | 106 [in] PP_CompletionCallback callback); |
60 | 107 |
61 /** | 108 /** |
62 * Returns the address that the socket has bound to, as a PPB_NetAddress_Dev | 109 * Get the address that the socket has bound to. It can only be called after |
bbudge
2013/06/20 17:38:27
s/Get/Gets
yzshen1
2013/06/20 20:27:45
Done.
| |
63 * resource. Bind must be called and succeed first. Returns 0 if Bind fails, | 110 * a successful <code>Bind()</code> call. |
64 * or if Close has been called. | 111 * |
112 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP | |
113 * socket. | |
114 * | |
115 * @return A <code>PPB_NetAddress_Dev</code> resource on success or 0 on | |
116 * failure. | |
65 */ | 117 */ |
66 PP_Resource GetBoundAddress([in] PP_Resource udp_socket); | 118 PP_Resource GetBoundAddress([in] PP_Resource udp_socket); |
67 | 119 |
68 /** | 120 /** |
69 * Performs a non-blocking recvfrom call on socket. | 121 * Receives data from the socket and stores the source address. It can only be |
70 * Bind must be called first. |callback| is invoked when recvfrom reads data. | 122 * called after a successful <code>Bind()</code> call. |
71 * |addr| will store a PPB_NetAddress_Dev resource on success. | 123 * |
124 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP | |
125 * socket. | |
126 * @param[out] buffer The buffer to store the received data on success. It | |
127 * must be at least as large as <code>num_bytes</code>. | |
128 * @param[in] num_bytes The number of bytes to read. | |
bbudge
2013/06/20 17:38:27
s/read/receive to be consistent with 'Receives' ab
yzshen1
2013/06/20 20:27:45
Done.
| |
129 * @param[out] addr A <code>PPB_NetAddress_Dev</code> resource to store the | |
130 * source address on success. | |
131 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
132 * completion. | |
133 * | |
134 * @return A non-negative number on success to indicate how many bytes have | |
135 * been received; otherwise, an error code from <code>pp_errors.h</code>. | |
72 */ | 136 */ |
73 int32_t RecvFrom([in] PP_Resource udp_socket, | 137 int32_t RecvFrom([in] PP_Resource udp_socket, |
74 [out] str_t buffer, | 138 [out] str_t buffer, |
75 [in] int32_t num_bytes, | 139 [in] int32_t num_bytes, |
76 [out] PP_Resource addr, | 140 [out] PP_Resource addr, |
77 [in] PP_CompletionCallback callback); | 141 [in] PP_CompletionCallback callback); |
78 | 142 |
79 /** | 143 /** |
80 * Performs a non-blocking sendto call on the socket. | 144 * Sends data to a specific destination. It can only be called after a |
bbudge
2013/06/20 17:38:27
s/destination/target address
or change 'target add
yzshen1
2013/06/20 20:27:45
Done.
| |
81 * Bind must be called first. |addr| is a PPB_NetAddress_Dev resource holding | 145 * successful <code>Bind()</code> call. |
82 * the target address. |callback| is invoked when sendto completes. | 146 * |
147 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP | |
148 * socket. | |
149 * @param[in] buffer The buffer containing the data to send. | |
150 * @param[in] num_bytes The number of bytes to send. | |
151 * @param[in] addr A <code>PPB_NetAddress_Dev</code> resource holding the | |
152 * target address. | |
153 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
154 * completion. | |
155 * | |
156 * @return A non-negative number on success to indicate how many bytes have | |
157 * been sent; otherwise, an error code from <code>pp_errors.h</code>. | |
158 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have | |
159 * required permissions. | |
83 */ | 160 */ |
84 int32_t SendTo([in] PP_Resource udp_socket, | 161 int32_t SendTo([in] PP_Resource udp_socket, |
85 [in] str_t buffer, | 162 [in] str_t buffer, |
86 [in] int32_t num_bytes, | 163 [in] int32_t num_bytes, |
87 [in] PP_Resource addr, | 164 [in] PP_Resource addr, |
88 [in] PP_CompletionCallback callback); | 165 [in] PP_CompletionCallback callback); |
89 | 166 |
90 /** | 167 /** |
91 * Cancels all pending reads and writes, and closes the socket. | 168 * Cancels all pending reads and writes, and closes the socket. Any pending |
169 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if | |
170 * pending IO was interrupted. After a call to this method, any output | |
bbudge
2013/06/20 17:38:27
A little awkward. How about:
After a call to this
yzshen1
2013/06/20 20:27:45
Because the output parameters also include PP_Reso
| |
171 * parameters passed into previous <code>RecvFrom()</code> calls won't be | |
172 * accessed. It is not valid to call <code>Bind()</code> again. | |
173 * | |
174 * The socket is implicitly closed if it is destroyed, so you are not | |
175 * required to call this method. | |
176 * | |
177 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP | |
178 * socket. | |
92 */ | 179 */ |
93 void Close([in] PP_Resource udp_socket); | 180 void Close([in] PP_Resource udp_socket); |
94 | 181 |
95 /** | 182 /** |
96 * Sets a socket option to |udp_socket|. Should be called before Bind(). | 183 * Sets a socket option on the UDP socket. |
97 * See the PP_UDPSocket_Option_Dev description for option names, value types | 184 * Please see the <code>PP_UDPSocket_Option_Dev</code> description for option |
98 * and allowed values. | 185 * names, value types and allowed values. |
99 * Returns PP_OK on success. Otherwise, returns PP_ERROR_BADRESOURCE (if bad | 186 * |
100 * |udp_socket| provided), PP_ERROR_BADARGUMENT (if bad name/value/value's | 187 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP |
101 * type provided) or PP_ERROR_FAILED in the case of internal errors. | 188 * socket. |
189 * @param[in] name The option type to set. | |
190 * @param[in] value The option value to set. | |
191 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon | |
192 * completion. | |
193 * | |
194 * @return An int32_t containing an error code from <code>pp_errors.h</code>. | |
102 */ | 195 */ |
103 int32_t SetOption([in] PP_Resource udp_socket, | 196 int32_t SetOption([in] PP_Resource udp_socket, |
104 [in] PP_UDPSocket_Option_Dev name, | 197 [in] PP_UDPSocket_Option_Dev name, |
105 [in] PP_Var value, | 198 [in] PP_Var value, |
106 [in] PP_CompletionCallback callback); | 199 [in] PP_CompletionCallback callback); |
107 }; | 200 }; |
OLD | NEW |