OLD | NEW |
1 /* Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /* From dev/ppb_tcp_socket_dev.idl modified Wed Jun 12 11:16:37 2013. */ | 6 /* From dev/ppb_tcp_socket_dev.idl modified Thu Jun 20 12:21:11 2013. */ |
7 | 7 |
8 #ifndef PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ | 8 #ifndef PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ |
9 #define PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ | 9 #define PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ |
10 | 10 |
11 #include "ppapi/c/pp_bool.h" | 11 #include "ppapi/c/pp_bool.h" |
12 #include "ppapi/c/pp_completion_callback.h" | 12 #include "ppapi/c/pp_completion_callback.h" |
13 #include "ppapi/c/pp_instance.h" | 13 #include "ppapi/c/pp_instance.h" |
14 #include "ppapi/c/pp_macros.h" | 14 #include "ppapi/c/pp_macros.h" |
15 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
16 #include "ppapi/c/pp_stdint.h" | 16 #include "ppapi/c/pp_stdint.h" |
17 #include "ppapi/c/pp_var.h" | 17 #include "ppapi/c/pp_var.h" |
18 | 18 |
19 #define PPB_TCPSOCKET_DEV_INTERFACE_0_1 "PPB_TCPSocket(Dev);0.1" | 19 #define PPB_TCPSOCKET_DEV_INTERFACE_0_1 "PPB_TCPSocket(Dev);0.1" |
20 #define PPB_TCPSOCKET_DEV_INTERFACE PPB_TCPSOCKET_DEV_INTERFACE_0_1 | 20 #define PPB_TCPSOCKET_DEV_INTERFACE PPB_TCPSOCKET_DEV_INTERFACE_0_1 |
21 | 21 |
22 /** | 22 /** |
23 * @file | 23 * @file |
24 * This file defines the <code>PPB_TCPSocket_Dev</code> interface. | 24 * This file defines the <code>PPB_TCPSocket_Dev</code> interface. |
25 */ | 25 */ |
26 | 26 |
27 | 27 |
28 /** | 28 /** |
29 * @addtogroup Enums | 29 * @addtogroup Enums |
30 * @{ | 30 * @{ |
31 */ | 31 */ |
| 32 /** |
| 33 * Option names used by <code>SetOption()</code>. |
| 34 */ |
32 typedef enum { | 35 typedef enum { |
33 /* Disables coalescing of small writes to make TCP segments, and instead | 36 /** |
34 * deliver data immediately. Value type is PP_VARTYPE_BOOL. */ | 37 * Disables coalescing of small writes to make TCP segments, and instead |
| 38 * delivers data immediately. Value's type is <code>PP_VARTYPE_BOOL</code>. |
| 39 * This option can only be set after a successful <code>Connect()</code> call. |
| 40 */ |
35 PP_TCPSOCKET_OPTION_NO_DELAY = 0, | 41 PP_TCPSOCKET_OPTION_NO_DELAY = 0, |
36 /* Specifies the socket send buffer in bytes. Value's type should be | 42 /** |
37 * PP_VARTYPE_INT32. | 43 * Specifies the total per-socket buffer space reserved for sends. Value's |
| 44 * type should be <code>PP_VARTYPE_INT32</code>. |
| 45 * This option can only be set after a successful <code>Connect()</code> call. |
| 46 * |
38 * Note: This is only treated as a hint for the browser to set the buffer | 47 * Note: This is only treated as a hint for the browser to set the buffer |
39 * size. Even if SetOption() reports that this option has been successfully | 48 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't |
40 * set, the browser doesn't guarantee to conform to it. */ | 49 * guarantee it will conform to the size. |
| 50 */ |
41 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, | 51 PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE = 1, |
42 /* Specifies the socket receive buffer in bytes. Value's type should be | 52 /** |
43 * PP_VARTYPE_INT32. | 53 * Specifies the total per-socket buffer space reserved for receives. Value's |
| 54 * type should be <code>PP_VARTYPE_INT32</code>. |
| 55 * This option can only be set after a successful <code>Connect()</code> call. |
| 56 * |
44 * Note: This is only treated as a hint for the browser to set the buffer | 57 * Note: This is only treated as a hint for the browser to set the buffer |
45 * size. Even if SetOption() reports that this option has been successfully | 58 * size. Even if <code>SetOption()</code> succeeds, the browser doesn't |
46 * set, the browser doesn't guarantee to conform to it. */ | 59 * guarantee it will conform to the size. |
| 60 */ |
47 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 | 61 PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE = 2 |
48 } PP_TCPSocket_Option_Dev; | 62 } PP_TCPSocket_Option_Dev; |
49 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option_Dev, 4); | 63 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TCPSocket_Option_Dev, 4); |
50 /** | 64 /** |
51 * @} | 65 * @} |
52 */ | 66 */ |
53 | 67 |
54 /** | 68 /** |
55 * @addtogroup Interfaces | 69 * @addtogroup Interfaces |
56 * @{ | 70 * @{ |
57 */ | 71 */ |
58 /** | 72 /** |
59 * The <code>PPB_TCPSocket_Dev</code> interface provides TCP socket operations. | 73 * The <code>PPB_TCPSocket_Dev</code> interface provides TCP socket operations. |
| 74 * |
| 75 * Permissions: Apps permission <code>socket</code> with subrule |
| 76 * <code>tcp-connect</code> is required for <code>Connect()</code>. |
| 77 * For more details about network communication permissions, please see: |
| 78 * http://developer.chrome.com/apps/app_network.html |
60 */ | 79 */ |
61 struct PPB_TCPSocket_Dev_0_1 { | 80 struct PPB_TCPSocket_Dev_0_1 { |
62 /** | 81 /** |
63 * Allocates a TCP socket resource. | 82 * Creates a TCP socket resource. |
| 83 * |
| 84 * @param[in] instance A <code>PP_Instance</code> identifying one instance of |
| 85 * a module. |
| 86 * |
| 87 * @return A <code>PP_Resource</code> corresponding to a TCP socket or 0 |
| 88 * on failure. |
64 */ | 89 */ |
65 PP_Resource (*Create)(PP_Instance instance); | 90 PP_Resource (*Create)(PP_Instance instance); |
66 /** | 91 /** |
67 * Determines if a given resource is TCP socket. | 92 * Determines if a given resource is a TCP socket. |
| 93 * |
| 94 * @param[in] resource A <code>PP_Resource</code> to check. |
| 95 * |
| 96 * @return <code>PP_TRUE</code> if the input is a |
| 97 * <code>PPB_TCPSocket_Dev</code> resource; <code>PP_FALSE</code> |
| 98 * otherwise. |
68 */ | 99 */ |
69 PP_Bool (*IsTCPSocket)(PP_Resource resource); | 100 PP_Bool (*IsTCPSocket)(PP_Resource resource); |
70 /** | 101 /** |
71 * Connects to an address given by |addr|, which is a PPB_NetAddress_Dev | 102 * Connects to the given address. |
72 * resource. | 103 * |
| 104 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 105 * socket. |
| 106 * @param[in] addr A <code>PPB_NetAddress_Dev</code> resource. |
| 107 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 108 * completion. |
| 109 * |
| 110 * @return An int32_t containing an error code from <code>pp_errors.h</code>, |
| 111 * including (but not limited to): |
| 112 * - <code>PP_ERROR_NOACCESS</code>: the caller doesn't have required |
| 113 * permissions. |
| 114 * - <code>PP_ERROR_ADDRESS_UNREACHABLE</code>: <code>addr</code> is |
| 115 * unreachable. |
| 116 * - <code>PP_ERROR_CONNECTION_REFUSED</code>: the connection attempt was |
| 117 * refused. |
| 118 * - <code>PP_ERROR_CONNECTION_FAILED</code>: the connection attempt failed. |
| 119 * - <code>PP_ERROR_CONNECTION_TIMEDOUT</code>: the connection attempt timed |
| 120 * out. |
73 */ | 121 */ |
74 int32_t (*Connect)(PP_Resource tcp_socket, | 122 int32_t (*Connect)(PP_Resource tcp_socket, |
75 PP_Resource addr, | 123 PP_Resource addr, |
76 struct PP_CompletionCallback callback); | 124 struct PP_CompletionCallback callback); |
77 /** | 125 /** |
78 * Gets the local address of the socket, if it has been connected. | 126 * Gets the local address of the socket, if it is connected. |
79 * Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure. | 127 * |
| 128 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 129 * socket. |
| 130 * |
| 131 * @return A <code>PPB_NetAddress_Dev</code> resource on success or 0 on |
| 132 * failure. |
80 */ | 133 */ |
81 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); | 134 PP_Resource (*GetLocalAddress)(PP_Resource tcp_socket); |
82 /** | 135 /** |
83 * Gets the remote address of the socket, if it has been connected. | 136 * Gets the remote address of the socket, if it is connected. |
84 * Returns a PPB_NetAddress_Dev resource on success; returns 0 on failure. | 137 * |
| 138 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 139 * socket. |
| 140 * |
| 141 * @return A <code>PPB_NetAddress_Dev</code> resource on success or 0 on |
| 142 * failure. |
85 */ | 143 */ |
86 PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket); | 144 PP_Resource (*GetRemoteAddress)(PP_Resource tcp_socket); |
87 /** | 145 /** |
88 * Reads data from the socket. The size of |buffer| must be at least as large | 146 * Reads data from the socket. The socket must be connected. It may perform a |
89 * as |bytes_to_read|. May perform a partial read. Returns the number of bytes | 147 * partial read. |
90 * read or an error code. If the return value is 0, then it indicates that | |
91 * end-of-file was reached. | |
92 * | 148 * |
93 * Multiple outstanding read requests are not supported. | 149 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 150 * socket. |
| 151 * @param[out] buffer The buffer to store the received data on success. It |
| 152 * must be at least as large as <code>bytes_to_read</code>. |
| 153 * @param[in] bytes_to_read The number of bytes to read. |
| 154 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 155 * completion. |
| 156 * |
| 157 * @return A non-negative number on success to indicate how many bytes have |
| 158 * been read, 0 means that end-of-file was reached; otherwise, an error code |
| 159 * from <code>pp_errors.h</code>. |
94 */ | 160 */ |
95 int32_t (*Read)(PP_Resource tcp_socket, | 161 int32_t (*Read)(PP_Resource tcp_socket, |
96 char* buffer, | 162 char* buffer, |
97 int32_t bytes_to_read, | 163 int32_t bytes_to_read, |
98 struct PP_CompletionCallback callback); | 164 struct PP_CompletionCallback callback); |
99 /** | 165 /** |
100 * Writes data to the socket. May perform a partial write. Returns the number | 166 * Writes data to the socket. The socket must be connected. It may perform a |
101 * of bytes written or an error code. | 167 * partial write. |
102 * | 168 * |
103 * Multiple outstanding write requests are not supported. | 169 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 170 * socket. |
| 171 * @param[in] buffer The buffer containing the data to write. |
| 172 * @param[in] bytes_to_write The number of bytes to write. |
| 173 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 174 * completion. |
| 175 * |
| 176 * @return A non-negative number on success to indicate how many bytes have |
| 177 * been written; otherwise, an error code from <code>pp_errors.h</code>. |
104 */ | 178 */ |
105 int32_t (*Write)(PP_Resource tcp_socket, | 179 int32_t (*Write)(PP_Resource tcp_socket, |
106 const char* buffer, | 180 const char* buffer, |
107 int32_t bytes_to_write, | 181 int32_t bytes_to_write, |
108 struct PP_CompletionCallback callback); | 182 struct PP_CompletionCallback callback); |
109 /** | 183 /** |
110 * Cancels any IO that may be pending, and disconnects the socket. Any pending | 184 * Cancels all pending reads and writes and disconnects the socket. Any |
111 * callbacks will still run, reporting PP_ERROR_ABORTED if pending IO was | 185 * pending callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> |
112 * interrupted. It is NOT valid to call Connect() again after a call to this | 186 * if pending IO was interrupted. After a call to this method, no output |
113 * method. Note: If the socket is destroyed when it is still connected, then | 187 * buffer pointers passed into previous <code>Read()</code> calls will be |
114 * it will be implicitly disconnected, so you are not required to call this | 188 * accessed. It is not valid to call <code>Connect()</code> again. |
115 * method. | 189 * |
| 190 * The socket is implicitly closed if it is destroyed, so you are not required |
| 191 * to call this method. |
| 192 * |
| 193 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 194 * socket. |
116 */ | 195 */ |
117 void (*Close)(PP_Resource tcp_socket); | 196 void (*Close)(PP_Resource tcp_socket); |
118 /** | 197 /** |
119 * Sets an option on |tcp_socket|. Supported |name| and |value| parameters | 198 * Sets a socket option on the TCP socket. |
120 * are as described for PP_TCPSocketOption_Dev. |callback| will be | 199 * Please see the <code>PP_TCPSocket_Option_Dev</code> description for option |
121 * invoked with PP_OK if setting the option succeeds, or an error code | 200 * names, value types and allowed values. |
122 * otherwise. The socket must be connected before SetOption is called. | 201 * |
| 202 * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP |
| 203 * socket. |
| 204 * @param[in] name The option type to set. |
| 205 * @param[in] value The option value to set. |
| 206 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 207 * completion. |
| 208 * |
| 209 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
123 */ | 210 */ |
124 int32_t (*SetOption)(PP_Resource tcp_socket, | 211 int32_t (*SetOption)(PP_Resource tcp_socket, |
125 PP_TCPSocket_Option_Dev name, | 212 PP_TCPSocket_Option_Dev name, |
126 struct PP_Var value, | 213 struct PP_Var value, |
127 struct PP_CompletionCallback callback); | 214 struct PP_CompletionCallback callback); |
128 }; | 215 }; |
129 | 216 |
130 typedef struct PPB_TCPSocket_Dev_0_1 PPB_TCPSocket_Dev; | 217 typedef struct PPB_TCPSocket_Dev_0_1 PPB_TCPSocket_Dev; |
131 /** | 218 /** |
132 * @} | 219 * @} |
133 */ | 220 */ |
134 | 221 |
135 #endif /* PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ */ | 222 #endif /* PPAPI_C_DEV_PPB_TCP_SOCKET_DEV_H_ */ |
136 | 223 |
OLD | NEW |