OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 namespace socket { | 5 namespace socket { |
6 enum SocketType { | 6 enum SocketType { |
7 tcp, | 7 tcp, |
8 udp | 8 udp |
9 }; | 9 }; |
10 | 10 |
11 // The socket options. | 11 // The socket options. |
12 dictionary CreateOptions { | 12 dictionary CreateOptions { |
13 }; | 13 }; |
14 | 14 |
15 dictionary CreateInfo { | 15 dictionary CreateInfo { |
16 // The id of the newly created socket. | 16 // The id of the newly created socket. |
17 long socketId; | 17 long socketId; |
18 }; | 18 }; |
19 | 19 |
| 20 dictionary AcceptInfo { |
| 21 // The id of the accepted socket. |
| 22 long socketId; |
| 23 long resultCode; |
| 24 }; |
| 25 |
20 callback CreateCallback = void (CreateInfo createInfo); | 26 callback CreateCallback = void (CreateInfo createInfo); |
21 | 27 |
22 callback ConnectCallback = void (long result); | 28 callback ConnectCallback = void (long result); |
23 | 29 |
24 callback BindCallback = void (long result); | 30 callback BindCallback = void (long result); |
25 | 31 |
| 32 callback ListenCallback = void (long result); |
| 33 |
| 34 callback AcceptCallback = void (AcceptInfo acceptInfo); |
| 35 |
26 dictionary ReadInfo { | 36 dictionary ReadInfo { |
27 // The resultCode returned from the underlying read() call. | 37 // The resultCode returned from the underlying read() call. |
28 long resultCode; | 38 long resultCode; |
29 | 39 |
30 ArrayBuffer data; | 40 ArrayBuffer data; |
31 }; | 41 }; |
32 | 42 |
33 callback ReadCallback = void (ReadInfo readInfo); | 43 callback ReadCallback = void (ReadInfo readInfo); |
34 | 44 |
35 dictionary WriteInfo { | 45 dictionary WriteInfo { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // and <code>write()</code> calls. | 135 // and <code>write()</code> calls. |
126 // |socketId| : The socketId. | 136 // |socketId| : The socketId. |
127 // |hostname| : The hostname or IP address of the remote machine. | 137 // |hostname| : The hostname or IP address of the remote machine. |
128 // |port| : The port of the remote machine. | 138 // |port| : The port of the remote machine. |
129 // |callback| : Called when the connection attempt is complete. | 139 // |callback| : Called when the connection attempt is complete. |
130 static void connect(long socketId, | 140 static void connect(long socketId, |
131 DOMString hostname, | 141 DOMString hostname, |
132 long port, | 142 long port, |
133 ConnectCallback callback); | 143 ConnectCallback callback); |
134 | 144 |
135 // Binds the local address for socket. Currently, it does not support | 145 // Binds the local address for socket. |
136 // TCP socket. | |
137 // |socketId| : The socketId. | 146 // |socketId| : The socketId. |
138 // |address| : The address of the local machine. | 147 // |address| : The address of the local machine. |
139 // |port| : The port of the local machine. | 148 // |port| : The port of the local machine. |
140 // |callback| : Called when the bind attempt is complete. | 149 // |callback| : Called when the bind attempt is complete. |
141 static void bind(long socketId, | 150 static void bind(long socketId, |
142 DOMString address, | 151 DOMString address, |
143 long port, | 152 long port, |
144 BindCallback callback); | 153 BindCallback callback); |
145 | 154 |
| 155 // This method applies to TCP sockets only. |
| 156 // Listens for connections on the specified port that this socket was bound |
| 157 // to. This effectively makes this a server socket and client socket |
| 158 // functions (connect, read, write) can no longer be used on this socket. |
| 159 // |socketId| : The socketId. |
| 160 // |backlog| : Length of the socket's accept queue. |
| 161 static void listen(long socketId, |
| 162 long backlog, |
| 163 ListenCallback callback); |
| 164 |
| 165 // This method applies to TCP sockets only. |
| 166 // Starts waiting for connections on the listening server socket. |
| 167 // |socketId| : The socketId. |
| 168 // |callback| : The callback is invoked when a new socket is accepted. |
| 169 static void accept(long socketId, |
| 170 AcceptCallback callback); |
| 171 |
146 // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a | 172 // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a |
147 // non-operation but is safe to call. | 173 // non-operation but is safe to call. |
148 // |socketId| : The socketId. | 174 // |socketId| : The socketId. |
149 static void disconnect(long socketId); | 175 static void disconnect(long socketId); |
150 | 176 |
151 // Reads data from the given connected socket. | 177 // Reads data from the given connected socket. |
152 // |socketId| : The socketId. | 178 // |socketId| : The socketId. |
153 // |bufferSize| : The read buffer size. | 179 // |bufferSize| : The read buffer size. |
154 // |callback| : Delivers data that was available to be read without | 180 // |callback| : Delivers data that was available to be read without |
155 // blocking. | 181 // blocking. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // |callback| : Called when the state is available. | 238 // |callback| : Called when the state is available. |
213 static void getInfo(long socketId, | 239 static void getInfo(long socketId, |
214 GetInfoCallback callback); | 240 GetInfoCallback callback); |
215 | 241 |
216 // Retrieves information about local adapters on this system. | 242 // Retrieves information about local adapters on this system. |
217 // |callback| : Called when local adapter information is available. | 243 // |callback| : Called when local adapter information is available. |
218 static void getNetworkList(GetNetworkCallback callback); | 244 static void getNetworkList(GetNetworkCallback callback); |
219 }; | 245 }; |
220 | 246 |
221 }; | 247 }; |
OLD | NEW |