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

Side by Side Diff: runtime/bin/socket_impl.dart

Issue 8659032: Fix memory leak in MacOS process handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years 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.dart ('k') | runtime/bin/socket_linux.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 5
6 class _SocketBase { 6 class _SocketBase {
7 // Bit flags used when communicating between the eventhandler and 7 // Bit flags used when communicating between the eventhandler and
8 // dart code. The EVENT flags are used to indicate events of 8 // dart code. The EVENT flags are used to indicate events of
9 // interest when sending a message from dart code to the 9 // interest when sending a message from dart code to the
10 // eventhandler. When receiving a message from the eventhandler the 10 // eventhandler. When receiving a message from the eventhandler the
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 throw new IndexOutOfRangeException(offset); 291 throw new IndexOutOfRangeException(offset);
292 } 292 }
293 if (bytes < 0) { 293 if (bytes < 0) {
294 throw new IndexOutOfRangeException(bytes); 294 throw new IndexOutOfRangeException(bytes);
295 } 295 }
296 if ((offset + bytes) > buffer.length) { 296 if ((offset + bytes) > buffer.length) {
297 throw new IndexOutOfRangeException(offset + bytes); 297 throw new IndexOutOfRangeException(offset + bytes);
298 } 298 }
299 int result = _readList(buffer, offset, bytes); 299 int result = _readList(buffer, offset, bytes);
300 if (result < 0) { 300 if (result < 0) {
301 throw new SocketIOException("Error: readList failed"); 301 _reportError();
302 } 302 }
303 return result; 303 return result;
304 } 304 }
305 throw new 305 throw new
306 SocketIOException("Error: readList failed - invalid socket handle"); 306 SocketIOException("Error: readList failed - invalid socket handle");
307 } 307 }
308 308
309 int _readList(List<int> buffer, int offset, int bytes) 309 int _readList(List<int> buffer, int offset, int bytes)
310 native "Socket_ReadList"; 310 native "Socket_ReadList";
311 311
312 int writeList(List<int> buffer, int offset, int bytes) { 312 int writeList(List<int> buffer, int offset, int bytes) {
313 if (_id >= 0) { 313 if (_id >= 0) {
314 if (bytes == 0) { 314 if (bytes == 0) {
315 return 0; 315 return 0;
316 } 316 }
317 if (offset < 0) { 317 if (offset < 0) {
318 throw new IndexOutOfRangeException(offset); 318 throw new IndexOutOfRangeException(offset);
319 } 319 }
320 if (bytes < 0) { 320 if (bytes < 0) {
321 throw new IndexOutOfRangeException(bytes); 321 throw new IndexOutOfRangeException(bytes);
322 } 322 }
323 if ((offset + bytes) > buffer.length) { 323 if ((offset + bytes) > buffer.length) {
324 throw new IndexOutOfRangeException(offset + bytes); 324 throw new IndexOutOfRangeException(offset + bytes);
325 } 325 }
326 return _writeList(buffer, offset, bytes); 326 var bytes_written = _writeList(buffer, offset, bytes);
327 if (bytes_written < 0) {
328 // If writing fails we return 0 as the number of bytes and
329 // report the error on the error handler.
330 bytes_written = 0;
331 _reportError();
332 }
333 return bytes_written;
327 } 334 }
328 throw new 335 throw new
329 SocketIOException("Error: writeList failed - invalid socket handle"); 336 SocketIOException("Error: writeList failed - invalid socket handle");
330 } 337 }
331 338
332 int _writeList(List<int> buffer, int offset, int bytes) 339 int _writeList(List<int> buffer, int offset, int bytes)
333 native "Socket_WriteList"; 340 native "Socket_WriteList";
334 341
342 void _reportError() {
343 // For all errors we close the socket, call the error handler and
344 // disable further calls of the error handler.
345 close();
346 var errorHandler = _handlerMap[_ERROR_EVENT];
347 if (errorHandler != null) {
348 errorHandler();
349 _setHandler(_ERROR_EVENT, null);
350 }
351 }
352
335 bool _createConnect(String host, int port) native "Socket_CreateConnect"; 353 bool _createConnect(String host, int port) native "Socket_CreateConnect";
336 354
337 void set writeHandler(void callback()) { 355 void set writeHandler(void callback()) {
338 _setHandler(_OUT_EVENT, callback); 356 _setHandler(_OUT_EVENT, callback);
339 } 357 }
340 358
341 void set connectHandler(void callback()) { 359 void set connectHandler(void callback()) {
342 _setHandler(_OUT_EVENT, callback); 360 _setHandler(_OUT_EVENT, callback);
343 } 361 }
344 362
(...skipping 22 matching lines...) Expand all
367 return _outputStream; 385 return _outputStream;
368 } 386 }
369 387
370 bool _closedRead = false; 388 bool _closedRead = false;
371 bool _closedWrite = false; 389 bool _closedWrite = false;
372 bool _pipe = false; 390 bool _pipe = false;
373 SocketInputStream _inputStream; 391 SocketInputStream _inputStream;
374 SocketOutputStream _outputStream; 392 SocketOutputStream _outputStream;
375 } 393 }
376 394
OLDNEW
« no previous file with comments | « runtime/bin/socket.dart ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698