Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: sdk/lib/io/sync_socket.dart

Issue 2814773004: Various fixes for sync socket implementation. (Closed)
Patch Set: Various fixes for sync socket implementation. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sdk/lib/io/io_sources.gypi ('k') | tests/standalone/io/raw_synchronous_socket_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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.
9 *
10 * Warning: [RawSynchronousSocket] should probably only be used to connect to
11 * 'localhost'. The operations below will block the calling thread to wait for
12 * a response from the network. The thread can process no other events while
13 * waiting for these operations to complete. [RawSynchronousSocket] is not
14 * suitable for applications that require high performance or asynchronous I/O
15 * such as a server. Instead such applications should use the non-blocking
16 * sockets and asynchronous operations in the Socket or RawSocket classes.
17 */
18 abstract class RawSynchronousSocket {
19 /**
20 * Creates a new socket connection and returns a [RawSynchronousSocket].
21 *
22 * [host] can either be a [String] or an [InternetAddress]. If [host] is a
23 * [String], [connectSync] will perform a [InternetAddress.lookup] and try
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 * Reads up to [bytes] bytes from the socket.
59 *
60 * Blocks and waits for a response of up to a specified number of bytes
61 * sent by the socket. [bytes] specifies the maximum number of bytes to
62 * 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 * The port used by this socket.
91 */
92 int get port;
93
94 /**
95 * The remote port connected to by this socket.
96 */
97 int get remotePort;
98
99 /**
100 * The [InternetAddress] used to connect this socket.
101 */
102 InternetAddress get address;
103
104 /**
105 * The remote [InternetAddress] connected to by this socket.
106 */
107 InternetAddress get remoteAddress;
108 }
OLDNEW
« no previous file with comments | « sdk/lib/io/io_sources.gypi ('k') | tests/standalone/io/raw_synchronous_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698