ppb_tcp_socket.h revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
14f94c520f8d699a5973956a1716272146be17128Zonr Chang/* Copyright 2013 The Chromium Authors. All rights reserved. 24f94c520f8d699a5973956a1716272146be17128Zonr Chang * Use of this source code is governed by a BSD-style license that can be 34f94c520f8d699a5973956a1716272146be17128Zonr Chang * found in the LICENSE file. 44f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 54f94c520f8d699a5973956a1716272146be17128Zonr Chang 64f94c520f8d699a5973956a1716272146be17128Zonr Chang/* From ppb_tcp_socket.idl modified Fri Sep 20 09:58:19 2013. */ 74f94c520f8d699a5973956a1716272146be17128Zonr Chang 84f94c520f8d699a5973956a1716272146be17128Zonr Chang#ifndef PPAPI_C_PPB_TCP_SOCKET_H_ 94f94c520f8d699a5973956a1716272146be17128Zonr Chang#define PPAPI_C_PPB_TCP_SOCKET_H_ 104f94c520f8d699a5973956a1716272146be17128Zonr Chang 114f94c520f8d699a5973956a1716272146be17128Zonr Chang#include "ppapi/c/pp_bool.h" 124f94c520f8d699a5973956a1716272146be17128Zonr Chang#include "ppapi/c/pp_completion_callback.h" 134f94c520f8d699a5973956a1716272146be17128Zonr Chang#include "ppapi/c/pp_instance.h" 144f94c520f8d699a5973956a1716272146be17128Zonr Chang#include "ppapi/c/pp_macros.h" 154f94c520f8d699a5973956a1716272146be17128Zonr Chang#include "ppapi/c/pp_resource.h" 164f94c520f8d699a5973956a1716272146be17128Zonr Chang#include "ppapi/c/pp_stdint.h" 17c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#include "ppapi/c/pp_var.h" 184f94c520f8d699a5973956a1716272146be17128Zonr Chang 19331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines#define PPB_TCPSOCKET_INTERFACE_1_0 "PPB_TCPSocket;1.0" 20331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines#define PPB_TCPSOCKET_INTERFACE_1_1 "PPB_TCPSocket;1.1" 214f94c520f8d699a5973956a1716272146be17128Zonr Chang#define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_1 224f94c520f8d699a5973956a1716272146be17128Zonr Chang 234f94c520f8d699a5973956a1716272146be17128Zonr Chang/** 244f94c520f8d699a5973956a1716272146be17128Zonr Chang * @file 254f94c520f8d699a5973956a1716272146be17128Zonr Chang * This file defines the <code>PPB_TCPSocket</code> interface. 26331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines */ 274f94c520f8d699a5973956a1716272146be17128Zonr Chang 284f94c520f8d699a5973956a1716272146be17128Zonr Chang 294f94c520f8d699a5973956a1716272146be17128Zonr Chang/** 304f94c520f8d699a5973956a1716272146be17128Zonr Chang * @addtogroup Enums 314f94c520f8d699a5973956a1716272146be17128Zonr Chang * @{ 324f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 3348cd745480738c026312931877ecb8ebecb1c64eStephen Hines/** 3448cd745480738c026312931877ecb8ebecb1c64eStephen Hines * Option names used by <code>SetOption()</code>. 3548cd745480738c026312931877ecb8ebecb1c64eStephen Hines */ 3648cd745480738c026312931877ecb8ebecb1c64eStephen Hinestypedef enum { 3748cd745480738c026312931877ecb8ebecb1c64eStephen Hines /** 3848cd745480738c026312931877ecb8ebecb1c64eStephen Hines * Disables coalescing of small writes to make TCP segments, and instead 3948cd745480738c026312931877ecb8ebecb1c64eStephen Hines * delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>. 4048cd745480738c026312931877ecb8ebecb1c64eStephen Hines * This option can only be set after a successful <code>Connect()</code> call. 4148cd745480738c026312931877ecb8ebecb1c64eStephen Hines */ 4248cd745480738c026312931877ecb8ebecb1c64eStephen Hines PP_TCPSOCKET_OPTION_NO_DELAY = 0, 4348cd745480738c026312931877ecb8ebecb1c64eStephen Hines /** 4448cd745480738c026312931877ecb8ebecb1c64eStephen Hines * Specifies the total per-socket buffer space reserved for sends. Value's 454f94c520f8d699a5973956a1716272146be17128Zonr Chang * type should be <code>PP_VARTYPE_INT32</code>. 464f94c520f8d699a5973956a1716272146be17128Zonr Chang * This option can only be set after a successful <code>Connect()</code> call. 474f94c520f8d699a5973956a1716272146be17128Zonr Chang * 484f94c520f8d699a5973956a1716272146be17128Zonr Chang * Note: This is only treated as a hint for the browser to set the buffer 494f94c520f8d699a5973956a1716272146be17128Zonr Chang * size. Even if <code>SetOption()</code> succeeds, the browser doesn't 504f94c520f8d699a5973956a1716272146be17128Zonr Chang * guarantee it will conform to the size. 51331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines */ 52331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, 534f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 544f94c520f8d699a5973956a1716272146be17128Zonr Chang * Specifies the total per-socket buffer space reserved for receives. Value's 554f94c520f8d699a5973956a1716272146be17128Zonr Chang * type should be <code>PP_VARTYPE_INT32</code>. 564f94c520f8d699a5973956a1716272146be17128Zonr Chang * This option can only be set after a successful <code>Connect()</code> call. 574f94c520f8d699a5973956a1716272146be17128Zonr Chang * 584f94c520f8d699a5973956a1716272146be17128Zonr Chang * Note: This is only treated as a hint for the browser to set the buffer 59c02eae6f35de7dfd92233d591b27c05f15c2a6a1Shih-wei Liao * size. Even if <code>SetOption()</code> succeeds, the browser doesn't 60c02eae6f35de7dfd92233d591b27c05f15c2a6a1Shih-wei Liao * guarantee it will conform to the size. 61c02eae6f35de7dfd92233d591b27c05f15c2a6a1Shih-wei Liao */ 624f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 63b2b8c64cd0524f9210218df4738f40409631ea26Shih-wei Liao} PP_TCPSocket_Option; 64b2b8c64cd0524f9210218df4738f40409631ea26Shih-wei LiaoPP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option, 4); 65b2b8c64cd0524f9210218df4738f40409631ea26Shih-wei Liao/** 66b2b8c64cd0524f9210218df4738f40409631ea26Shih-wei Liao * @} 67331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines */ 68331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines 69331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines/** 70331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines * @addtogroup Interfaces 714f94c520f8d699a5973956a1716272146be17128Zonr Chang * @{ 724f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 734f94c520f8d699a5973956a1716272146be17128Zonr Chang/** 744f94c520f8d699a5973956a1716272146be17128Zonr Chang * The <code>PPB_TCPSocket</code> interface provides TCP socket operations. 754f94c520f8d699a5973956a1716272146be17128Zonr Chang * 764f94c520f8d699a5973956a1716272146be17128Zonr Chang * Permissions: Apps permission <code>socket</code> with subrule 774f94c520f8d699a5973956a1716272146be17128Zonr Chang * <code>tcp-connect</code> is required for <code>Connect()</code>; subrule 784f94c520f8d699a5973956a1716272146be17128Zonr Chang * <code>tcp-listen</code> is required for <code>Listen()</code>. 794f94c520f8d699a5973956a1716272146be17128Zonr Chang * For more details about network communication permissions, please see: 804f94c520f8d699a5973956a1716272146be17128Zonr Chang * http://developer.chrome.com/apps/app_network.html 814f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 824f94c520f8d699a5973956a1716272146be17128Zonr Changstruct PPB_TCPSocket_1_1 { 834f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 844f94c520f8d699a5973956a1716272146be17128Zonr Chang * Creates a TCP socket resource. 854f94c520f8d699a5973956a1716272146be17128Zonr Chang * 864f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] instance A <code>PP_Instance</code> identifying one instance of 874f94c520f8d699a5973956a1716272146be17128Zonr Chang * a module. 884f94c520f8d699a5973956a1716272146be17128Zonr Chang * 894f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 904f94c520f8d699a5973956a1716272146be17128Zonr Chang * on failure. 914f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 924f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource (*Create)(PP_Instance instance); 934f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 944f94c520f8d699a5973956a1716272146be17128Zonr Chang * Determines if a given resource is a TCP socket. 954f94c520f8d699a5973956a1716272146be17128Zonr Chang * 964f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] resource A <code>PP_Resource</code> to check. 974f94c520f8d699a5973956a1716272146be17128Zonr Chang * 984f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return <code>PP_TRUE</code> if the input is a 994f94c520f8d699a5973956a1716272146be17128Zonr Chang * <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise. 1004f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 1014f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Bool (*IsTCPSocket)(PP_Resource resource); 1024f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 1034f94c520f8d699a5973956a1716272146be17128Zonr Chang * Binds the socket to the given address. The socket must not be bound. 1044f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1054f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 1064f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 1074f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] addr A <code>PPB_NetAddress</code> resource. 1084f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 1094f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 1104f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1114f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return An int32_t containing an error code from <code>pp_errors.h</code>, 1124f94c520f8d699a5973956a1716272146be17128Zonr Chang * including (but not limited to): 1134f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use. 1144f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid. 1154f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 1164f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Bind)(PP_Resource tcp_socket, 1174f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource addr, 1184f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 1194f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 1204f94c520f8d699a5973956a1716272146be17128Zonr Chang * Connects the socket to the given address. The socket must not be listening. 1214f94c520f8d699a5973956a1716272146be17128Zonr Chang * Binding the socket beforehand is optional. 1224f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1234f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 1244f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 1254f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] addr A <code>PPB_NetAddress</code> resource. 1264f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 1274f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 1284f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1294f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return An int32_t containing an error code from <code>pp_errors.h</code>, 1304f94c520f8d699a5973956a1716272146be17128Zonr Chang * including (but not limited to): 131f21590eae009b4f596d7e448d0b8e142c46fc382Stephen Hines * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required 1324f94c520f8d699a5973956a1716272146be17128Zonr Chang * permissions. 1334f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is 1344f94c520f8d699a5973956a1716272146be17128Zonr Chang * unreachable. 1354f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was 1364f94c520f8d699a5973956a1716272146be17128Zonr Chang * refused. 1374f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. 1384f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed 1394f94c520f8d699a5973956a1716272146be17128Zonr Chang * out. 1404f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1414f94c520f8d699a5973956a1716272146be17128Zonr Chang * Since version 1.1, if the socket is listening/connected or has a pending 1424f94c520f8d699a5973956a1716272146be17128Zonr Chang * listen/connect request, <code>Connect()</code> will fail without starting a 1434f94c520f8d699a5973956a1716272146be17128Zonr Chang * connection attempt; otherwise, any failure during the connection attempt 1444f94c520f8d699a5973956a1716272146be17128Zonr Chang * will cause the socket to be closed. 1454f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 1464f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Connect)(PP_Resource tcp_socket, 1474f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource addr, 1484f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 1494f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 1504f94c520f8d699a5973956a1716272146be17128Zonr Chang * Gets the local address of the socket, if it is bound. 1514f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1524f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 1534f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 1544f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1554f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. 1564f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 157f21590eae009b4f596d7e448d0b8e142c46fc382Stephen Hines PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); 1584f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 1594f94c520f8d699a5973956a1716272146be17128Zonr Chang * Gets the remote address of the socket, if it is connected. 1604f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1614f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 1624f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 1634f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1644f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return A <code>PPB_NetAddress</code> resource on success or 0 on failure. 1654f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 1664f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket); 1674f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 1684f94c520f8d699a5973956a1716272146be17128Zonr Chang * Reads data from the socket. The socket must be connected. It may perform a 1694f94c520f8d699a5973956a1716272146be17128Zonr Chang * partial read. 1704f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1714f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 1724f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 1734f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[out] buffer The buffer to store the received data on success. It 1744f94c520f8d699a5973956a1716272146be17128Zonr Chang * must be at least as large as <code>bytes_to_read</code>. 1754f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] bytes_to_read The number of bytes to read. 1764f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 1774f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 1784f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1794f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return A non-negative number on success to indicate how many bytes have 1804f94c520f8d699a5973956a1716272146be17128Zonr Chang * been read, 0 means that end-of-file was reached; otherwise, an error code 1814f94c520f8d699a5973956a1716272146be17128Zonr Chang * from <code>pp_errors.h</code>. 1824f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 1834f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Read)(PP_Resource tcp_socket, 1844f94c520f8d699a5973956a1716272146be17128Zonr Chang char* buffer, 1854f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t bytes_to_read, 1864f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 1874f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 1884f94c520f8d699a5973956a1716272146be17128Zonr Chang * Writes data to the socket. The socket must be connected. It may perform a 1894f94c520f8d699a5973956a1716272146be17128Zonr Chang * partial write. 1904f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1914f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 1924f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 1934f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] buffer The buffer containing the data to write. 1944f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] bytes_to_write The number of bytes to write. 1954f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 1964f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 1974f94c520f8d699a5973956a1716272146be17128Zonr Chang * 1984f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return A non-negative number on success to indicate how many bytes have 1994f94c520f8d699a5973956a1716272146be17128Zonr Chang * been written; otherwise, an error code from <code>pp_errors.h</code>. 2004f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 2014f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Write)(PP_Resource tcp_socket, 2024f94c520f8d699a5973956a1716272146be17128Zonr Chang const char* buffer, 2034f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t bytes_to_write, 2044f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2054f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 2064f94c520f8d699a5973956a1716272146be17128Zonr Chang * Starts listening. The socket must be bound and not connected. 2074f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2084f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 2094f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 2104f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] backlog A hint to determine the maximum length to which the 2114f94c520f8d699a5973956a1716272146be17128Zonr Chang * queue of pending connections may grow. 2124f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 2134f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 2144f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2154f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return An int32_t containing an error code from <code>pp_errors.h</code>, 2164f94c520f8d699a5973956a1716272146be17128Zonr Chang * including (but not limited to): 2174f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required 2184f94c520f8d699a5973956a1716272146be17128Zonr Chang * permissions. 2194f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening 2204f94c520f8d699a5973956a1716272146be17128Zonr Chang * on the same port. 2214f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 2224f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Listen)(PP_Resource tcp_socket, 2234f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t backlog, 2244f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2254f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 2264f94c520f8d699a5973956a1716272146be17128Zonr Chang * Accepts a connection. The socket must be listening. 2274f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2284f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 2294f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 2304f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[out] accepted_tcp_socket Stores the accepted TCP socket on success. 2314f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 2324f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 233f21590eae009b4f596d7e448d0b8e142c46fc382Stephen Hines * 2344f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return An int32_t containing an error code from <code>pp_errors.h</code>, 2354f94c520f8d699a5973956a1716272146be17128Zonr Chang * including (but not limited to): 2364f94c520f8d699a5973956a1716272146be17128Zonr Chang * - <code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted. 2374f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 2384f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Accept)(PP_Resource tcp_socket, 2394f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource* accepted_tcp_socket, 2404f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2414f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 2424f94c520f8d699a5973956a1716272146be17128Zonr Chang * Cancels all pending operations and closes the socket. Any pending callbacks 2434f94c520f8d699a5973956a1716272146be17128Zonr Chang * will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was 2444f94c520f8d699a5973956a1716272146be17128Zonr Chang * interrupted. After a call to this method, no output buffer pointers passed 2454f94c520f8d699a5973956a1716272146be17128Zonr Chang * into previous <code>Read()</code> or <code>Accept()</code> calls will be 2464f94c520f8d699a5973956a1716272146be17128Zonr Chang * accessed. It is not valid to call <code>Connect()</code> or 2474f94c520f8d699a5973956a1716272146be17128Zonr Chang * <code>Listen()</code> again. 2484f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2494f94c520f8d699a5973956a1716272146be17128Zonr Chang * The socket is implicitly closed if it is destroyed, so you are not required 2504f94c520f8d699a5973956a1716272146be17128Zonr Chang * to call this method. 2514f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2524f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 2534f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 2544f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 2554f94c520f8d699a5973956a1716272146be17128Zonr Chang void (*Close)(PP_Resource tcp_socket); 2564f94c520f8d699a5973956a1716272146be17128Zonr Chang /** 2574f94c520f8d699a5973956a1716272146be17128Zonr Chang * Sets a socket option on the TCP socket. 2584f94c520f8d699a5973956a1716272146be17128Zonr Chang * Please see the <code>PP_TCPSocket_Option</code> description for option 2594f94c520f8d699a5973956a1716272146be17128Zonr Chang * names, value types and allowed values. 2604f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2614f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP 2624f94c520f8d699a5973956a1716272146be17128Zonr Chang * socket. 2634f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] name The option to set. 2644f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] value The option value to set. 2654f94c520f8d699a5973956a1716272146be17128Zonr Chang * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon 2664f94c520f8d699a5973956a1716272146be17128Zonr Chang * completion. 2674f94c520f8d699a5973956a1716272146be17128Zonr Chang * 2684f94c520f8d699a5973956a1716272146be17128Zonr Chang * @return An int32_t containing an error code from <code>pp_errors.h</code>. 2694f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 2704f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*SetOption)(PP_Resource tcp_socket, 2714f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_TCPSocket_Option name, 2724f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_Var value, 2734f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2744f94c520f8d699a5973956a1716272146be17128Zonr Chang}; 2754f94c520f8d699a5973956a1716272146be17128Zonr Chang 2764f94c520f8d699a5973956a1716272146be17128Zonr Changtypedef struct PPB_TCPSocket_1_1 PPB_TCPSocket; 2774f94c520f8d699a5973956a1716272146be17128Zonr Chang 2784f94c520f8d699a5973956a1716272146be17128Zonr Changstruct PPB_TCPSocket_1_0 { 2794f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource (*Create)(PP_Instance instance); 2804f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Bool (*IsTCPSocket)(PP_Resource resource); 2814f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Connect)(PP_Resource tcp_socket, 2824f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource addr, 2834f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2844f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); 2854f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket); 2864f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Read)(PP_Resource tcp_socket, 2874f94c520f8d699a5973956a1716272146be17128Zonr Chang char* buffer, 2884f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t bytes_to_read, 2894f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2904f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*Write)(PP_Resource tcp_socket, 2914f94c520f8d699a5973956a1716272146be17128Zonr Chang const char* buffer, 2924f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t bytes_to_write, 2934f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2944f94c520f8d699a5973956a1716272146be17128Zonr Chang void (*Close)(PP_Resource tcp_socket); 2954f94c520f8d699a5973956a1716272146be17128Zonr Chang int32_t (*SetOption)(PP_Resource tcp_socket, 2964f94c520f8d699a5973956a1716272146be17128Zonr Chang PP_TCPSocket_Option name, 2974f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_Var value, 2984f94c520f8d699a5973956a1716272146be17128Zonr Chang struct PP_CompletionCallback callback); 2994f94c520f8d699a5973956a1716272146be17128Zonr Chang}; 3004f94c520f8d699a5973956a1716272146be17128Zonr Chang/** 3014f94c520f8d699a5973956a1716272146be17128Zonr Chang * @} 3024f94c520f8d699a5973956a1716272146be17128Zonr Chang */ 3034f94c520f8d699a5973956a1716272146be17128Zonr Chang 3044f94c520f8d699a5973956a1716272146be17128Zonr Chang#endif /* PPAPI_C_PPB_TCP_SOCKET_H_ */ 305331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines 306331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines