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

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
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | 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 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 setOption(SocketOption option, bool enabled) {
396 if (option is! SocketOption) throw new ArgumentError(options);
397 if (enabled is! bool) throw new ArgumentError(enabled);
398 return nativeSetOption(option._value, enabled);
399 }
400
395 nativeAvailable() native "Socket_Available"; 401 nativeAvailable() native "Socket_Available";
396 nativeRead(int len) native "Socket_Read"; 402 nativeRead(int len) native "Socket_Read";
397 nativeWrite(List<int> buffer, int offset, int bytes) 403 nativeWrite(List<int> buffer, int offset, int bytes)
398 native "Socket_WriteList"; 404 native "Socket_WriteList";
399 nativeCreateConnect(String host, int port) native "Socket_CreateConnect"; 405 nativeCreateConnect(String host, int port) native "Socket_CreateConnect";
400 nativeCreateBindListen(String address, int port, int backlog) 406 nativeCreateBindListen(String address, int port, int backlog)
401 native "ServerSocket_CreateBindListen"; 407 native "ServerSocket_CreateBindListen";
402 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; 408 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept";
403 int nativeGetPort() native "Socket_GetPort"; 409 int nativeGetPort() native "Socket_GetPort";
404 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; 410 List nativeGetRemotePeer() native "Socket_GetRemotePeer";
405 OSError nativeGetError() native "Socket_GetError"; 411 OSError nativeGetError() native "Socket_GetError";
412 bool nativeSetOption(int option, bool enabled) native "Socket_SetOption";
406 413
407 static SendPort newServicePort() native "Socket_NewServicePort"; 414 static SendPort newServicePort() native "Socket_NewServicePort";
408 } 415 }
409 416
410 417
411 class _RawServerSocket extends Stream<RawSocket> 418 class _RawServerSocket extends Stream<RawSocket>
412 implements RawServerSocket { 419 implements RawServerSocket {
413 final _NativeSocket _socket; 420 final _NativeSocket _socket;
414 StreamController<RawSocket> _controller; 421 StreamController<RawSocket> _controller;
415 422
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 571 }
565 572
566 bool get writeEventsEnabled => _writeEventsEnabled; 573 bool get writeEventsEnabled => _writeEventsEnabled;
567 void set writeEventsEnabled(bool value) { 574 void set writeEventsEnabled(bool value) {
568 if (value != _writeEventsEnabled) { 575 if (value != _writeEventsEnabled) {
569 _writeEventsEnabled = value; 576 _writeEventsEnabled = value;
570 if (!_controller.isPaused) _resume(); 577 if (!_controller.isPaused) _resume();
571 } 578 }
572 } 579 }
573 580
581 bool setOption(SocketOption option, bool enabled) =>
582 _socket.setOption(option, enabled);
583
574 _pause() { 584 _pause() {
575 _socket.setListening(read: false, write: false); 585 _socket.setListening(read: false, write: false);
576 } 586 }
577 587
578 void _resume() { 588 void _resume() {
579 _socket.setListening(read: _readEventsEnabled, write: _writeEventsEnabled); 589 _socket.setListening(read: _readEventsEnabled, write: _writeEventsEnabled);
580 } 590 }
581 591
582 void _onPauseStateChange() { 592 void _onPauseStateChange() {
583 if (_controller.isPaused) { 593 if (_controller.isPaused) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 803
794 void destroy() { 804 void destroy() {
795 // Destroy can always be called to get rid of a socket. 805 // Destroy can always be called to get rid of a socket.
796 if (_raw == null) return; 806 if (_raw == null) return;
797 _consumer.stop(); 807 _consumer.stop();
798 _closeRawSocket(); 808 _closeRawSocket();
799 _controllerClosed = true; 809 _controllerClosed = true;
800 _controller.close(); 810 _controller.close();
801 } 811 }
802 812
813 bool setOption(SocketOption option, bool enabled) {
814 if (_raw == null) return false;
815 return _raw.setOption(option, enabled);
816 }
817
803 int get port => _raw.port; 818 int get port => _raw.port;
804 String get remoteHost => _raw.remoteHost; 819 String get remoteHost => _raw.remoteHost;
805 int get remotePort => _raw.remotePort; 820 int get remotePort => _raw.remotePort;
806 821
807 // Ensure a subscription on the raw socket. Both the stream and the 822 // Ensure a subscription on the raw socket. Both the stream and the
808 // consumer needs a subscription as they share the error and done 823 // consumer needs a subscription as they share the error and done
809 // events from the raw socket. 824 // events from the raw socket.
810 void _ensureRawSocketSubscription() { 825 void _ensureRawSocketSubscription() {
811 if (_subscription == null) { 826 if (_subscription == null) {
812 _subscription = _raw.listen(_onData, 827 _subscription = _raw.listen(_onData,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 _raw.onBadCertificate = callback; 945 _raw.onBadCertificate = callback;
931 } 946 }
932 947
933 X509Certificate get peerCertificate { 948 X509Certificate get peerCertificate {
934 if (_raw == null) { 949 if (_raw == null) {
935 throw new StateError("peerCertificate called on destroyed SecureSocket"); 950 throw new StateError("peerCertificate called on destroyed SecureSocket");
936 } 951 }
937 return _raw.peerCertificate; 952 return _raw.peerCertificate;
938 } 953 }
939 } 954 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698