OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // | 5 // |
6 // Implementation of Socket and RawSocket for Mojo. | 6 // Implementation of Socket and RawSocket for Mojo. |
7 // | 7 // |
8 | 8 |
9 patch class Socket { | 9 patch class Socket { |
10 /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) { | 10 /* patch */ static Future<Socket> connect(host, int port, {sourceAddress}) { |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // Constructing a new MojoDataPipe allocates two handles. All failure paths | 27 // Constructing a new MojoDataPipe allocates two handles. All failure paths |
28 // must be sure that these handles are closed so we do not leak any handles. | 28 // must be sure that these handles are closed so we do not leak any handles. |
29 final _pipeOut = new MojoDataPipe(); | 29 final _pipeOut = new MojoDataPipe(); |
30 bool _outClosed = false; | 30 bool _outClosed = false; |
31 // Constructing a new MojoDataPipe allocates two handles. All failure paths | 31 // Constructing a new MojoDataPipe allocates two handles. All failure paths |
32 // must be sure that these handles are closed so we do not leak any handles. | 32 // must be sure that these handles are closed so we do not leak any handles. |
33 final _pipeIn = new MojoDataPipe(); | 33 final _pipeIn = new MojoDataPipe(); |
34 bool _inClosed = false; | 34 bool _inClosed = false; |
35 bool _readEventsEnabled = true; | 35 bool _readEventsEnabled = true; |
36 bool _writeEventsEnabled = true; | 36 bool _writeEventsEnabled = true; |
37 MojoEventStream _pipeOutEvents; | 37 MojoEventHandler _pipeOutEvents; |
38 MojoEventStream _pipeInEvents; | 38 MojoEventHandler _pipeInEvents; |
39 InternetAddress _localAddress; | 39 InternetAddress _localAddress; |
40 int _localPort; | 40 int _localPort; |
41 InternetAddress _remoteAddress; | 41 InternetAddress _remoteAddress; |
42 int _remotePort; | 42 int _remotePort; |
43 var _owner; | 43 var _owner; |
44 | 44 |
45 bool _trace = false; | 45 bool _trace = false; |
46 int _traceId; | 46 int _traceId; |
47 | 47 |
48 _tracePrint(String message) { | 48 _tracePrint(String message) { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 } | 320 } |
321 if (_trace) { | 321 if (_trace) { |
322 _tracePrint('<- CLOSED (done)'); | 322 _tracePrint('<- CLOSED (done)'); |
323 } | 323 } |
324 _controller.add(RawSocketEvent.CLOSED); | 324 _controller.add(RawSocketEvent.CLOSED); |
325 _outClosed = true; | 325 _outClosed = true; |
326 } | 326 } |
327 | 327 |
328 _setupIn() { | 328 _setupIn() { |
329 assert(_pipeInEvents == null); | 329 assert(_pipeInEvents == null); |
330 _pipeInEvents = new MojoEventStream(_pipeIn.consumer.handle, | 330 _pipeInEvents = new MojoEventHandler(_pipeIn.consumer.handle, |
331 MojoHandleSignals.READABLE + | 331 MojoHandleSignals.READABLE + |
332 MojoHandleSignals.PEER_CLOSED); | 332 MojoHandleSignals.PEER_CLOSED); |
333 _pipeInEvents.listen(_onInputData, | 333 _pipeInEvents.handleEvents(_onInputData); |
334 onError: _onInputError, | |
335 onDone: _onInputDone); | |
336 } | 334 } |
337 | 335 |
338 _setupOut() { | 336 _setupOut() { |
339 assert(_pipeOutEvents == null); | 337 assert(_pipeOutEvents == null); |
340 _pipeOutEvents = new MojoEventStream(_pipeOut.producer.handle, | 338 _pipeOutEvents = new MojoEventHandler(_pipeOut.producer.handle, |
341 MojoHandleSignals.WRITABLE + | 339 MojoHandleSignals.WRITABLE + |
342 MojoHandleSignals.PEER_CLOSED); | 340 MojoHandleSignals.PEER_CLOSED); |
343 _pipeOutEvents.listen(_onOutputData, | 341 _pipeOutEvents.handleEvents(_onOutputData); |
344 onError: _onOutputError, | |
345 onDone: _onOutputDone); | |
Cutch
2015/11/11 17:47:17
Who calls _onOutputError and _onOutputDone now?
zra
2015/11/11 18:44:33
These and _onInput{Error,Done} aren't needed anymo
| |
346 } | 342 } |
347 | 343 |
348 _shutdownIn([bool force = false]) { | 344 _shutdownIn([bool force = false]) { |
349 _inClosed = true; | 345 _inClosed = true; |
350 if (_trace) { | 346 if (_trace) { |
351 _tracePrint('shutdown IN'); | 347 _tracePrint('shutdown IN'); |
352 _tracePipeIn(); | 348 _tracePipeIn(); |
353 } | 349 } |
354 if (_pipeInEvents != null) { | 350 if (_pipeInEvents != null) { |
355 if (force) { | 351 if (force) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 | 487 |
492 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), | 488 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), |
493 {Function onError, | 489 {Function onError, |
494 void onDone(), | 490 void onDone(), |
495 bool cancelOnError}) { | 491 bool cancelOnError}) { |
496 return _controller.stream.listen(onData, onError: onError, onDone: onDone, | 492 return _controller.stream.listen(onData, onError: onError, onDone: onDone, |
497 cancelOnError: cancelOnError); | 493 cancelOnError: cancelOnError); |
498 } | 494 } |
499 | 495 |
500 | 496 |
501 static _enableReadEvents(MojoEventStream stream) { | 497 static _enableReadEvents(MojoEventHandler stream) { |
502 if (stream == null) { | 498 if (stream == null) { |
503 return; | 499 return; |
504 } | 500 } |
505 stream.enableSignals(MojoHandleSignals.PEER_CLOSED + | 501 stream.enableSignals(MojoHandleSignals.PEER_CLOSED + |
506 MojoHandleSignals.READABLE); | 502 MojoHandleSignals.READABLE); |
507 } | 503 } |
508 | 504 |
509 static _enableWriteEvents(MojoEventStream stream) { | 505 static _enableWriteEvents(MojoEventHandler stream) { |
510 if (stream == null) { | 506 if (stream == null) { |
511 return; | 507 return; |
512 } | 508 } |
513 stream.enableSignals(MojoHandleSignals.PEER_CLOSED + | 509 stream.enableSignals(MojoHandleSignals.PEER_CLOSED + |
514 MojoHandleSignals.WRITABLE); | 510 MojoHandleSignals.WRITABLE); |
515 } | 511 } |
516 | 512 |
517 static _disableEvents(MojoEventStream stream) { | 513 static _disableEvents(MojoEventHandler stream) { |
518 if (stream == null) { | 514 if (stream == null) { |
519 return; | 515 return; |
520 } | 516 } |
521 stream.enableSignals(MojoHandleSignals.PEER_CLOSED); | 517 stream.enableSignals(MojoHandleSignals.PEER_CLOSED); |
522 } | 518 } |
523 | 519 |
524 _pause() { | 520 _pause() { |
525 _disableEvents(_pipeInEvents); | 521 _disableEvents(_pipeInEvents); |
526 _disableEvents(_pipeOutEvents); | 522 _disableEvents(_pipeOutEvents); |
527 } | 523 } |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 if (_raw != null) { | 848 if (_raw != null) { |
853 _raw.shutdown(SocketDirection.SEND); | 849 _raw.shutdown(SocketDirection.SEND); |
854 _disableWriteEvent(); | 850 _disableWriteEvent(); |
855 } | 851 } |
856 } | 852 } |
857 } | 853 } |
858 | 854 |
859 Map _toJSON(bool ref) => _raw._toJSON(ref); | 855 Map _toJSON(bool ref) => _raw._toJSON(ref); |
860 void set _owner(owner) { _raw._owner = owner; } | 856 void set _owner(owner) { _raw._owner = owner; } |
861 } | 857 } |
OLD | NEW |