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 // File-level comment to appease parser. Eventually this will not be necessary. | 5 // File-level comment to appease parser. Eventually this will not be necessary. |
6 | 6 |
7 namespace socket { | 7 namespace socket { |
8 enum SocketType { | 8 enum SocketType { |
9 tcp, | 9 tcp, |
10 udp | 10 udp |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 long resultCode; | 46 long resultCode; |
47 | 47 |
48 ArrayBuffer data; | 48 ArrayBuffer data; |
49 | 49 |
50 // The address of the remote machine. | 50 // The address of the remote machine. |
51 DOMString address; | 51 DOMString address; |
52 | 52 |
53 long port; | 53 long port; |
54 }; | 54 }; |
55 | 55 |
56 dictionary SocketInfo { | |
57 // The type of the passed socket. This will be <code>tcp</code> or | |
58 // <code>udp</code>. | |
59 SocketType socketType; | |
60 | |
61 // Whether or not the underlying socket is connected. | |
62 // | |
63 // For <code>tcp</code> sockets, this will remain true even if the remote | |
64 // peer has disconnected. Reading or writing to the socket may then result | |
65 // in an error, hinting that this socket should be disconnected via | |
66 // <code>disconnect()</code>. | |
67 // | |
68 // For <code>udp</code> sockets, this just represents whether a default | |
69 // remote address has been specified for reading and writing packets. | |
70 boolean connected; | |
71 | |
72 // If the underlying socket is connected, contains the IPv4/6 address of | |
73 // the peer. | |
74 DOMString? peerAddress; | |
75 | |
76 // If the underlying socket is connected, contains the port of the | |
77 // connected peer. | |
78 long? peerPort; | |
79 | |
80 // If the underlying socket is bound or connected, contains its local | |
81 // IPv4/6 address. | |
82 DOMString? localAddress; | |
83 | |
84 // If the underlying socket is bound or connected, contains its local port. | |
85 long? localPort; | |
86 }; | |
87 | |
56 callback RecvFromCallback = void (RecvFromInfo recvFromInfo); | 88 callback RecvFromCallback = void (RecvFromInfo recvFromInfo); |
57 | 89 |
58 callback SendToCallback = void (WriteInfo writeInfo); | 90 callback SendToCallback = void (WriteInfo writeInfo); |
59 | 91 |
60 callback SetKeepAliveCallback = void (boolean result); | 92 callback SetKeepAliveCallback = void (boolean result); |
61 | 93 |
62 callback SetNoDelayCallback = void (boolean result); | 94 callback SetNoDelayCallback = void (boolean result); |
63 | 95 |
96 callback GetInfoCallback = void (SocketInfo result); | |
97 | |
64 interface Functions { | 98 interface Functions { |
65 // Creates a socket of the specified type that will connect to the specified | 99 // Creates a socket of the specified type that will connect to the specified |
66 // remote machine. | 100 // remote machine. |
67 // |type| : The type of socket to create. Must be <code>tcp</code> or | 101 // |type| : The type of socket to create. Must be <code>tcp</code> or |
68 // <code>udp</code>. | 102 // <code>udp</code>. |
69 // |options| : The socket options. | 103 // |options| : The socket options. |
70 // |callback| : Called when the socket has been created. | 104 // |callback| : Called when the socket has been created. |
71 static void create(SocketType type, | 105 static void create(SocketType type, |
72 optional CreateOptions options, | 106 optional CreateOptions options, |
73 CreateCallback callback); | 107 CreateCallback callback); |
74 | 108 |
75 // Destroys the socket. Each socket created should be destroyed after use. | 109 // Destroys the socket. Each socket created should be destroyed after use. |
76 // |socketId| : The socketId. | 110 // |socketId| : The socketId. |
77 static void destroy(long socketId); | 111 static void destroy(long socketId); |
78 | 112 |
79 // Connects the socket to the remote machine. | 113 // Connects the socket to the remote machine (for a <code>tcp</code> |
114 // socket). For a <code>udp</code> socket, this sets the default address | |
115 // which packets are sent to and read from for <code>read()</code> | |
116 // and <code>write()</code> calls. | |
80 // |socketId| : The socketId. | 117 // |socketId| : The socketId. |
81 // |hostname| : The hostname or IP address of the remote machine. | 118 // |hostname| : The hostname or IP address of the remote machine. |
82 // |port| : The port of the remote machine. | 119 // |port| : The port of the remote machine. |
83 // |callback| : Called when the connection attempt is complete. | 120 // |callback| : Called when the connection attempt is complete. |
84 static void connect(long socketId, | 121 static void connect(long socketId, |
85 DOMString hostname, | 122 DOMString hostname, |
86 long port, | 123 long port, |
87 ConnectCallback callback); | 124 ConnectCallback callback); |
88 | 125 |
89 // Binds the local address for socket. Currently, it does not support | 126 // Binds the local address for socket. Currently, it does not support |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // |address| : The address of the remote machine. | 171 // |address| : The address of the remote machine. |
135 // |port| : The port of the remote machine. | 172 // |port| : The port of the remote machine. |
136 // |callback| : Called when the send operation completes without blocking | 173 // |callback| : Called when the send operation completes without blocking |
137 // or an error occurs. | 174 // or an error occurs. |
138 static void sendTo(long socketId, | 175 static void sendTo(long socketId, |
139 ArrayBuffer data, | 176 ArrayBuffer data, |
140 DOMString address, | 177 DOMString address, |
141 long port, | 178 long port, |
142 SendToCallback callback); | 179 SendToCallback callback); |
143 | 180 |
144 // Enable/disable keep-alive functionality for a TCP connection. | 181 // Enables or disables the keep-alive functionality for a TCP connection. |
145 // |socketId| : The socketId. | 182 // |socketId| : The socketId. |
146 // |enable| : If true, enable keep-alive functionality. | 183 // |enable| : If true, enable keep-alive functionality. |
147 // |delay| : Set the delay seconds between the last data packet received | 184 // |delay| : Set the delay seconds between the last data packet received |
148 // and the first keepalive probe. Default is 0. | 185 // and the first keepalive probe. Default is 0. |
149 // |callback| : Called when the setKeepAlive attempt is complete. | 186 // |callback| : Called when the setKeepAlive attempt is complete. |
150 static void setKeepAlive(long socketId, | 187 static void setKeepAlive(long socketId, |
151 boolean enable, | 188 boolean enable, |
152 optional long delay, | 189 optional long delay, |
153 SetKeepAliveCallback callback); | 190 SetKeepAliveCallback callback); |
154 | 191 |
155 // Enable/disable Nagle algorithm. | 192 // Sets or clears <code>TCP_NODELAY</code> for a TCP connection. Nagle's |
193 // algorithm will be disabled when <code>TCP_NODELAY</code> is set. | |
156 // |socketId| : The socketId. | 194 // |socketId| : The socketId. |
157 // |noDelay| : If true, disable Nagle algorithm. | 195 // |noDelay| : If true, disables Nagle's algorithm. |
158 // |callback| : Called when the setNoDelay attempt is complete. | 196 // |callback| : Called when the setNoDelay attempt is complete. |
159 static void setNoDelay(long socketId, | 197 static void setNoDelay(long socketId, |
160 boolean noDelay, | 198 boolean noDelay, |
161 SetNoDelayCallback callback); | 199 SetNoDelayCallback callback); |
200 | |
201 // Retrieves the state of the given socket. | |
202 // |socketId| : The socketId. | |
203 // |callback| : Called when the state is available. | |
204 static void getInfo(long socketId, | |
Peng
2012/08/03 14:13:36
I am not sure if new added function should be expe
thorogood
2012/08/05 02:22:57
Since the whole API is now out of experimental, I'
miket_OOO
2012/08/06 21:47:53
Yes, that's fine; it's additive and backward-compa
| |
205 GetInfoCallback callback); | |
162 }; | 206 }; |
163 | 207 |
164 }; | 208 }; |
OLD | NEW |