Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.io; | |
| 6 | |
| 7 /** | |
| 8 * 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.
| |
| 9 * 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.
| |
| 10 * as many RawSynchronousSocket operations are blocking. Unless connecting to a | |
| 11 * socket on localhost, operations such as readSync and readIntoSync are likely | |
| 12 * to block and the socket will not be able to handle any other events while | |
| 13 * blocked on a read or write. For anything more than local connections made by | |
| 14 * simple scripts, please refer to [Socket] or [RawSocket] for asynchronous, | |
| 15 * non-blocking socket implementations. | |
| 16 */ | |
| 17 abstract class RawSynchronousSocket { | |
| 18 /** | |
| 19 * 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.
| |
| 20 * [RawSynchronousSocket]. | |
| 21 * | |
| 22 * [host] can either be a [String] or an [InternetAddress]. If [host] is a | |
| 23 * [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.
| |
| 24 * all returned [InternetAddress]es, until connected. Unless a | |
| 25 * connection was established, the error from the first failing connection is | |
| 26 * returned. | |
| 27 */ | |
| 28 external static RawSynchronousSocket connectSync(host, int port); | |
| 29 | |
| 30 /** | |
| 31 * Returns the number of received and unread bytes in the socket that can be | |
| 32 * read. | |
| 33 */ | |
| 34 int available(); | |
| 35 | |
| 36 /** | |
| 37 * Closes the [RawSynchronousSocket]. | |
| 38 * | |
| 39 * Once [closeSync] has been called, attempting to call [readSync], | |
| 40 * [readIntoSync], [writeFromSync], [remoteAddress], and [remotePort] will | |
| 41 * cause a [SocketException] to be thrown. | |
| 42 */ | |
| 43 void closeSync(); | |
| 44 | |
| 45 /** | |
| 46 * Reads into an existing [List<int>] from the socket into the range: | |
| 47 * [[start],[end]). | |
| 48 * | |
| 49 * Reads into an existing [List<int>] from the socket. If [start] is present, | |
| 50 * the bytes will be filled into [buffer] from index [start], otherwise index | |
| 51 * 0. If [end] is present, [end] - [start] bytes will be read into [buffer], | |
| 52 * otherwise up to [buffer.length]. If [end] == [start], no bytes are read. | |
| 53 * Returns the number of bytes read. | |
| 54 */ | |
| 55 int readIntoSync(List<int> buffer, [int start = 0, int end]); | |
| 56 | |
| 57 /** | |
| 58 * 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.
| |
| 59 * | |
| 60 * 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.
| |
| 61 * sent by the remote server. [bytes] specifies the maximum number of bytes | |
| 62 * to be read. Returns the list of bytes read, which could be less than the | |
| 63 * value specified by [bytes]. | |
| 64 */ | |
| 65 List<int> readSync(int bytes); | |
| 66 | |
| 67 /** | |
| 68 * Shutdown a socket in the provided direction. | |
| 69 * | |
| 70 * Calling shutdown will never throw an exception and calling it several times | |
| 71 * is supported. If both [RECEIVE] and [SEND] directions are closed, the | |
| 72 * socket is closed completely, the same as if [closeSync] has been called. | |
| 73 */ | |
| 74 void shutdown(SocketDirection direction); | |
| 75 | |
| 76 /** | |
| 77 * Writes data from a specified range in a [List<int>] to the socket. | |
| 78 * | |
| 79 * Writes into the socket from a [List<int>]. If [start] is present, the bytes | |
| 80 * will be written to the socket starting from index [start]. If [start] is | |
| 81 * not present, the bytes will be written starting from index 0. If [end] is | |
| 82 * present, the [end] - [start] bytes will be written into the socket starting | |
| 83 * at index [start]. If [end] is not provided, [buffer.length] elements will | |
| 84 * be written to the socket starting from index [start]. If [end] == [start], | |
| 85 * nothing happens. | |
| 86 */ | |
| 87 void writeFromSync(List<int> buffer, [int start = 0, int end]); | |
| 88 | |
| 89 /** | |
| 90 * Returns the port used by this socket. | |
|
zra
2017/04/10 21:39:43
strike "Returns"
bkonyi
2017/04/11 01:30:51
Done.
| |
| 91 */ | |
| 92 int get port; | |
| 93 | |
| 94 /** | |
| 95 * 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.
| |
| 96 */ | |
| 97 int get remotePort; | |
| 98 | |
| 99 /** | |
| 100 * Returns the [InternetAddress] used to connect this socket. | |
|
zra
2017/04/10 21:39:44
ditto
bkonyi
2017/04/11 01:30:52
Done.
| |
| 101 */ | |
| 102 InternetAddress get address; | |
| 103 | |
| 104 /** | |
| 105 * 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.
| |
| 106 */ | |
| 107 InternetAddress get remoteAddress; | |
| 108 } | |
| OLD | NEW |