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
3 * found in the LICENSE file.
7 * This file defines the <code>PPB_UDPSocket</code> interface.
17 * Option names used by <code>SetOption()</code>.
20 enum PP_UDPSocket_Option
{
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>.
26 PP_UDPSOCKET_OPTION_ADDRESS_REUSE
= 0,
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>.
33 PP_UDPSOCKET_OPTION_BROADCAST
= 1,
36 * Specifies the total per-socket buffer space reserved for sends. Value's
37 * type should be <code>PP_VARTYPE_INT32</code>.
38 * This option can only be set after a successful <code>Bind()</code> call.
40 * Note: This is only treated as a hint for the browser to set the buffer
41 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
42 * guarantee it will conform to the size.
44 PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE
= 2,
47 * Specifies the total per-socket buffer space reserved for receives. Value's
48 * type should be <code>PP_VARTYPE_INT32</code>.
49 * This option can only be set after a successful <code>Bind()</code> call.
51 * Note: This is only treated as a hint for the browser to set the buffer
52 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
53 * guarantee it will conform to the size.
55 PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE
= 3
59 * The <code>PPB_UDPSocket</code> interface provides UDP socket operations.
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
67 interface PPB_UDPSocket
{
69 * Creates a UDP socket resource.
71 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
74 * @return A <code>PP_Resource</code> corresponding to a UDP socket or 0
77 PP_Resource Create
([in] PP_Instance instance
);
80 * Determines if a given resource is a UDP socket.
82 * @param[in] resource A <code>PP_Resource</code> to check.
84 * @return <code>PP_TRUE</code> if the input is a <code>PPB_UDPSocket</code>
85 * resource; <code>PP_FALSE</code> otherwise.
87 PP_Bool IsUDPSocket
([in] PP_Resource resource
);
90 * Binds the socket to the given address.
92 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
94 * @param[in] addr A <code>PPB_NetAddress</code> resource.
95 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
98 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
99 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
100 * required permissions. <code>PP_ERROR_ADDRESS_IN_USE</code> will be returned
101 * if the address is already in use.
103 int32_t Bind
([in] PP_Resource udp_socket
,
104 [in] PP_Resource addr
,
105 [in] PP_CompletionCallback
callback);
108 * Gets the address that the socket is bound to. The socket must be bound.
110 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
113 * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
115 PP_Resource GetBoundAddress
([in] PP_Resource udp_socket
);
118 * Receives data from the socket and stores the source address. The socket
121 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
123 * @param[out] buffer The buffer to store the received data on success. It
124 * must be at least as large as <code>num_bytes</code>.
125 * @param[in] num_bytes The number of bytes to receive.
126 * @param[out] addr A <code>PPB_NetAddress</code> resource to store the source
127 * address on success.
128 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
131 * @return A non-negative number on success to indicate how many bytes have
132 * been received; otherwise, an error code from <code>pp_errors.h</code>.
134 int32_t RecvFrom
([in] PP_Resource udp_socket
,
136 [in] int32_t num_bytes
,
137 [out] PP_Resource addr
,
138 [in] PP_CompletionCallback
callback);
141 * Sends data to a specific destination. The socket must be bound.
143 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
145 * @param[in] buffer The buffer containing the data to send.
146 * @param[in] num_bytes The number of bytes to send.
147 * @param[in] addr A <code>PPB_NetAddress</code> resource holding the
148 * destination address.
149 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
152 * @return A non-negative number on success to indicate how many bytes have
153 * been sent; otherwise, an error code from <code>pp_errors.h</code>.
154 * <code>PP_ERROR_NOACCESS</code> will be returned if the caller doesn't have
155 * required permissions.
157 int32_t SendTo
([in] PP_Resource udp_socket
,
159 [in] int32_t num_bytes
,
160 [in] PP_Resource addr
,
161 [in] PP_CompletionCallback
callback);
164 * Cancels all pending reads and writes, and closes the socket. Any pending
165 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> if
166 * pending IO was interrupted. After a call to this method, no output
167 * parameters passed into previous <code>RecvFrom()</code> calls will be
168 * accessed. It is not valid to call <code>Bind()</code> again.
170 * The socket is implicitly closed if it is destroyed, so you are not
171 * required to call this method.
173 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
176 void Close
([in] PP_Resource udp_socket
);
179 * Sets a socket option on the UDP socket.
180 * Please see the <code>PP_UDPSocket_Option</code> description for option
181 * names, value types and allowed values.
183 * @param[in] udp_socket A <code>PP_Resource</code> corresponding to a UDP
185 * @param[in] name The option to set.
186 * @param[in] value The option value to set.
187 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
190 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
192 int32_t SetOption
([in] PP_Resource udp_socket
,
193 [in] PP_UDPSocket_Option name
,
195 [in] PP_CompletionCallback
callback);