bad_socket 0.1.1

Add constrains to your Socket to simulate realworld network connections.

0
likes
70 / 110
pub points
0 %
popularity

We analyzed this package on Sep 23, 2020, and awarded it 70 pub points (of a possible 110):

Follow Dart file conventions
20 / 20

10/10 points: Provide a valid pubspec.yaml

5/5 points: Provide a valid README.md

5/5 points: Provide a valid CHANGELOG.md

Provide documentation
20 / 20

10/10 points: Package has an example

  • Found example at: example/bad_socket_example.dart

10/10 points: 20% or more of the public API has dartdoc comments

  • 7 out of 15 API elements (46.7 %) have documentation comments.
Support multiple platforms
10 / 20

10/20 points: Supports 1 of 2 possible platforms (native, js)

Consider supporting multiple platforms:

Package not compatible with runtime js

Because:

  • package:bad_socket/bad_socket.dart that imports:
  • package:bad_socket/src/bad_socket_base.dart that imports:
  • dart:io
Pass static analysis
0 / 30

0/30 points: code has no errors, warnings, lints, or formatting issues

Found 28 issues. Showing the first 2:

ERROR: The class 'BadSocket' cannot implement both 'Stream

lib/src/bad_socket_base.dart:13:1

    ╷
13  │ ┌ class BadSocket extends Stream<List<int>> with IOSink implements Socket {
14  │ │   final Socket _socket;
15  │ │   final Random _ramdom = Random.secure();
16  │ │ 
17  │ │   final int readLatency;
18  │ │   // final int readVolatility;
19  │ │   final int writeLatency;
20  │ │   // final int writeVolatility;
21  │ │   final double readLoss;
22  │ │   final double writeLoss;
23  │ │ 
24  │ │   /// Creates a BadSocket from another Socket
25  │ │   BadSocket.wrap(
26  │ │     this._socket, {
27  │ │     this.readLatency = 0,
28  │ │     this.writeLatency = 0,
29  │ │     this.readLoss = 0.0,
30  │ │     this.writeLoss = 0.0,
31  │ │     // this.readVolatility = 15,
32  │ │     // this.writeVolatility = 15,
33  │ │   });
34  │ │ 
35  │ │   listen(onData, {onError, onDone, cancelOnError}) {
36  │ │     return _socket
37  │ │         .asyncMap<List<int>>(_afterReadDelay)
38  │ │         .where(_willSurviveRead)
39  │ │         .listen(
40  │ │           onData,
41  │ │           onError: onError,
42  │ │           onDone: onDone,
43  │ │           cancelOnError: cancelOnError,
44  │ │         );
45  │ │   }
46  │ │ 
47  │ │   @override
48  │ │   void add(List<int> data) {
49  │ │     _withWriteCondition(
50  │ │       () => _socket.add(data),
51  │ │     );
52  │ │   }
53  │ │ 
54  │ │   @override
55  │ │   void addError(Object error, [StackTrace stackTrace]) {
56  │ │     _socket.addError(error, stackTrace);
57  │ │   }
58  │ │ 
59  │ │   @override
60  │ │   Future addStream(Stream<List<int>> stream) {
61  │ │     return _socket
62  │ │         .addStream(stream.asyncMap(_afterWriteDelay).where(_willSurviveWrite));
63  │ │   }
64  │ │ 
65  │ │   @override
66  │ │   Future close() {
67  │ │     return _socket.close();
68  │ │   }
69  │ │ 
70  │ │   @override
71  │ │   Future flush() {
72  │ │     return _socket.flush();
73  │ │   }
74  │ │ 
75  │ │   @override
76  │ │   void write(Object obj) {
77  │ │     _withWriteCondition(
78  │ │       () => _socket.write(obj),
79  │ │     );
80  │ │   }
81  │ │ 
82  │ │   @override
83  │ │   void writeAll(Iterable objects, [String separator = ""]) {
84  │ │     _withWriteCondition(
85  │ │       () => _socket.writeAll(objects, separator),
86  │ │     );
87  │ │   }
88  │ │ 
89  │ │   @override
90  │ │   void writeCharCode(int charCode) {
91  │ │     _withWriteCondition(
92  │ │       () => _socket.writeCharCode(charCode),
93  │ │     );
94  │ │   }
95  │ │ 
96  │ │   @override
97  │ │   void writeln([Object obj = ""]) {
98  │ │     _withWriteCondition(
99  │ │       () => _socket.writeln(obj),
100 │ │     );
101 │ │   }
102 │ │ 
103 │ │   @override
104 │ │   void destroy() {
105 │ │     _socket.destroy();
106 │ │   }
107 │ │ 
108 │ │   @override
109 │ │   Uint8List getRawOption(RawSocketOption option) {
110 │ │     return _socket.getRawOption(option);
111 │ │   }
112 │ │ 
113 │ │   @override
114 │ │   void setRawOption(RawSocketOption option) {
115 │ │     _socket.setRawOption(option);
116 │ │   }
117 │ │ 
118 │ │   @override
119 │ │   bool setOption(SocketOption option, bool enabled) {
120 │ │     return _socket.setOption(option, enabled);
121 │ │   }
122 │ │ 
123 │ │   @override
124 │ │   Future get done => _socket.done;
125 │ │ 
126 │ │   @override
127 │ │   InternetAddress get address => _socket.address;
128 │ │ 
129 │ │   @override
130 │ │   int get port => _socket.port;
131 │ │ 
132 │ │   @override
133 │ │   InternetAddress get remoteAddress => _socket.remoteAddress;
134 │ │ 
135 │ │   @override
136 │ │   int get remotePort => _socket.remotePort;
137 │ │ 
138 │ │   _withWriteCondition(Function fn) {
139 │ │     if(!_willSurviveWrite('')) return;
140 │ │     Future.delayed(Duration(milliseconds: writeLatency), fn);
141 │ │   }
142 │ │ 
143 │ │   Future<List<int>> _afterReadDelay(List<int> data) {
144 │ │     return Future.delayed(
145 │ │       Duration(milliseconds: readLatency),
146 │ │       () => data,
147 │ │     );
148 │ │   }
149 │ │ 
150 │ │   Future<List<int>> _afterWriteDelay(List<int> data) {
151 │ │     return Future.delayed(
152 │ │       Duration(milliseconds: writeLatency),
153 │ │       () => data,
154 │ │     );
155 │ │   }
156 │ │ 
157 │ │   bool _willSurviveRead(_) {
158 │ │     return _ramdom.nextDouble() > readLoss;
159 │ │   }
160 │ │ 
161 │ │   bool _willSurviveWrite(_) {
162 │ │     return _ramdom.nextDouble() > writeLoss;
163 │ │   }
164 │ └ }
    ╵

To reproduce make sure you are using pedantic and run dartanalyzer lib/src/bad_socket_base.dart

ERROR: Superinterfaces don't have a valid override for 'firstWhere': Stream.firstWhere (Future

lib/src/bad_socket_base.dart:13:7

   ╷
13 │ class BadSocket extends Stream<List<int>> with IOSink implements Socket {
   │       ^^^^^^^^^
   ╵

To reproduce make sure you are using pedantic and run dartanalyzer lib/src/bad_socket_base.dart

Support up-to-date dependencies
20 / 20

10/10 points: All of the package dependencies are supported in the latest version

No dependencies.

To reproduce run pub outdated --no-dev-dependencies --up-to-date --no-dependency-overrides.

10/10 points: Package supports latest stable Dart and Flutter SDKs

0
likes
70
pub points
0%
popularity

Add constrains to your Socket to simulate realworld network connections.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

xty50337@gmail.com

License

MIT (LICENSE)

More

Packages that depend on bad_socket