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..4fdeed1da280cbe55e6b27b5d5ae2acdb234b6d5 |
--- /dev/null |
+++ b/sdk/lib/io/sync_socket.dart |
@@ -0,0 +1,108 @@ |
+// Copyright (c) 2017, 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. |
+ |
+part of dart.io; |
+ |
+/** |
+ * A low-level class for communicating synchronously over a TCP socket. |
zra
2017/04/10 21:39:43
Add another line break here.
bkonyi
2017/04/11 01:30:52
Done.
|
+ * Warning: This socket implementation is not suitable for most Socket I/O tasks |
zra
2017/04/10 21:39:44
I'd prefer something more like:
"Warning: [RawSyn
bkonyi
2017/04/11 01:30:51
Done.
|
+ * as many RawSynchronousSocket operations are blocking. Unless connecting to a |
+ * socket on localhost, operations such as readSync and readIntoSync are likely |
+ * to block and the socket will not be able to handle any other events while |
+ * blocked on a read or write. For anything more than local connections made by |
+ * simple scripts, please refer to [Socket] or [RawSocket] for asynchronous, |
+ * non-blocking socket implementations. |
+ */ |
+abstract class RawSynchronousSocket { |
+ /** |
+ * Creates a new socket connection to the host and port and returns a |
zra
2017/04/10 21:39:44
strike: 'to the host and port'
bkonyi
2017/04/11 01:30:51
Done.
|
+ * [RawSynchronousSocket]. |
+ * |
+ * [host] can either be a [String] or an [InternetAddress]. If [host] is a |
+ * [String], [connect] will perform a [InternetAddress.lookup] and try |
zra
2017/04/10 21:39:44
connect -> connectSync
bkonyi
2017/04/11 01:30:51
Done.
|
+ * 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]. |
+ * |
+ * Once [closeSync] has been called, attempting to call [readSync], |
+ * [readIntoSync], [writeFromSync], [remoteAddress], and [remotePort] will |
+ * cause a [SocketException] to be thrown. |
+ */ |
+ void closeSync(); |
+ |
+ /** |
+ * Reads into an existing [List<int>] from the socket into the range: |
+ * [[start],[end]). |
+ * |
+ * Reads into an existing [List<int>] from the socket. If [start] is present, |
+ * 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]); |
+ |
+ /** |
+ * Blocks and waits for a response from the server. |
zra
2017/04/10 21:39:44
"Reads up to [bytes] bytes from the socket."
bkonyi
2017/04/11 01:30:51
Done.
|
+ * |
+ * Blocks and waits for a response of up to a specified number of bytes |
zra
2017/04/10 21:39:44
Replace "remove server" with "socket".
bkonyi
2017/04/11 01:30:51
Done.
|
+ * sent by the remote server. [bytes] specifies the maximum number of bytes |
+ * to be read. Returns the list of bytes read, which could be less than the |
+ * value specified by [bytes]. |
+ */ |
+ List<int> readSync(int bytes); |
+ |
+ /** |
+ * Shutdown a socket in the provided direction. |
+ * |
+ * Calling shutdown will never throw an exception and calling it several times |
+ * is supported. If both [RECEIVE] and [SEND] directions are closed, the |
+ * socket is closed completely, the same as if [closeSync] has been called. |
+ */ |
+ void shutdown(SocketDirection direction); |
+ |
+ /** |
+ * Writes data from a specified range in a [List<int>] to the socket. |
+ * |
+ * 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. |
zra
2017/04/10 21:39:43
strike "Returns"
bkonyi
2017/04/11 01:30:51
Done.
|
+ */ |
+ int get port; |
+ |
+ /** |
+ * Returns the remote port connected to by this socket. |
zra
2017/04/10 21:39:44
ditto
bkonyi
2017/04/11 01:30:51
Done.
|
+ */ |
+ int get remotePort; |
+ |
+ /** |
+ * Returns the [InternetAddress] used to connect this socket. |
zra
2017/04/10 21:39:44
ditto
bkonyi
2017/04/11 01:30:52
Done.
|
+ */ |
+ InternetAddress get address; |
+ |
+ /** |
+ * Returns the remote [InternetAddress] connected to by this socket. |
zra
2017/04/10 21:39:44
ditto
bkonyi
2017/04/11 01:30:51
Done.
|
+ */ |
+ InternetAddress get remoteAddress; |
+} |