1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
/* Copyright 2013 The Chromium Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* From ppb_tcp_socket.idl modified Mon Dec 8 16:50:44 2014. */
#ifndef PPAPI_C_PPB_TCP_SOCKET_H_
#define PPAPI_C_PPB_TCP_SOCKET_H_
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/pp_var.h"
#define PPB_TCPSOCKET_INTERFACE_1_0 "PPB_TCPSocket;1.0"
#define PPB_TCPSOCKET_INTERFACE_1_1 "PPB_TCPSocket;1.1"
#define PPB_TCPSOCKET_INTERFACE_1_2 "PPB_TCPSocket;1.2"
#define PPB_TCPSOCKET_INTERFACE PPB_TCPSOCKET_INTERFACE_1_2
/**
* @file
* This file defines the <code>PPB_TCPSocket</code> interface.
*/
/**
* @addtogroup Enums
* @{
*/
/**
* Option names used by <code>SetOption()</code>.
*/
typedef enum {
/**
* Disables coalescing of small writes to make TCP segments, and instead
* delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>.
* On version 1.1 or earlier, this option can only be set after a successful
* <code>Connect()</code> call. On version 1.2 or later, there is no such
* limitation.
*/
PP_TCPSOCKET_OPTION_NO_DELAY = 0,
/**
* Specifies the total per-socket buffer space reserved for sends. Value's
* type should be <code>PP_VARTYPE_INT32</code>.
* On version 1.1 or earlier, this option can only be set after a successful
* <code>Connect()</code> call. On version 1.2 or later, there is no such
* limitation.
*
* Note: This is only treated as a hint for the browser to set the buffer
* size. Even if <code>SetOption()</code> succeeds, the browser doesn't
* guarantee it will conform to the size.
*/
PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1,
/**
* Specifies the total per-socket buffer space reserved for receives. Value's
* type should be <code>PP_VARTYPE_INT32</code>.
* On version 1.1 or earlier, this option can only be set after a successful
* <code>Connect()</code> call. On version 1.2 or later, there is no such
* limitation.
*
* Note: This is only treated as a hint for the browser to set the buffer
* size. Even if <code>SetOption()</code> succeeds, the browser doesn't
* guarantee it will conform to the size.
*/
PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2
} PP_TCPSocket_Option;
PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option, 4);
/**
* @}
*/
/**
* @addtogroup Interfaces
* @{
*/
/**
* The <code>PPB_TCPSocket</code> interface provides TCP socket operations.
*
* Permissions: Apps permission <code>socket</code> with subrule
* <code>tcp-connect</code> is required for <code>Connect()</code>; subrule
* <code>tcp-listen</code> is required for <code>Listen()</code>.
* For more details about network communication permissions, please see:
* http://developer.chrome.com/apps/app_network.html
*/
struct PPB_TCPSocket_1_2 {
/**
* Creates a TCP socket resource.
*
* @param[in] instance A <code>PP_Instance</code> identifying one instance of
* a module.
*
* @return A <code>PP_Resource</code> corresponding to a TCP socket or 0
* on failure.
*/
PP_Resource (*Create)(PP_Instance instance);
/**
* Determines if a given resource is a TCP socket.
*
* @param[in] resource A <code>PP_Resource</code> to check.
*
* @return <code>PP_TRUE</code> if the input is a
* <code>PPB_TCPSocket</code> resource; <code>PP_FALSE</code> otherwise.
*/
PP_Bool (*IsTCPSocket)(PP_Resource resource);
/**
* Binds the socket to the given address. The socket must not be bound.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[in] addr A <code>PPB_NetAddress</code> resource.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>,
* including (but not limited to):
* - <code>PP_ERROR_ADDRESS_IN_USE</code>: the address is already in use.
* - <code>PP_ERROR_ADDRESS_INVALID</code>: the address is invalid.
*/
int32_t (*Bind)(PP_Resource tcp_socket,
PP_Resource addr,
struct PP_CompletionCallback callback);
/**
* Connects the socket to the given address. The socket must not be listening.
* Binding the socket beforehand is optional.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[in] addr A <code>PPB_NetAddress</code> resource.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>,
* including (but not limited to):
* - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
* permissions.
* - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is
* unreachable.
* - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was
* refused.
* - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed.
* - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed
* out.
*
* Since version 1.1, if the socket is listening/connected or has a pending
* listen/connect request, <code>Connect()</code> will fail without starting a
* connection attempt; otherwise, any failure during the connection attempt
* will cause the socket to be closed.
*/
int32_t (*Connect)(PP_Resource tcp_socket,
PP_Resource addr,
struct PP_CompletionCallback callback);
/**
* Gets the local address of the socket, if it is bound.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
*
* @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
*/
PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
/**
* Gets the remote address of the socket, if it is connected.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
*
* @return A <code>PPB_NetAddress</code> resource on success or 0 on failure.
*/
PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
/**
* Reads data from the socket. The socket must be connected. It may perform a
* partial read.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[out] buffer The buffer to store the received data on success. It
* must be at least as large as <code>bytes_to_read</code>.
* @param[in] bytes_to_read The number of bytes to read.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return A non-negative number on success to indicate how many bytes have
* been read, 0 means that end-of-file was reached; otherwise, an error code
* from <code>pp_errors.h</code>.
*/
int32_t (*Read)(PP_Resource tcp_socket,
char* buffer,
int32_t bytes_to_read,
struct PP_CompletionCallback callback);
/**
* Writes data to the socket. The socket must be connected. It may perform a
* partial write.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[in] buffer The buffer containing the data to write.
* @param[in] bytes_to_write The number of bytes to write.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return A non-negative number on success to indicate how many bytes have
* been written; otherwise, an error code from <code>pp_errors.h</code>.
*/
int32_t (*Write)(PP_Resource tcp_socket,
const char* buffer,
int32_t bytes_to_write,
struct PP_CompletionCallback callback);
/**
* Starts listening. The socket must be bound and not connected.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[in] backlog A hint to determine the maximum length to which the
* queue of pending connections may grow.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>,
* including (but not limited to):
* - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required
* permissions.
* - <code>PP_ERROR_ADDRESS_IN_USE</code>: Another socket is already listening
* on the same port.
*/
int32_t (*Listen)(PP_Resource tcp_socket,
int32_t backlog,
struct PP_CompletionCallback callback);
/**
* Accepts a connection. The socket must be listening.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[out] accepted_tcp_socket Stores the accepted TCP socket on success.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>,
* including (but not limited to):
* - <code>PP_ERROR_CONNECTION_ABORTED</code>: A connection has been aborted.
*/
int32_t (*Accept)(PP_Resource tcp_socket,
PP_Resource* accepted_tcp_socket,
struct PP_CompletionCallback callback);
/**
* Cancels all pending operations and closes the socket. Any pending callbacks
* will still run, reporting <code>PP_ERROR_ABORTED</code> if pending IO was
* interrupted. After a call to this method, no output buffer pointers passed
* into previous <code>Read()</code> or <code>Accept()</code> calls will be
* accessed. It is not valid to call <code>Connect()</code> or
* <code>Listen()</code> again.
*
* The socket is implicitly closed if it is destroyed, so you are not required
* to call this method.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
*/
void (*Close)(PP_Resource tcp_socket);
/**
* Sets a socket option on the TCP socket.
* Please see the <code>PP_TCPSocket_Option</code> description for option
* names, value types and allowed values.
*
* @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
* socket.
* @param[in] name The option to set.
* @param[in] value The option value to set.
* @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
* completion.
*
* @return An int32_t containing an error code from <code>pp_errors.h</code>.
*/
int32_t (*SetOption)(PP_Resource tcp_socket,
PP_TCPSocket_Option name,
struct PP_Var value,
struct PP_CompletionCallback callback);
};
typedef struct PPB_TCPSocket_1_2 PPB_TCPSocket;
struct PPB_TCPSocket_1_0 {
PP_Resource (*Create)(PP_Instance instance);
PP_Bool (*IsTCPSocket)(PP_Resource resource);
int32_t (*Connect)(PP_Resource tcp_socket,
PP_Resource addr,
struct PP_CompletionCallback callback);
PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
int32_t (*Read)(PP_Resource tcp_socket,
char* buffer,
int32_t bytes_to_read,
struct PP_CompletionCallback callback);
int32_t (*Write)(PP_Resource tcp_socket,
const char* buffer,
int32_t bytes_to_write,
struct PP_CompletionCallback callback);
void (*Close)(PP_Resource tcp_socket);
int32_t (*SetOption)(PP_Resource tcp_socket,
PP_TCPSocket_Option name,
struct PP_Var value,
struct PP_CompletionCallback callback);
};
struct PPB_TCPSocket_1_1 {
PP_Resource (*Create)(PP_Instance instance);
PP_Bool (*IsTCPSocket)(PP_Resource resource);
int32_t (*Bind)(PP_Resource tcp_socket,
PP_Resource addr,
struct PP_CompletionCallback callback);
int32_t (*Connect)(PP_Resource tcp_socket,
PP_Resource addr,
struct PP_CompletionCallback callback);
PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket);
PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket);
int32_t (*Read)(PP_Resource tcp_socket,
char* buffer,
int32_t bytes_to_read,
struct PP_CompletionCallback callback);
int32_t (*Write)(PP_Resource tcp_socket,
const char* buffer,
int32_t bytes_to_write,
struct PP_CompletionCallback callback);
int32_t (*Listen)(PP_Resource tcp_socket,
int32_t backlog,
struct PP_CompletionCallback callback);
int32_t (*Accept)(PP_Resource tcp_socket,
PP_Resource* accepted_tcp_socket,
struct PP_CompletionCallback callback);
void (*Close)(PP_Resource tcp_socket);
int32_t (*SetOption)(PP_Resource tcp_socket,
PP_TCPSocket_Option name,
struct PP_Var value,
struct PP_CompletionCallback callback);
};
/**
* @}
*/
#endif /* PPAPI_C_PPB_TCP_SOCKET_H_ */
|