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

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

Issue 12614014: Add setNoDelay method on Socket/RawSocket. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/secure_socket.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * The RawServerSocket is a server socket, providing a stream of low-level 8 * The RawServerSocket is a server socket, providing a stream of low-level
9 * [RawSocket]s. 9 * [RawSocket]s.
10 * 10 *
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 */ 79 */
80 class SocketDirection { 80 class SocketDirection {
81 static const SocketDirection RECEIVE = const SocketDirection._(0); 81 static const SocketDirection RECEIVE = const SocketDirection._(0);
82 static const SocketDirection SEND = const SocketDirection._(1); 82 static const SocketDirection SEND = const SocketDirection._(1);
83 static const SocketDirection BOTH = const SocketDirection._(2); 83 static const SocketDirection BOTH = const SocketDirection._(2);
84 const SocketDirection._(this._value); 84 const SocketDirection._(this._value);
85 final _value; 85 final _value;
86 } 86 }
87 87
88 /** 88 /**
89 * The [SocketOption] is used as a parameter to [Socket.setOption] and
90 * [RawSocket.setOption] to set customize the behaviour of the underlying
91 * socket.
92 */
93 class SocketOption {
94 /**
95 * Enable or disable no-delay on the socket. If TCP_NODELAY is enabled, the
96 * socket will not buffer data internally, but instead write each data chunk
97 * as an invidual TCP packet.
98 *
99 * TCP_NODELAY is disabled by default.
100 */
101 static const SocketOption TCP_NODELAY = const SocketOption._(0);
102 const SocketOption._(this._value);
103 final _value;
104 }
105
106 /**
89 * Events for the [RawSocket]. 107 * Events for the [RawSocket].
90 */ 108 */
91 class RawSocketEvent { 109 class RawSocketEvent {
92 static const RawSocketEvent READ = const RawSocketEvent._(0); 110 static const RawSocketEvent READ = const RawSocketEvent._(0);
93 static const RawSocketEvent WRITE = const RawSocketEvent._(1); 111 static const RawSocketEvent WRITE = const RawSocketEvent._(1);
94 static const RawSocketEvent READ_CLOSED = const RawSocketEvent._(2); 112 static const RawSocketEvent READ_CLOSED = const RawSocketEvent._(2);
95 const RawSocketEvent._(this._value); 113 const RawSocketEvent._(this._value);
96 final int _value; 114 final int _value;
97 String toString() { 115 String toString() {
98 return ['RawSocketEvent:READ', 116 return ['RawSocketEvent:READ',
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 */ 190 */
173 bool readEventsEnabled; 191 bool readEventsEnabled;
174 192
175 /** 193 /**
176 * Set or get, if the [RawSocket] should listen for [RawSocketEvent.WRITE] 194 * Set or get, if the [RawSocket] should listen for [RawSocketEvent.WRITE]
177 * events. Default is [true]. 195 * events. Default is [true].
178 * This is a one-shot listener, and writeEventsEnabled must be set 196 * This is a one-shot listener, and writeEventsEnabled must be set
179 * to true again to receive another write event. 197 * to true again to receive another write event.
180 */ 198 */
181 bool writeEventsEnabled; 199 bool writeEventsEnabled;
200
201 /**
202 * Use [setOption] to customize the [RawSocket]. See [SocketOption] for
203 * available options.
204 *
205 * Returns [true] if the option was set successfully, false otherwise.
206 */
207 bool setOption(SocketOption option, bool enabled);
182 } 208 }
183 209
184 /** 210 /**
185 * A high-level class for communicating over a TCP socket. The [Socket] exposes 211 * A high-level class for communicating over a TCP socket. The [Socket] exposes
186 * both a [Stream] and a [IOSink] interface, making it ideal for 212 * both a [Stream] and a [IOSink] interface, making it ideal for
187 * using together with other [Stream]s. 213 * using together with other [Stream]s.
188 */ 214 */
189 abstract class Socket implements Stream<List<int>>, 215 abstract class Socket implements Stream<List<int>>,
190 IOSink<Socket> { 216 IOSink<Socket> {
191 /** 217 /**
192 * Creats a new socket connection to the host and port and returns a [Future] 218 * Creats a new socket connection to the host and port and returns a [Future]
193 * that will complete with either a [RawSocket] once connected or an error 219 * that will complete with either a [RawSocket] once connected or an error
194 * if the host-lookup or connection failed. 220 * if the host-lookup or connection failed.
195 */ 221 */
196 external static Future<Socket> connect(String host, int port); 222 external static Future<Socket> connect(String host, int port);
197 223
198 /** 224 /**
199 * Destroy the socket in both directions. Calling [destroy] will make the 225 * Destroy the socket in both directions. Calling [destroy] will make the
200 * send a close event on the stream and will no longer react on data being 226 * send a close event on the stream and will no longer react on data being
201 * piped to it. 227 * piped to it.
202 * 228 *
203 * Call [close](inherited from [IOSink]) to only close the [Socket] 229 * Call [close](inherited from [IOSink]) to only close the [Socket]
204 * for sending data. 230 * for sending data.
205 */ 231 */
206 void destroy(); 232 void destroy();
207 233
234 /**
235 * Enable or disable no-delay on the socket. If no-delay is enabled, the
236 * socket will not buffer data internally, but instead write each data chunk
237 * as an invidual TCP packet.
238 *
239 * No-delay is disabled by default.
240 */
241 bool setNoDelay([bool enabled = true]);
242
208 int get port; 243 int get port;
209 String get remoteHost; 244 String get remoteHost;
210 int get remotePort; 245 int get remotePort;
211 } 246 }
212 247
213 248
214 class SocketIOException implements Exception { 249 class SocketIOException implements Exception {
215 const SocketIOException([String this.message = "", 250 const SocketIOException([String this.message = "",
216 OSError this.osError = null]); 251 OSError this.osError = null]);
217 String toString() { 252 String toString() {
218 StringBuffer sb = new StringBuffer(); 253 StringBuffer sb = new StringBuffer();
219 sb.write("SocketIOException"); 254 sb.write("SocketIOException");
220 if (!message.isEmpty) { 255 if (!message.isEmpty) {
221 sb.write(": $message"); 256 sb.write(": $message");
222 if (osError != null) { 257 if (osError != null) {
223 sb.write(" ($osError)"); 258 sb.write(" ($osError)");
224 } 259 }
225 } else if (osError != null) { 260 } else if (osError != null) {
226 sb.write(": $osError"); 261 sb.write(": $osError");
227 } 262 }
228 return sb.toString(); 263 return sb.toString();
229 } 264 }
230 final String message; 265 final String message;
231 final OSError osError; 266 final OSError osError;
232 } 267 }
OLDNEW
« no previous file with comments | « sdk/lib/io/secure_socket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698