1 /* Copyright (c) 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 Pepper equivalent of the <code>chrome.socket</code>
16 * A string <code>PP_Var</code> which has one of the following values:
20 typedef PP_Var PP_Ext_Socket_SocketType_Dev
;
23 * A dictionary <code>PP_Var</code>.
25 typedef PP_Var PP_Ext_Socket_CreateOptions_Dev
;
28 * A dictionary <code>PP_Var</code> which contains
29 * - "socketId" : integer <code>PP_Var</code>
30 * The id of the newly created socket.
32 typedef PP_Var PP_Ext_Socket_CreateInfo_Dev
;
35 * A dictionary <code>PP_Var</code> which contains
36 * - "resultCode" : integer <code>PP_Var</code>
37 * - "socketId" : integer or undefined <code>PP_Var</code>
38 * The id of the accepted socket.
40 typedef PP_Var PP_Ext_Socket_AcceptInfo_Dev
;
43 * A dictionary <code>PP_Var</code> which contains
44 * - "resultCode" : integer <code>PP_Var</code>
45 * The resultCode returned from the underlying read() call.
46 * - "data" : array buffer <code>PP_Var</code>
48 typedef PP_Var PP_Ext_Socket_ReadInfo_Dev
;
51 * A dictionary <code>PP_Var</code> which contains
52 * - "bytesWritten" : integer <code>PP_Var</code>
53 * The number of bytes sent, or a negative error code.
55 typedef PP_Var PP_Ext_Socket_WriteInfo_Dev
;
58 * A dictionary <code>PP_Var</code> which contains
59 * - "resultCode" : integer <code>PP_Var</code>
60 * The resultCode returned from the underlying recvfrom() call.
61 * - "data": array buffer <code>PP_Var</code>
62 * - "address": string <code>PP_Var</code>
63 * The address of the remote machine.
64 * - "port": integer <code>PP_Var</code>
66 typedef PP_Var PP_Ext_Socket_RecvFromInfo_Dev
;
69 * A dictionary <code>PP_Var</code> which contains
70 * - "socketType" : string <code>PP_Var</code> which matches the description of
71 * <code>PP_Ext_Socket_SocketType_Dev</code>
72 * The type of the passed socket. This will be <code>tcp</code> or
74 * - "connected" : boolean <code>PP_Var</code>
75 * Whether or not the underlying socket is connected.
77 * For <code>tcp</code> sockets, this will remain true even if the remote peer
78 * has disconnected. Reading or writing to the socket may then result in an
79 * error, hinting that this socket should be disconnected via
80 * <code>Disconnect()</code>.
82 * For <code>udp</code> sockets, this just represents whether a default remote
83 * address has been specified for reading and writing packets.
84 * - "peerAddress" : string or undefined <code>PP_Var</code>
85 * If the underlying socket is connected, contains the IPv4/6 address of the
87 * - "peerPort" : integer or undefined <code>PP_Var</code>
88 * If the underlying socket is connected, contains the port of the connected
90 * - "localAddress" : string or undefined <code>PP_Var</code>
91 * If the underlying socket is bound or connected, contains its local IPv4/6
93 * - "localPort" : integer or undefined <code>PP_Var</code>
94 * If the underlying socket is bound or connected, contains its local port.
96 typedef PP_Var PP_Ext_Socket_SocketInfo_Dev
;
99 * A dictionary <code>PP_Var</code> which contains
100 * - "name" : string <code>PP_Var</code>
101 * The underlying name of the adapter. On *nix, this will typically be "eth0",
103 * - "address": string <code>PP_Var</code>
104 * The available IPv4/6 address.
106 typedef PP_Var PP_Ext_Socket_NetworkInterface_Dev
;
109 * An array <code>PP_Var</code> which contains elements of
110 * <code>PP_Ext_Socket_NetworkInterface_Dev</code>.
112 typedef PP_Var PP_Ext_Socket_NetworkInterface_Dev_Array
;
114 interface PPB_Ext_Socket_Dev
{
116 * Creates a socket of the specified type that will connect to the specified
119 * @param[in] instance A <code>PP_Instance</code>.
120 * @param[in] type A <code>PP_Ext_Socket_SocketType_Dev</code>. The type of
121 * socket to create. Must be <code>tcp</code> or <code>udp</code>.
122 * @param[in] options An undefined <code>PP_Var</code> or
123 * <code>PP_Ext_Socket_CreateOptions_Dev</code>. The socket options.
124 * @param[out] create_info A <code>PP_Ext_Socket_CreateInfo_Dev</code>.
125 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
128 * @return An error code from <code>pp_errors.h</code>.
131 [in] PP_Instance instance
,
132 [in] PP_Ext_Socket_SocketType_Dev type
,
133 [in] PP_Ext_Socket_CreateOptions_Dev options
,
134 [out] PP_Ext_Socket_CreateInfo_Dev create_info
,
135 [in] PP_CompletionCallback
callback);
138 * Destroys the socket. Each socket created should be destroyed after use.
140 * @param[in] instance A <code>PP_Instance</code>.
141 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
144 [in] PP_Instance instance
,
145 [in] PP_Var socket_id
);
148 * Connects the socket to the remote machine (for a <code>tcp</code> socket).
149 * For a <code>udp</code> socket, this sets the default address which packets
150 * are sent to and read from for <code>Read()</code> and <code>Write()</code>
153 * @param[in] instance A <code>PP_Instance</code>.
154 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
155 * @param[in] hostname A string <code>PP_Var</code>. The hostname or IP
156 * address of the remote machine.
157 * @param[in] port An integer <code>PP_Var</code>. The port of the remote
159 * @param[out] result An integer <code>PP_Var</code>.
160 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
163 * @return An error code from <code>pp_errors.h</code>.
166 [in] PP_Instance instance
,
167 [in] PP_Var socket_id
,
168 [in] PP_Var hostname
,
171 [in] PP_CompletionCallback
callback);
174 * Binds the local address for socket. Currently, it does not support TCP
177 * @param[in] instance A <code>PP_Instance</code>.
178 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
179 * @param[in] address A string <code>PP_Var</code>. The address of the local
181 * @param[in] port An integer <code>PP_Var</code>. The port of the local
183 * @param[out] result An integer <code>PP_Var</code>.
184 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
187 * @return An error code from <code>pp_errors.h</code>.
190 [in] PP_Instance instance
,
191 [in] PP_Var socket_id
,
195 [in] PP_CompletionCallback
callback);
198 * Disconnects the socket. For UDP sockets, <code>Disconnect</code> is a
199 * non-operation but is safe to call.
201 * @param[in] instance A <code>PP_Instance</code>.
202 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
205 [in] PP_Instance instance
,
206 [in] PP_Var socket_id
);
209 * Reads data from the given connected socket.
211 * @param[in] instance A <code>PP_Instance</code>.
212 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
213 * @param[in] buffer_size An undefined or integer <code>PP_Var</code>. The
215 * @param[out] read_info A <code>PP_Ext_Socket_ReadInfo_Dev</code>.
216 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
219 * @return An error code from <code>pp_errors.h</code>.
222 [in] PP_Instance instance
,
223 [in] PP_Var socket_id
,
224 [in] PP_Var buffer_size
,
225 [out] PP_Ext_Socket_ReadInfo_Dev read_info
,
226 [in] PP_CompletionCallback
callback);
229 * Writes data on the given connected socket.
231 * @param[in] instance A <code>PP_Instance</code>.
232 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
233 * @param[in] data An array buffer <code>PP_Var</code>. The data to write.
234 * @param[out] write_info A <code>PP_Ext_Socket_WriteInfo_Dev</code>.
235 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
238 * @return An error code from <code>pp_errors.h</code>.
241 [in] PP_Instance instance
,
242 [in] PP_Var socket_id
,
244 [out] PP_Ext_Socket_WriteInfo_Dev write_info
,
245 [in] PP_CompletionCallback
callback);
248 * Receives data from the given UDP socket.
250 * @param[in] instance A <code>PP_Instance</code>.
251 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
252 * @param[in] buffer_size An undefined or integer <code>PP_Var</code>. The
253 * receive buffer size.
254 * @param[out] recv_from_info A <code>PP_Ext_Socket_RecvFromInfo_Dev</code>.
255 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
258 * @return An error code from <code>pp_errors.h</code>.
261 [in] PP_Instance instance
,
262 [in] PP_Var socket_id
,
263 [in] PP_Var buffer_size
,
264 [out] PP_Ext_Socket_RecvFromInfo_Dev recv_from_info
,
265 [in] PP_CompletionCallback
callback);
268 * Sends data on the given UDP socket to the given address and port.
270 * @param[in] instance A <code>PP_Instance</code>.
271 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
272 * @param[in] data An array buffer <code>PP_Var</code>.
273 * @param[in] address A string <code>PP_Var</code>. The address of the remote
275 * @param[in] port An integer <code>PP_Var</code>. The port of the remote
277 * @param[out] write_info A <code>PP_Ext_Socket_WriteInfo_Dev</code>.
278 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
281 * @return An error code from <code>pp_errors.h</code>.
284 [in] PP_Instance instance
,
285 [in] PP_Var socket_id
,
289 [out] PP_Ext_Socket_WriteInfo_Dev write_info
,
290 [in] PP_CompletionCallback
callback);
293 * This method applies to TCP sockets only.
294 * Listens for connections on the specified port and address. This effectively
295 * makes this a server socket, and client socket functions (Connect, Read,
296 * Write) can no longer be used on this socket.
298 * @param[in] instance A <code>PP_Instance</code>.
299 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
300 * @param[in] address A string <code>PP_Var</code>. The address of the local
302 * @param[in] port An integer <code>PP_Var</code>. The port of the local
304 * @param[in] backlog An undefined or integer <code>PP_Var</code>. Length of
305 * the socket's listen queue.
306 * @param[out] result An integer <code>PP_Var</code>.
307 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
310 * @return An error code from <code>pp_errors.h</code>.
313 [in] PP_Instance instance
,
314 [in] PP_Var socket_id
,
319 [in] PP_CompletionCallback
callback);
322 * This method applies to TCP sockets only.
323 * Registers a callback function to be called when a connection is accepted on
324 * this listening server socket. Listen must be called first.
325 * If there is already an active accept callback, this callback will be
326 * invoked immediately with an error as the resultCode.
328 * @param[in] instance A <code>PP_Instance</code>.
329 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
330 * @param[out] accept_info A <code>PP_Ext_Socket_AcceptInfo_Dev</code>.
331 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
334 * @return An error code from <code>pp_errors.h</code>.
337 [in] PP_Instance instance
,
338 [in] PP_Var socket_id
,
339 [out] PP_Ext_Socket_AcceptInfo_Dev accept_info
,
340 [in] PP_CompletionCallback
callback);
343 * Enables or disables the keep-alive functionality for a TCP connection.
345 * @param[in] instance A <code>PP_Instance</code>.
346 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
347 * @param[in] enable A boolean <code>PP_Var</code>. If true, enable keep-alive
349 * @param[in] delay An undefined or integer <code>PP_Var</code>. Set the delay
350 * seconds between the last data packet received and the first keepalive
351 * probe. Default is 0.
352 * @param[out] result A boolean <code>PP_Var</code>.
353 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
356 * @return An error code from <code>pp_errors.h</code>.
358 int32_t SetKeepAlive
(
359 [in] PP_Instance instance
,
360 [in] PP_Var socket_id
,
364 [in] PP_CompletionCallback
callback);
367 * Sets or clears <code>TCP_NODELAY</code> for a TCP connection. Nagle's
368 * algorithm will be disabled when <code>TCP_NODELAY</code> is set.
370 * @param[in] instance A <code>PP_Instance</code>.
371 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
372 * @param[in] no_delay A boolean <code>PP_Var</code>.
373 * @param[out] result A boolean <code>PP_Var</code>.
374 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
377 * @return An error code from <code>pp_errors.h</code>.
380 [in] PP_Instance instance
,
381 [in] PP_Var socket_id
,
382 [in] PP_Var no_delay
,
384 [in] PP_CompletionCallback
callback);
387 * Retrieves the state of the given socket.
389 * @param[in] instance A <code>PP_Instance</code>.
390 * @param[in] socket_id An integer <code>PP_Var</code>. The socket ID.
391 * @param[out] result A <code>PP_Ext_Socket_SocketInfo_Dev</code>.
392 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
395 * @return An error code from <code>pp_errors.h</code>.
398 [in] PP_Instance instance
,
399 [in] PP_Var socket_id
,
400 [out] PP_Ext_Socket_SocketInfo_Dev result
,
401 [in] PP_CompletionCallback
callback);
404 * Retrieves information about local adapters on this system.
406 * @param[in] instance A <code>PP_Instance</code>.
407 * @param[out] result A <code>PP_Ext_Socket_NetworkInterface_Dev_Array</code>.
408 * @param[in] callback A <code>PP_CompletionCallback</code> to be called
411 * @return An error code from <code>pp_errors.h</code>.
413 int32_t GetNetworkList
(
414 [in] PP_Instance instance
,
415 [out] PP_Ext_Socket_NetworkInterface_Dev_Array result
,
416 [in] PP_CompletionCallback
callback);