Add ServerSocketBase to remove dynamic invocations of secure sockets in _HttpServer.

Change-Id: If8379fe73eeabd3aef99fcb85b4a5fd8414f8a18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260980
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
This commit is contained in:
Kallen Tu 2022-11-10 22:28:48 +00:00
parent 0381c38490
commit 5adeb03c2f
6 changed files with 15 additions and 13 deletions

View file

@ -69,6 +69,7 @@
- Deprecated `RangeError.checkValidIndex` in favor of `IndexError.check`.
- Deprecated `IndexError` constructor in favor of `IndexError.withLength`
constructor.
- `ServerSocket` and `SecureServerSocket` implement `ServerSocketBase`.
[#49529]: https://github.com/dart-lang/sdk/issues/49529
[#24644]: https://github.com/dart-lang/sdk/issues/24644

View file

@ -1,10 +1,4 @@
{
"org-dartlang-sdk:///lib/_http/http_impl.dart": {
"Dynamic access of 'address'.": 1,
"Dynamic access of 'port'.": 1,
"Dynamic invocation of 'listen'.": 1,
"Dynamic invocation of 'close'.": 1
},
"org-dartlang-sdk:///lib/_internal/js_runtime/lib/js_helper.dart": {
"Dynamic access of 'length'.": 1
},

View file

@ -3136,6 +3136,14 @@ class _HttpConnection extends LinkedListEntry<_HttpConnection>
String get _serviceTypeName => 'HttpServerConnection';
}
// Common interface of [ServerSocket] and [SecureServerSocket] used by
// [_HttpServer].
abstract class ServerSocketBase<T extends Socket> implements Stream<T> {
int get port;
InternetAddress get address;
Future<void> close();
}
// HTTP server waiting for socket connections.
class _HttpServer extends Stream<HttpRequest>
with _ServiceObject
@ -3249,7 +3257,7 @@ class _HttpServer extends Stream<HttpRequest>
Future close({bool force = false}) {
closed = true;
Future result;
if (_serverSocket != null && _closeServer) {
if (_closeServer) {
result = _serverSocket.close();
} else {
result = Future.value();
@ -3348,9 +3356,7 @@ class _HttpServer extends Stream<HttpRequest>
// Indicated if the http server has been closed.
bool closed = false;
// The server listen socket. Untyped as it can be both ServerSocket and
// SecureServerSocket.
final dynamic /*ServerSocket|SecureServerSocket*/ _serverSocket;
final ServerSocketBase _serverSocket;
final bool _closeServer;
// Set of currently connected clients.

View file

@ -196,7 +196,7 @@ import 'dart:collection'
show HashMap, HashSet, Queue, ListQueue, MapBase, UnmodifiableMapView;
import 'dart:convert';
import 'dart:developer' hide log;
import 'dart:_http' show HttpClient, HttpProfiler;
import 'dart:_http' show HttpClient, HttpProfiler, ServerSocketBase;
import 'dart:isolate';
import 'dart:math';
import 'dart:typed_data';

View file

@ -7,7 +7,8 @@ part of dart.io;
/// A server socket, providing a stream of high-level [Socket]s.
///
/// See [SecureSocket] for more info.
class SecureServerSocket extends Stream<SecureSocket> {
class SecureServerSocket extends Stream<SecureSocket>
implements ServerSocketBase<SecureSocket> {
final RawSecureServerSocket _socket;
SecureServerSocket._(this._socket);

View file

@ -263,7 +263,7 @@ abstract class RawServerSocket implements Stream<RawSocket> {
/// one for each connection made to the listening socket.
///
/// See [Socket] for more info.
abstract class ServerSocket implements Stream<Socket> {
abstract class ServerSocket implements ServerSocketBase<Socket> {
/// Listens on a given address and port.
///
/// When the returned future completes the server socket is bound