| Index: tools/dom/src/chrome/socket.dart
|
| diff --git a/tools/dom/src/chrome/socket.dart b/tools/dom/src/chrome/socket.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c80296fec9360c35d84bdbd245d4d1d0832189ef
|
| --- /dev/null
|
| +++ b/tools/dom/src/chrome/socket.dart
|
| @@ -0,0 +1,447 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +// Generated from namespace: socket
|
| +
|
| +part of chrome;
|
| +
|
| +/**
|
| + * Types
|
| + */
|
| +
|
| +class SocketCreateOptions extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketCreateOptions({}) {
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketCreateOptions._proxy(_jsObject) : super._proxy(_jsObject);
|
| +}
|
| +
|
| +class SocketCreateInfo extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketCreateInfo({int socketId}) {
|
| + if (?socketId)
|
| + this.socketId = socketId;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketCreateInfo._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + /// The id of the newly created socket.
|
| + int get socketId => JS('int', '#.socketId', this._jsObject);
|
| +
|
| + void set socketId(int socketId) {
|
| + JS('void', '#.socketId = #', this._jsObject, socketId);
|
| + }
|
| +
|
| +}
|
| +
|
| +class SocketAcceptInfo extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketAcceptInfo({int resultCode, int socketId}) {
|
| + if (?resultCode)
|
| + this.resultCode = resultCode;
|
| + if (?socketId)
|
| + this.socketId = socketId;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketAcceptInfo._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + int get resultCode => JS('int', '#.resultCode', this._jsObject);
|
| +
|
| + void set resultCode(int resultCode) {
|
| + JS('void', '#.resultCode = #', this._jsObject, resultCode);
|
| + }
|
| +
|
| + /// The id of the accepted socket.
|
| + int get socketId => JS('int', '#.socketId', this._jsObject);
|
| +
|
| + void set socketId(int socketId) {
|
| + JS('void', '#.socketId = #', this._jsObject, socketId);
|
| + }
|
| +
|
| +}
|
| +
|
| +class SocketReadInfo extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketReadInfo({int resultCode, String data}) {
|
| + if (?resultCode)
|
| + this.resultCode = resultCode;
|
| + if (?data)
|
| + this.data = data;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketReadInfo._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + /// The resultCode returned from the underlying read() call.
|
| + int get resultCode => JS('int', '#.resultCode', this._jsObject);
|
| +
|
| + void set resultCode(int resultCode) {
|
| + JS('void', '#.resultCode = #', this._jsObject, resultCode);
|
| + }
|
| +
|
| + String get data => JS('String', '#.data', this._jsObject);
|
| +
|
| + void set data(String data) {
|
| + JS('void', '#.data = #', this._jsObject, data);
|
| + }
|
| +
|
| +}
|
| +
|
| +class SocketWriteInfo extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketWriteInfo({int bytesWritten}) {
|
| + if (?bytesWritten)
|
| + this.bytesWritten = bytesWritten;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketWriteInfo._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + /// The number of bytes sent, or a negative error code.
|
| + int get bytesWritten => JS('int', '#.bytesWritten', this._jsObject);
|
| +
|
| + void set bytesWritten(int bytesWritten) {
|
| + JS('void', '#.bytesWritten = #', this._jsObject, bytesWritten);
|
| + }
|
| +
|
| +}
|
| +
|
| +class SocketRecvFromInfo extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketRecvFromInfo({int resultCode, String data, String address, int port}) {
|
| + if (?resultCode)
|
| + this.resultCode = resultCode;
|
| + if (?data)
|
| + this.data = data;
|
| + if (?address)
|
| + this.address = address;
|
| + if (?port)
|
| + this.port = port;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketRecvFromInfo._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + /// The resultCode returned from the underlying recvfrom() call.
|
| + int get resultCode => JS('int', '#.resultCode', this._jsObject);
|
| +
|
| + void set resultCode(int resultCode) {
|
| + JS('void', '#.resultCode = #', this._jsObject, resultCode);
|
| + }
|
| +
|
| + String get data => JS('String', '#.data', this._jsObject);
|
| +
|
| + void set data(String data) {
|
| + JS('void', '#.data = #', this._jsObject, data);
|
| + }
|
| +
|
| + /// The address of the remote machine.
|
| + String get address => JS('String', '#.address', this._jsObject);
|
| +
|
| + void set address(String address) {
|
| + JS('void', '#.address = #', this._jsObject, address);
|
| + }
|
| +
|
| + int get port => JS('int', '#.port', this._jsObject);
|
| +
|
| + void set port(int port) {
|
| + JS('void', '#.port = #', this._jsObject, port);
|
| + }
|
| +
|
| +}
|
| +
|
| +class SocketSocketInfo extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketSocketInfo({String socketType, bool connected, String peerAddress, int peerPort, String localAddress, int localPort}) {
|
| + if (?socketType)
|
| + this.socketType = socketType;
|
| + if (?connected)
|
| + this.connected = connected;
|
| + if (?peerAddress)
|
| + this.peerAddress = peerAddress;
|
| + if (?peerPort)
|
| + this.peerPort = peerPort;
|
| + if (?localAddress)
|
| + this.localAddress = localAddress;
|
| + if (?localPort)
|
| + this.localPort = localPort;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketSocketInfo._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + /// The type of the passed socket. This will be <code>tcp</code> or
|
| + /// <code>udp</code>.
|
| + String get socketType => JS('String', '#.socketType', this._jsObject);
|
| +
|
| + void set socketType(String socketType) {
|
| + JS('void', '#.socketType = #', this._jsObject, socketType);
|
| + }
|
| +
|
| + /// Whether or not the underlying socket is connected.<br/><br/> For
|
| + /// <code>tcp</code> sockets, this will remain true even if the remote peer has
|
| + /// disconnected. Reading or writing to the socket may then result in an error,
|
| + /// hinting that this socket should be disconnected via
|
| + /// <code>disconnect()</code>.<br/><br/> For <code>udp</code> sockets, this
|
| + /// just represents whether a default remote address has been specified for
|
| + /// reading and writing packets.
|
| + bool get connected => JS('bool', '#.connected', this._jsObject);
|
| +
|
| + void set connected(bool connected) {
|
| + JS('void', '#.connected = #', this._jsObject, connected);
|
| + }
|
| +
|
| + /// If the underlying socket is connected, contains the IPv4/6 address of the
|
| + /// peer.
|
| + String get peerAddress => JS('String', '#.peerAddress', this._jsObject);
|
| +
|
| + void set peerAddress(String peerAddress) {
|
| + JS('void', '#.peerAddress = #', this._jsObject, peerAddress);
|
| + }
|
| +
|
| + /// If the underlying socket is connected, contains the port of the connected
|
| + /// peer.
|
| + int get peerPort => JS('int', '#.peerPort', this._jsObject);
|
| +
|
| + void set peerPort(int peerPort) {
|
| + JS('void', '#.peerPort = #', this._jsObject, peerPort);
|
| + }
|
| +
|
| + /// If the underlying socket is bound or connected, contains its local IPv4/6
|
| + /// address.
|
| + String get localAddress => JS('String', '#.localAddress', this._jsObject);
|
| +
|
| + void set localAddress(String localAddress) {
|
| + JS('void', '#.localAddress = #', this._jsObject, localAddress);
|
| + }
|
| +
|
| + /// If the underlying socket is bound or connected, contains its local port.
|
| + int get localPort => JS('int', '#.localPort', this._jsObject);
|
| +
|
| + void set localPort(int localPort) {
|
| + JS('void', '#.localPort = #', this._jsObject, localPort);
|
| + }
|
| +
|
| +}
|
| +
|
| +class SocketNetworkInterface extends ChromeObject {
|
| + /*
|
| + * Public constructor
|
| + */
|
| + SocketNetworkInterface({String name, String address}) {
|
| + if (?name)
|
| + this.name = name;
|
| + if (?address)
|
| + this.address = address;
|
| + }
|
| +
|
| + /*
|
| + * Private constructor
|
| + */
|
| + SocketNetworkInterface._proxy(_jsObject) : super._proxy(_jsObject);
|
| +
|
| + /*
|
| + * Public accessors
|
| + */
|
| + /// The underlying name of the adapter. On *nix, this will typically be "eth0",
|
| + /// "lo", etc.
|
| + String get name => JS('String', '#.name', this._jsObject);
|
| +
|
| + void set name(String name) {
|
| + JS('void', '#.name = #', this._jsObject, name);
|
| + }
|
| +
|
| + /// The available IPv4/6 address.
|
| + String get address => JS('String', '#.address', this._jsObject);
|
| +
|
| + void set address(String address) {
|
| + JS('void', '#.address = #', this._jsObject, address);
|
| + }
|
| +
|
| +}
|
| +
|
| +/**
|
| + * Functions
|
| + */
|
| +
|
| +class API_socket {
|
| + /*
|
| + * API connection
|
| + */
|
| + Object _jsObject;
|
| +
|
| + /*
|
| + * Functions
|
| + */
|
| + /// Creates a socket of the specified type that will connect to the specified
|
| + /// remote machine.
|
| + void create(String type, void callback(SocketCreateInfo createInfo), [SocketCreateOptions options]) {
|
| + void __proxy_callback(createInfo) {
|
| + if (?callback) {
|
| + callback(new SocketCreateInfo._proxy(createInfo));
|
| + }
|
| + }
|
| + JS('void', '#.create(#, #, #)', this._jsObject, type, convertArgument(options), convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// Destroys the socket. Each socket created should be destroyed after use.
|
| + void destroy(int socketId) => JS('void', '#.destroy(#)', this._jsObject, socketId);
|
| +
|
| + /// Connects the socket to the remote machine (for a <code>tcp</code> socket).
|
| + /// For a <code>udp</code> socket, this sets the default address which packets
|
| + /// are sent to and read from for <code>read()</code> and <code>write()</code>
|
| + /// calls.
|
| + void connect(int socketId, String hostname, int port, void callback(int result)) => JS('void', '#.connect(#, #, #, #)', this._jsObject, socketId, hostname, port, convertDartClosureToJS(callback, 1));
|
| +
|
| + /// Binds the local address for socket. Currently, it does not support TCP
|
| + /// socket.
|
| + void bind(int socketId, String address, int port, void callback(int result)) => JS('void', '#.bind(#, #, #, #)', this._jsObject, socketId, address, port, convertDartClosureToJS(callback, 1));
|
| +
|
| + /// Disconnects the socket. For UDP sockets, <code>disconnect</code> is a
|
| + /// non-operation but is safe to call.
|
| + void disconnect(int socketId) => JS('void', '#.disconnect(#)', this._jsObject, socketId);
|
| +
|
| + /// Reads data from the given connected socket.
|
| + void read(int socketId, void callback(SocketReadInfo readInfo), [int bufferSize]) {
|
| + void __proxy_callback(readInfo) {
|
| + if (?callback) {
|
| + callback(new SocketReadInfo._proxy(readInfo));
|
| + }
|
| + }
|
| + JS('void', '#.read(#, #, #)', this._jsObject, socketId, bufferSize, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// Writes data on the given connected socket.
|
| + void write(int socketId, String data, void callback(SocketWriteInfo writeInfo)) {
|
| + void __proxy_callback(writeInfo) {
|
| + if (?callback) {
|
| + callback(new SocketWriteInfo._proxy(writeInfo));
|
| + }
|
| + }
|
| + JS('void', '#.write(#, #, #)', this._jsObject, socketId, data, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// Receives data from the given UDP socket.
|
| + void recvFrom(int socketId, void callback(SocketRecvFromInfo recvFromInfo), [int bufferSize]) {
|
| + void __proxy_callback(recvFromInfo) {
|
| + if (?callback) {
|
| + callback(new SocketRecvFromInfo._proxy(recvFromInfo));
|
| + }
|
| + }
|
| + JS('void', '#.recvFrom(#, #, #)', this._jsObject, socketId, bufferSize, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// Sends data on the given UDP socket to the given address and port.
|
| + void sendTo(int socketId, String data, String address, int port, void callback(SocketWriteInfo writeInfo)) {
|
| + void __proxy_callback(writeInfo) {
|
| + if (?callback) {
|
| + callback(new SocketWriteInfo._proxy(writeInfo));
|
| + }
|
| + }
|
| + JS('void', '#.sendTo(#, #, #, #, #)', this._jsObject, socketId, data, address, port, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// This method applies to TCP sockets only. Listens for connections on the
|
| + /// specified port and address. This effectively makes this a server socket,
|
| + /// and client socket functions (connect, read, write) can no longer be used on
|
| + /// this socket.
|
| + void listen(int socketId, String address, int port, void callback(int result), [int backlog]) => JS('void', '#.listen(#, #, #, #, #)', this._jsObject, socketId, address, port, backlog, convertDartClosureToJS(callback, 1));
|
| +
|
| + /// This method applies to TCP sockets only. Registers a callback function to
|
| + /// be called when a connection is accepted on this listening server socket.
|
| + /// Listen must be called first. If there is already an active accept callback,
|
| + /// this callback will be invoked immediately with an error as the resultCode.
|
| + void accept(int socketId, void callback(SocketAcceptInfo acceptInfo)) {
|
| + void __proxy_callback(acceptInfo) {
|
| + if (?callback) {
|
| + callback(new SocketAcceptInfo._proxy(acceptInfo));
|
| + }
|
| + }
|
| + JS('void', '#.accept(#, #)', this._jsObject, socketId, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// Enables or disables the keep-alive functionality for a TCP connection.
|
| + void setKeepAlive(int socketId, bool enable, void callback(bool result), [int delay]) => JS('void', '#.setKeepAlive(#, #, #, #)', this._jsObject, socketId, enable, delay, convertDartClosureToJS(callback, 1));
|
| +
|
| + /// Sets or clears <code>TCP_NODELAY</code> for a TCP connection. Nagle's
|
| + /// algorithm will be disabled when <code>TCP_NODELAY</code> is set.
|
| + void setNoDelay(int socketId, bool noDelay, void callback(bool result)) => JS('void', '#.setNoDelay(#, #, #)', this._jsObject, socketId, noDelay, convertDartClosureToJS(callback, 1));
|
| +
|
| + /// Retrieves the state of the given socket.
|
| + void getInfo(int socketId, void callback(SocketSocketInfo result)) {
|
| + void __proxy_callback(result) {
|
| + if (?callback) {
|
| + callback(new SocketSocketInfo._proxy(result));
|
| + }
|
| + }
|
| + JS('void', '#.getInfo(#, #)', this._jsObject, socketId, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + /// Retrieves information about local adapters on this system.
|
| + void getNetworkList(void callback(List<SocketNetworkInterface> result)) {
|
| + void __proxy_callback(result) {
|
| + if (?callback) {
|
| + List<SocketNetworkInterface> __proxy_result = new List<SocketNetworkInterface>();
|
| + for (var o in result) {
|
| + __proxy_result.add(new SocketNetworkInterface._proxy(o));
|
| + }
|
| + callback(__proxy_result);
|
| + }
|
| + }
|
| + JS('void', '#.getNetworkList(#)', this._jsObject, convertDartClosureToJS(__proxy_callback, 1));
|
| + }
|
| +
|
| + API_socket(this._jsObject) {
|
| + }
|
| +}
|
|
|