1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/* Copyright 2013 The Chromium Authors. All rights reserved.
2eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * Use of this source code is governed by a BSD-style license that can be
3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * found in the LICENSE file.
4eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)/* From ppb_tcp_socket.idl modified Fri Sep 20 09:58:19 2013. */
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#ifndef PPAPI_C_PPB_TCP_SOCKET_H_
9eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define PPAPI_C_PPB_TCP_SOCKET_H_
10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_bool.h"
12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_completion_callback.h"
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_instance.h"
14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_macros.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_resource.h"
16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_stdint.h"
17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ppapi/c/pp_var.h"
18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define PPB_TCPSOCKET_INTERFACE_1_0 "PPB_TCPSocket;1.0"
2068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#define PPB_TCPSOCKET_INTERFACE_1_1 "PPB_TCPSocket;1.1"
2168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_1
22eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
23eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
24eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @file
25eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * This file defines the <code>PPB_TCPSocket</code> interface.
26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @addtogroup Enums
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @{
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * Option names used by <code>SetOption()</code>.
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochtypedef enum {
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Disables coalescing of small writes to make TCP segments, and instead
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>.
40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * This option can only be set after a successful <code>Connect()</code> call.
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_TCPSOCKET_OPTION_NO_DELAY = 0,
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Specifies the total per-socket buffer space reserved for sends. Value's
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * type should be <code>PP_VARTYPE_INT32</code>.
46eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * This option can only be set after a successful <code>Connect()</code> call.
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Note: This is only treated as a hint for the browser to set the buffer
49eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
50eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * guarantee it will conform to the size.
51eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
52eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1,
53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Specifies the total per-socket buffer space reserved for receives. Value's
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * type should be <code>PP_VARTYPE_INT32</code>.
56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * This option can only be set after a successful <code>Connect()</code> call.
57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Note: This is only treated as a hint for the browser to set the buffer
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * size. Even if <code>SetOption()</code> succeeds, the browser doesn't
60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * guarantee it will conform to the size.
61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2
63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} PP_TCPSocket_Option;
64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochPP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option, 4);
65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @}
67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @addtogroup Interfaces
71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @{
72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * The <code>PPB_TCPSocket</code> interface provides TCP socket operations.
75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch *
76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * Permissions: Apps permission <code>socket</code> with subrule
7768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) * <code>tcp-connect</code> is required for <code>Connect()</code>; subrule
7868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) * <code>tcp-listen</code> is required for <code>Listen()</code>.
79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * For more details about network communication permissions, please see:
80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * http://developer.chrome.com/apps/app_network.html
81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
8268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)struct PPB_TCPSocket_1_1 {
83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Creates a TCP socket resource.
85eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
86eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] instance A <code>PP_Instance</code> identifying one instance of
87eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * a module.
88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0
90eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * on failure.
91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
92eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_Resource (*Create)(PP_Instance instance);
93eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Determines if a given resource is a TCP socket.
95eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
96eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] resource A <code>PP_Resource</code> to check.
97eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
98eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return <code>PP_TRUE</code> if the input is a
99eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise.
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
101eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_Bool (*IsTCPSocket)(PP_Resource resource);
102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
10368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Binds the socket to the given address. The socket must not be bound.
10468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
10568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
10668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * socket.
10768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] addr A <code>PPB_NetAddress</code> resource.
10868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
10968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * completion.
11068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
11168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @return An int32_t containing an error code from <code>pp_errors.h</code>,
11268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * including (but not limited to):
11368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * - <code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use.
11468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * - <code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid.
11568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   */
11668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*Bind)(PP_Resource tcp_socket,
11768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                  PP_Resource addr,
11868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                  struct PP_CompletionCallback callback);
11968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /**
12068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Connects the socket to the given address. The socket must not be listening.
12168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Binding the socket beforehand is optional.
122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] addr A <code>PPB_NetAddress</code> resource.
126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * completion.
128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return An int32_t containing an error code from <code>pp_errors.h</code>,
130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * including (but not limited to):
131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *   permissions.
133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is
134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *   unreachable.
135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was
136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *   refused.
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed.
138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed
139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *   out.
14068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
14168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Since version 1.1, if the socket is listening/connected or has a pending
14268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * listen/connect request, <code>Connect()</code> will fail without starting a
14368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * connection attempt; otherwise, any failure during the connection attempt
14468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * will cause the socket to be closed.
145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  int32_t (*Connect)(PP_Resource tcp_socket,
147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                     PP_Resource addr,
148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                     struct PP_CompletionCallback callback);
149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
15068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Gets the local address of the socket, if it is bound.
151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Gets the remote address of the socket, if it is connected.
160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Reads data from the socket. The socket must be connected. It may perform a
169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * partial read.
170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[out] buffer The buffer to store the received data on success. It
174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * must be at least as large as <code>bytes_to_read</code>.
175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] bytes_to_read The number of bytes to read.
176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * completion.
178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
179eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return A non-negative number on success to indicate how many bytes have
180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * been read, 0 means that end-of-file was reached; otherwise, an error code
181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * from <code>pp_errors.h</code>.
182eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  int32_t (*Read)(PP_Resource tcp_socket,
184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                  char* buffer,
185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                  int32_t bytes_to_read,
186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                  struct PP_CompletionCallback callback);
187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Writes data to the socket. The socket must be connected. It may perform a
189eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * partial write.
190eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
192eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
193eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] buffer The buffer containing the data to write.
194eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] bytes_to_write The number of bytes to write.
195eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
196eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * completion.
197eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return A non-negative number on success to indicate how many bytes have
199eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * been written; otherwise, an error code from <code>pp_errors.h</code>.
200eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
201eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  int32_t (*Write)(PP_Resource tcp_socket,
202eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                   const char* buffer,
203eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                   int32_t bytes_to_write,
204eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                   struct PP_CompletionCallback callback);
205eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
20668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Starts listening. The socket must be bound and not connected.
20768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
20868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
20968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * socket.
21068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] backlog A hint to determine the maximum length to which the
21168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * queue of pending connections may grow.
21268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
21368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * completion.
21468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
21568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @return An int32_t containing an error code from <code>pp_errors.h</code>,
21668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * including (but not limited to):
21768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
21868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *   permissions.
21968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening
22068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *   on the same port.
22168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   */
22268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*Listen)(PP_Resource tcp_socket,
22368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    int32_t backlog,
22468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    struct PP_CompletionCallback callback);
22568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /**
22668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Accepts a connection. The socket must be listening.
22768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
22868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
22968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * socket.
23068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[out] accepted_tcp_socket Stores the accepted TCP socket on success.
23168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
23268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * completion.
23368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   *
23468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * @return An int32_t containing an error code from <code>pp_errors.h</code>,
23568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * including (but not limited to):
23668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * - <code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted.
23768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   */
23868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*Accept)(PP_Resource tcp_socket,
23968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    PP_Resource* accepted_tcp_socket,
24068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                    struct PP_CompletionCallback callback);
24168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  /**
24268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * Cancels all pending operations and closes the socket. Any pending callbacks
24368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was
24468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * interrupted. After a call to this method, no output buffer pointers passed
24568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * into previous <code>Read()</code> or <code>Accept()</code> calls will be
24668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * accessed. It is not valid to call <code>Connect()</code> or
24768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)   * <code>Listen()</code> again.
248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
249eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * The socket is implicitly closed if it is destroyed, so you are not required
250eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * to call this method.
251eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
252eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
253eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void (*Close)(PP_Resource tcp_socket);
256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  /**
257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Sets a socket option on the TCP socket.
258eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * Please see the <code>PP_TCPSocket_Option</code> description for option
259eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * names, value types and allowed values.
260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
261eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * socket.
263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] name The option to set.
264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] value The option value to set.
265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * completion.
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   *
268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   * @return An int32_t containing an error code from <code>pp_errors.h</code>.
269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch   */
270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  int32_t (*SetOption)(PP_Resource tcp_socket,
271eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                       PP_TCPSocket_Option name,
272eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                       struct PP_Var value,
273eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch                       struct PP_CompletionCallback callback);
274eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch};
275eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
27668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)typedef struct PPB_TCPSocket_1_1 PPB_TCPSocket;
27768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)
27868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)struct PPB_TCPSocket_1_0 {
27968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  PP_Resource (*Create)(PP_Instance instance);
28068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  PP_Bool (*IsTCPSocket)(PP_Resource resource);
28168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*Connect)(PP_Resource tcp_socket,
28268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                     PP_Resource addr,
28368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                     struct PP_CompletionCallback callback);
28468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
28568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
28668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*Read)(PP_Resource tcp_socket,
28768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                  char* buffer,
28868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                  int32_t bytes_to_read,
28968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                  struct PP_CompletionCallback callback);
29068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*Write)(PP_Resource tcp_socket,
29168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                   const char* buffer,
29268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                   int32_t bytes_to_write,
29368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                   struct PP_CompletionCallback callback);
29468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  void (*Close)(PP_Resource tcp_socket);
29568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  int32_t (*SetOption)(PP_Resource tcp_socket,
29668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       PP_TCPSocket_Option name,
29768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       struct PP_Var value,
29868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)                       struct PP_CompletionCallback callback);
29968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)};
300eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch/**
301eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch * @}
302eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch */
303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
304eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif  /* PPAPI_C_PPB_TCP_SOCKET_H_ */
305eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
306