| OLD | NEW |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 // Indicates if native interrupts can be activated. | 68 // Indicates if native interrupts can be activated. |
| 69 bool canActivateEvents = true; | 69 bool canActivateEvents = true; |
| 70 | 70 |
| 71 // The type flags for this socket. | 71 // The type flags for this socket. |
| 72 final int typeFlags; | 72 final int typeFlags; |
| 73 | 73 |
| 74 // Holds the port of the socket, null if not known. | 74 // Holds the port of the socket, null if not known. |
| 75 int localPort; | 75 int localPort; |
| 76 | 76 |
| 77 // Holds the host or address used to connect or bind the socket. |
| 78 String localHost; |
| 79 |
| 77 // Native port for socket services. | 80 // Native port for socket services. |
| 78 static SendPort socketService; | 81 static SendPort socketService; |
| 79 | 82 |
| 80 static Future<_NativeSocket> connect(String host, int port) { | 83 static Future<_NativeSocket> connect(String host, int port) { |
| 81 var completer = new Completer(); | 84 var completer = new Completer(); |
| 82 ensureSocketService(); | 85 ensureSocketService(); |
| 83 socketService.call([HOST_NAME_LOOKUP, host]).then((response) { | 86 socketService.call([HOST_NAME_LOOKUP, host]).then((response) { |
| 84 if (isErrorResponse(response)) { | 87 if (isErrorResponse(response)) { |
| 85 completer.completeError( | 88 completer.completeError( |
| 86 createError(response, "Failed host name lookup")); | 89 createError(response, "Failed host name lookup")); |
| 87 } else { | 90 } else { |
| 88 var socket = new _NativeSocket.normal(); | 91 var socket = new _NativeSocket.normal(); |
| 92 socket.localHost = host; |
| 89 var result = socket.nativeCreateConnect(response, port); | 93 var result = socket.nativeCreateConnect(response, port); |
| 90 if (result is OSError) { | 94 if (result is OSError) { |
| 91 completer.completeError(createError(result, "Connection failed")); | 95 completer.completeError(createError(result, "Connection failed")); |
| 92 } else { | 96 } else { |
| 93 // Setup handlers for receiving the first write event which | 97 // Setup handlers for receiving the first write event which |
| 94 // indicate that the socket is fully connected. | 98 // indicate that the socket is fully connected. |
| 95 socket.setHandlers( | 99 socket.setHandlers( |
| 96 write: () { | 100 write: () { |
| 97 socket.setListening(read: false, write: false); | 101 socket.setListening(read: false, write: false); |
| 98 completer.complete(socket); | 102 completer.complete(socket); |
| 99 }, | 103 }, |
| 100 error: (e) { | 104 error: (e) { |
| 101 socket.close(); | 105 socket.close(); |
| 102 completer.completeError(createError(e, "Connection failed")); | 106 completer.completeError(createError(e, "Connection failed")); |
| 103 } | 107 } |
| 104 ); | 108 ); |
| 105 socket.setListening(read: false, write: true); | 109 socket.setListening(read: false, write: true); |
| 106 } | 110 } |
| 107 } | 111 } |
| 108 }); | 112 }); |
| 109 return completer.future; | 113 return completer.future; |
| 110 } | 114 } |
| 111 | 115 |
| 112 static Future<_NativeSocket> bind(String address, | 116 static Future<_NativeSocket> bind(String address, |
| 113 int port, | 117 int port, |
| 114 int backlog) { | 118 int backlog) { |
| 115 var socket = new _NativeSocket.listen(); | 119 var socket = new _NativeSocket.listen(); |
| 120 socket.localHost = address; |
| 116 var result = socket.nativeCreateBindListen(address, port, backlog); | 121 var result = socket.nativeCreateBindListen(address, port, backlog); |
| 117 if (result is OSError) { | 122 if (result is OSError) { |
| 118 return new Future.immediateError( | 123 return new Future.immediateError( |
| 119 new SocketIOException("Failed to create server socket", result)); | 124 new SocketIOException("Failed to create server socket", result)); |
| 120 } | 125 } |
| 121 if (port != 0) socket.localPort = port; | 126 if (port != 0) socket.localPort = port; |
| 122 return new Future.immediate(socket); | 127 return new Future.immediate(socket); |
| 123 } | 128 } |
| 124 | 129 |
| 125 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET { | 130 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 199 |
| 195 int get port { | 200 int get port { |
| 196 if (localPort != null) return localPort; | 201 if (localPort != null) return localPort; |
| 197 return localPort = nativeGetPort(); | 202 return localPort = nativeGetPort(); |
| 198 } | 203 } |
| 199 | 204 |
| 200 int get remotePort { | 205 int get remotePort { |
| 201 return nativeGetRemotePeer()[1]; | 206 return nativeGetRemotePeer()[1]; |
| 202 } | 207 } |
| 203 | 208 |
| 209 String get host => localHost; |
| 210 |
| 204 String get remoteHost { | 211 String get remoteHost { |
| 205 return nativeGetRemotePeer()[0]; | 212 return nativeGetRemotePeer()[0]; |
| 206 } | 213 } |
| 207 | 214 |
| 208 // Multiplexes socket events to the socket handlers. | 215 // Multiplexes socket events to the socket handlers. |
| 209 void multiplex(int events) { | 216 void multiplex(int events) { |
| 210 canActivateEvents = false; | 217 canActivateEvents = false; |
| 211 for (int i = FIRST_EVENT; i <= LAST_EVENT; i++) { | 218 for (int i = FIRST_EVENT; i <= LAST_EVENT; i++) { |
| 212 if (((events & (1 << i)) != 0)) { | 219 if (((events & (1 << i)) != 0)) { |
| 213 if (i == CLOSED_EVENT && | 220 if (i == CLOSED_EVENT && |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 _socket.write(buffer, offset, count); | 560 _socket.write(buffer, offset, count); |
| 554 | 561 |
| 555 void close() => _socket.close(); | 562 void close() => _socket.close(); |
| 556 | 563 |
| 557 void shutdown(SocketDirection direction) => _socket.shutdown(direction); | 564 void shutdown(SocketDirection direction) => _socket.shutdown(direction); |
| 558 | 565 |
| 559 int get port => _socket.port; | 566 int get port => _socket.port; |
| 560 | 567 |
| 561 int get remotePort => _socket.remotePort; | 568 int get remotePort => _socket.remotePort; |
| 562 | 569 |
| 570 String get host => _socket.host; |
| 571 |
| 563 String get remoteHost => _socket.remoteHost; | 572 String get remoteHost => _socket.remoteHost; |
| 564 | 573 |
| 565 bool get readEventsEnabled => _readEventsEnabled; | 574 bool get readEventsEnabled => _readEventsEnabled; |
| 566 void set readEventsEnabled(bool value) { | 575 void set readEventsEnabled(bool value) { |
| 567 if (value != _readEventsEnabled) { | 576 if (value != _readEventsEnabled) { |
| 568 _readEventsEnabled = value; | 577 _readEventsEnabled = value; |
| 569 if (!_controller.isPaused) _resume(); | 578 if (!_controller.isPaused) _resume(); |
| 570 } | 579 } |
| 571 } | 580 } |
| 572 | 581 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 _raw.onBadCertificate = callback; | 954 _raw.onBadCertificate = callback; |
| 946 } | 955 } |
| 947 | 956 |
| 948 X509Certificate get peerCertificate { | 957 X509Certificate get peerCertificate { |
| 949 if (_raw == null) { | 958 if (_raw == null) { |
| 950 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 959 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 951 } | 960 } |
| 952 return _raw.peerCertificate; | 961 return _raw.peerCertificate; |
| 953 } | 962 } |
| 954 } | 963 } |
| OLD | NEW |