Index: sdk/lib/io/sync_socket.dart |
diff --git a/sdk/lib/io/sync_socket.dart b/sdk/lib/io/sync_socket.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3c79a7644a51484e2792d0a80adf9d1a9171f518 |
--- /dev/null |
+++ b/sdk/lib/io/sync_socket.dart |
@@ -0,0 +1,86 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
zra
2017/04/07 16:29:41
2017
bkonyi
2017/04/10 19:20:06
Done.
|
+// 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. |
+ |
+part of dart.io; |
+ |
+/** |
+ * A low-level class for communicating over a TCP socket. |
zra
2017/04/07 16:29:41
Add warnings that direct people to the asynchronou
bkonyi
2017/04/10 19:20:06
Done.
|
+ */ |
+abstract class RawSynchronousSocket { |
+ /** |
+ * Creates a new socket connection to the host and port and returns a |
+ * [RawSynchronousSocket]. |
+ * |
+ * [host] can either be a [String] or an [InternetAddress]. If [host] is a |
+ * [String], [connect] will perform a [InternetAddress.lookup] and try |
+ * all returned [InternetAddress]es, until connected. Unless a |
+ * connection was established, the error from the first failing connection is |
+ * returned. |
+ */ |
+ external static RawSynchronousSocket connectSync(host, int port); |
+ |
+ /** |
+ * Returns the number of received and unread bytes in the socket that can be |
+ * read. |
+ */ |
+ int available(); |
+ |
+ /** |
+ * Closes the [RawSynchronousSocket]. |
+ */ |
+ void closeSync(); |
+ |
+ /** |
+ * Reads into an existing [List<int>] from the socket. If [start] is present, |
zra
2017/04/07 16:29:41
These comments should have a short one sentence de
bkonyi
2017/04/10 19:20:06
Done.
|
+ * the bytes will be filled into [buffer] from index [start], otherwise index |
+ * 0. If [end] is present, [end] - [start] bytes will be read into [buffer], |
+ * otherwise up to [buffer.length]. If [end] == [start], no bytes are read. |
+ * Returns the number of bytes read. |
+ */ |
+ int readIntoSync(List<int> buffer, [int start = 0, int end]); |
+ |
+ // TODO(bkonyi) Update description. |
+ /** |
+ * Blocks and waits for a response of an arbitrary number of bytes sent by the |
+ * remote server. If [bytes] is provided, it will be used as the maximum |
+ * number of bytes to be read. Returns the list of bytes read. |
+ */ |
+ List<int> readSync(int bytes); |
+ |
+ /** |
+ * TODO(bkonyi) shutdown? |
+ */ |
+ void shutdown(SocketDirection direction); |
+ |
+ /** |
+ * Writes into the socket from a [List<int>]. If [start] is present, the bytes |
+ * will be written to the socket starting from index [start]. If [start] is |
+ * not present, the bytes will be written starting from index 0. If [end] is |
+ * present, the [end] - [start] bytes will be written into the socket starting |
+ * at index [start]. If [end] is not provided, [buffer.length] elements will |
+ * be written to the socket starting from index [start]. If [end] == [start], |
+ * nothing happens. |
+ */ |
+ void writeFromSync(List<int> buffer, [int start = 0, int end]); |
+ |
+ /** |
+ * Returns the port used by this socket. |
+ */ |
+ int get port; |
+ |
+ /** |
+ * Returns the remote port connected to by this socket. |
+ */ |
+ int get remotePort; |
+ |
+ /** |
+ * Returns the [InternetAddress] used to connect this socket. |
+ */ |
+ InternetAddress get address; |
+ |
+ /** |
+ * Returns the remote [InternetAddress] connected to by this socket. |
+ */ |
+ InternetAddress get remoteAddress; |
+} |