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

Side by Side Diff: runtime/bin/socket_patch.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
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 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1", 6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1",
7 int port = 0, 7 int port = 0,
8 int backlog = 0]) { 8 int backlog = 0]) {
9 return _RawServerSocket.bind(address, port, backlog); 9 return _RawServerSocket.bind(address, port, backlog);
10 } 10 }
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 void reportError(error, String message) { 385 void reportError(error, String message) {
386 var e = createError(error, message); 386 var e = createError(error, message);
387 // Invoke the error handler if any. 387 // Invoke the error handler if any.
388 if (eventHandlers[ERROR_EVENT] != null) { 388 if (eventHandlers[ERROR_EVENT] != null) {
389 eventHandlers[ERROR_EVENT](e); 389 eventHandlers[ERROR_EVENT](e);
390 } 390 }
391 // For all errors we close the socket 391 // For all errors we close the socket
392 close(); 392 close();
393 } 393 }
394 394
395 bool setNoDelay(bool enabled) => nativeSetNoDelay(enabled);
396
395 nativeAvailable() native "Socket_Available"; 397 nativeAvailable() native "Socket_Available";
396 nativeRead(int len) native "Socket_Read"; 398 nativeRead(int len) native "Socket_Read";
397 nativeWrite(List<int> buffer, int offset, int bytes) 399 nativeWrite(List<int> buffer, int offset, int bytes)
398 native "Socket_WriteList"; 400 native "Socket_WriteList";
399 nativeCreateConnect(String host, int port) native "Socket_CreateConnect"; 401 nativeCreateConnect(String host, int port) native "Socket_CreateConnect";
400 nativeCreateBindListen(String address, int port, int backlog) 402 nativeCreateBindListen(String address, int port, int backlog)
401 native "ServerSocket_CreateBindListen"; 403 native "ServerSocket_CreateBindListen";
402 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; 404 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept";
403 int nativeGetPort() native "Socket_GetPort"; 405 int nativeGetPort() native "Socket_GetPort";
404 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; 406 List nativeGetRemotePeer() native "Socket_GetRemotePeer";
405 OSError nativeGetError() native "Socket_GetError"; 407 OSError nativeGetError() native "Socket_GetError";
408 bool nativeSetNoDelay(bool enabled) native "Socket_SetNoDelay";
406 409
407 static SendPort newServicePort() native "Socket_NewServicePort"; 410 static SendPort newServicePort() native "Socket_NewServicePort";
408 } 411 }
409 412
410 413
411 class _RawServerSocket extends Stream<RawSocket> 414 class _RawServerSocket extends Stream<RawSocket>
412 implements RawServerSocket { 415 implements RawServerSocket {
413 final _NativeSocket _socket; 416 final _NativeSocket _socket;
414 StreamController<RawSocket> _controller; 417 StreamController<RawSocket> _controller;
415 418
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 567 }
565 568
566 bool get writeEventsEnabled => _writeEventsEnabled; 569 bool get writeEventsEnabled => _writeEventsEnabled;
567 void set writeEventsEnabled(bool value) { 570 void set writeEventsEnabled(bool value) {
568 if (value != _writeEventsEnabled) { 571 if (value != _writeEventsEnabled) {
569 _writeEventsEnabled = value; 572 _writeEventsEnabled = value;
570 if (!_controller.isPaused) _resume(); 573 if (!_controller.isPaused) _resume();
571 } 574 }
572 } 575 }
573 576
577 bool setNoDelay([bool enabled = true]) => _socket.setNoDelay(enabled);
578
574 _pause() { 579 _pause() {
575 _socket.setListening(read: false, write: false); 580 _socket.setListening(read: false, write: false);
576 } 581 }
577 582
578 void _resume() { 583 void _resume() {
579 _socket.setListening(read: _readEventsEnabled, write: _writeEventsEnabled); 584 _socket.setListening(read: _readEventsEnabled, write: _writeEventsEnabled);
580 } 585 }
581 586
582 void _onPauseStateChange() { 587 void _onPauseStateChange() {
583 if (_controller.isPaused) { 588 if (_controller.isPaused) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 798
794 void destroy() { 799 void destroy() {
795 // Destroy can always be called to get rid of a socket. 800 // Destroy can always be called to get rid of a socket.
796 if (_raw == null) return; 801 if (_raw == null) return;
797 _consumer.stop(); 802 _consumer.stop();
798 _closeRawSocket(); 803 _closeRawSocket();
799 _controllerClosed = true; 804 _controllerClosed = true;
800 _controller.close(); 805 _controller.close();
801 } 806 }
802 807
808 bool setNoDelay([bool enabled = true]) {
809 if (_raw == null) return false;
810 return _raw.setNoDelay(enabled);
811 }
812
803 int get port => _raw.port; 813 int get port => _raw.port;
804 String get remoteHost => _raw.remoteHost; 814 String get remoteHost => _raw.remoteHost;
805 int get remotePort => _raw.remotePort; 815 int get remotePort => _raw.remotePort;
806 816
807 // Ensure a subscription on the raw socket. Both the stream and the 817 // Ensure a subscription on the raw socket. Both the stream and the
808 // consumer needs a subscription as they share the error and done 818 // consumer needs a subscription as they share the error and done
809 // events from the raw socket. 819 // events from the raw socket.
810 void _ensureRawSocketSubscription() { 820 void _ensureRawSocketSubscription() {
811 if (_subscription == null) { 821 if (_subscription == null) {
812 _subscription = _raw.listen(_onData, 822 _subscription = _raw.listen(_onData,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 _raw.onBadCertificate = callback; 940 _raw.onBadCertificate = callback;
931 } 941 }
932 942
933 X509Certificate get peerCertificate { 943 X509Certificate get peerCertificate {
934 if (_raw == null) { 944 if (_raw == null) {
935 throw new StateError("peerCertificate called on destroyed SecureSocket"); 945 throw new StateError("peerCertificate called on destroyed SecureSocket");
936 } 946 }
937 return _raw.peerCertificate; 947 return _raw.peerCertificate;
938 } 948 }
939 } 949 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | sdk/lib/io/socket.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698