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(address, | 6 /* patch */ static Future<RawServerSocket> bind(address, |
7 int port, | 7 int port, |
8 {int backlog: 0, | 8 {int backlog: 0, |
9 bool v6Only: false}) { | 9 bool v6Only: false}) { |
10 return _RawServerSocket.bind(address, port, backlog, v6Only); | 10 return _RawServerSocket.bind(address, port, backlog, v6Only); |
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 Future<Socket> addStream(Stream<List<int>> stream) { | 1172 Future<Socket> addStream(Stream<List<int>> stream) { |
1173 socket._ensureRawSocketSubscription(); | 1173 socket._ensureRawSocketSubscription(); |
1174 streamCompleter = new Completer<Socket>(); | 1174 streamCompleter = new Completer<Socket>(); |
1175 if (socket._raw != null) { | 1175 if (socket._raw != null) { |
1176 subscription = stream.listen( | 1176 subscription = stream.listen( |
1177 (data) { | 1177 (data) { |
1178 assert(!paused); | 1178 assert(!paused); |
1179 assert(buffer == null); | 1179 assert(buffer == null); |
1180 buffer = data; | 1180 buffer = data; |
1181 offset = 0; | 1181 offset = 0; |
1182 write(); | 1182 try { |
| 1183 write(); |
| 1184 } catch (e) { |
| 1185 stop(); |
| 1186 socket._consumerDone(); |
| 1187 done(e); |
| 1188 } |
1183 }, | 1189 }, |
1184 onError: (error, [stackTrace]) { | 1190 onError: (error, [stackTrace]) { |
1185 socket._consumerDone(); | 1191 socket._consumerDone(); |
1186 done(error, stackTrace); | 1192 done(error, stackTrace); |
1187 }, | 1193 }, |
1188 onDone: () { | 1194 onDone: () { |
1189 done(); | 1195 done(); |
1190 }, | 1196 }, |
1191 cancelOnError: true); | 1197 cancelOnError: true); |
1192 } | 1198 } |
1193 return streamCompleter.future; | 1199 return streamCompleter.future; |
1194 } | 1200 } |
1195 | 1201 |
1196 Future<Socket> close() { | 1202 Future<Socket> close() { |
1197 socket._consumerDone(); | 1203 socket._consumerDone(); |
1198 return new Future.value(socket); | 1204 return new Future.value(socket); |
1199 } | 1205 } |
1200 | 1206 |
1201 void write() { | 1207 void write() { |
1202 try { | 1208 if (subscription == null) return; |
1203 if (subscription == null) return; | 1209 assert(buffer != null); |
1204 assert(buffer != null); | 1210 // Write as much as possible. |
1205 // Write as much as possible. | 1211 offset += socket._write(buffer, offset, buffer.length - offset); |
1206 offset += socket._write(buffer, offset, buffer.length - offset); | 1212 if (offset < buffer.length) { |
1207 if (offset < buffer.length) { | 1213 if (!paused) { |
1208 if (!paused) { | 1214 paused = true; |
1209 paused = true; | 1215 subscription.pause(); |
1210 subscription.pause(); | |
1211 } | |
1212 socket._enableWriteEvent(); | |
1213 } else { | |
1214 buffer = null; | |
1215 if (paused) { | |
1216 paused = false; | |
1217 subscription.resume(); | |
1218 } | |
1219 } | 1216 } |
1220 } catch (e) { | 1217 socket._enableWriteEvent(); |
1221 stop(); | 1218 } else { |
1222 socket._consumerDone(); | 1219 buffer = null; |
1223 done(e); | 1220 if (paused) { |
| 1221 paused = false; |
| 1222 subscription.resume(); |
| 1223 } |
1224 } | 1224 } |
1225 } | 1225 } |
1226 | 1226 |
1227 void done([error, stackTrace]) { | 1227 void done([error, stackTrace]) { |
1228 if (streamCompleter != null) { | 1228 if (streamCompleter != null) { |
1229 if (error != null) { | 1229 if (error != null) { |
1230 streamCompleter.completeError(error, stackTrace); | 1230 streamCompleter.completeError(error, stackTrace); |
1231 } else { | 1231 } else { |
1232 streamCompleter.complete(socket); | 1232 streamCompleter.complete(socket); |
1233 } | 1233 } |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 | 1589 |
1590 Datagram _makeDatagram(List<int> data, | 1590 Datagram _makeDatagram(List<int> data, |
1591 String address, | 1591 String address, |
1592 List<int> in_addr, | 1592 List<int> in_addr, |
1593 int port) { | 1593 int port) { |
1594 return new Datagram( | 1594 return new Datagram( |
1595 data, | 1595 data, |
1596 new _InternetAddress(address, null, in_addr), | 1596 new _InternetAddress(address, null, in_addr), |
1597 port); | 1597 port); |
1598 } | 1598 } |
OLD | NEW |