| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 bool setOption(SocketOption option, bool enabled) { | 239 bool setOption(SocketOption option, bool enabled) { |
| 240 // TODO(johnmccutchan): Implement. | 240 // TODO(johnmccutchan): Implement. |
| 241 return false; | 241 return false; |
| 242 } | 242 } |
| 243 | 243 |
| 244 _onInputData(List<int> event) { | 244 _onInputData(List<int> event) { |
| 245 if (_inClosed) { | 245 if (_inClosed) { |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 var signalsWatched = new MojoHandleSignals(event[0]); | 248 int signalsWatched = event[0]; |
| 249 var signalsReceived = new MojoHandleSignals(event[1]); | 249 int signalsReceived = event[1]; |
| 250 if (_trace) { | 250 if (_trace) { |
| 251 _tracePrint('<- IN: ${signalsReceived}'); | 251 _tracePrint('<- IN: ${signalsReceived}'); |
| 252 } | 252 } |
| 253 if (signalsReceived.isReadable) { | 253 if (MojoHandleSignals.isReadable(signalsReceived)) { |
| 254 if (_trace) { | 254 if (_trace) { |
| 255 _tracePrint('<- READ'); | 255 _tracePrint('<- READ'); |
| 256 } | 256 } |
| 257 _controller.add(RawSocketEvent.READ); | 257 _controller.add(RawSocketEvent.READ); |
| 258 } | 258 } |
| 259 if (signalsReceived.isPeerClosed) { | 259 if (MojoHandleSignals.isPeerClosed(signalsReceived)) { |
| 260 if (_trace) { | 260 if (_trace) { |
| 261 _tracePrint('<- READ_CLOSED'); | 261 _tracePrint('<- READ_CLOSED'); |
| 262 } | 262 } |
| 263 _controller.add(RawSocketEvent.READ_CLOSED); | 263 _controller.add(RawSocketEvent.READ_CLOSED); |
| 264 // Once we are closed, stop reporting events. | 264 // Once we are closed, stop reporting events. |
| 265 _inClosed = true; | 265 _inClosed = true; |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 _onOutputData(List<int> event) { | 270 _onOutputData(List<int> event) { |
| 271 if (_outClosed) { | 271 if (_outClosed) { |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 var signalsWatched = new MojoHandleSignals(event[0]); | 274 int signalsWatched = event[0]; |
| 275 var signalsReceived = new MojoHandleSignals(event[1]); | 275 int signalsReceived = event[1]; |
| 276 if (_trace) { | 276 if (_trace) { |
| 277 _tracePrint('<- OUT: ${signalsReceived}'); | 277 _tracePrint('<- OUT: ${signalsReceived}'); |
| 278 } | 278 } |
| 279 if (signalsReceived.isPeerClosed) { | 279 if (MojoHandleSignals.isPeerClosed(signalsReceived)) { |
| 280 if (_trace) { | 280 if (_trace) { |
| 281 _tracePrint('<- CLOSED'); | 281 _tracePrint('<- CLOSED'); |
| 282 } | 282 } |
| 283 _controller.add(RawSocketEvent.CLOSED); | 283 _controller.add(RawSocketEvent.CLOSED); |
| 284 // Once we are closed, stop reporting events. | 284 // Once we are closed, stop reporting events. |
| 285 _outClosed = true; | 285 _outClosed = true; |
| 286 return; | 286 return; |
| 287 } | 287 } |
| 288 if (signalsReceived.isWritable) { | 288 if (MojoHandleSignals.isWritable(signalsReceived)) { |
| 289 if (_trace) { | 289 if (_trace) { |
| 290 _tracePrint('<- WRITE'); | 290 _tracePrint('<- WRITE'); |
| 291 } | 291 } |
| 292 _controller.add(RawSocketEvent.WRITE); | 292 _controller.add(RawSocketEvent.WRITE); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 _setupIn() { | 296 _setupIn() { |
| 297 assert(_pipeInEvents == null); | 297 assert(_pipeInEvents == null); |
| 298 _pipeInEvents = new MojoEventSubscription(_pipeIn.consumer.handle, | 298 _pipeInEvents = new MojoEventSubscription( |
| 299 MojoHandleSignals.READABLE + | 299 _pipeIn.consumer.handle, MojoHandleSignals.kPeerClosedReadable); |
| 300 MojoHandleSignals.PEER_CLOSED); | |
| 301 _pipeInEvents.subscribe(_onInputData); | 300 _pipeInEvents.subscribe(_onInputData); |
| 302 } | 301 } |
| 303 | 302 |
| 304 _setupOut() { | 303 _setupOut() { |
| 305 assert(_pipeOutEvents == null); | 304 assert(_pipeOutEvents == null); |
| 306 _pipeOutEvents = new MojoEventSubscription(_pipeOut.producer.handle, | 305 _pipeOutEvents = new MojoEventSubscription( |
| 307 MojoHandleSignals.WRITABLE + | 306 _pipeOut.producer.handle, MojoHandleSignals.kPeerClosedWritable); |
| 308 MojoHandleSignals.PEER_CLOSED); | |
| 309 _pipeOutEvents.subscribe(_onOutputData); | 307 _pipeOutEvents.subscribe(_onOutputData); |
| 310 } | 308 } |
| 311 | 309 |
| 312 _shutdownIn([bool force = false]) { | 310 _shutdownIn([bool force = false]) { |
| 313 _inClosed = true; | 311 _inClosed = true; |
| 314 if (_trace) { | 312 if (_trace) { |
| 315 _tracePrint('shutdown IN'); | 313 _tracePrint('shutdown IN'); |
| 316 _tracePipeIn(); | 314 _tracePipeIn(); |
| 317 } | 315 } |
| 318 if (_pipeInEvents != null) { | 316 if (_pipeInEvents != null) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 bool cancelOnError}) { | 457 bool cancelOnError}) { |
| 460 return _controller.stream.listen(onData, onError: onError, onDone: onDone, | 458 return _controller.stream.listen(onData, onError: onError, onDone: onDone, |
| 461 cancelOnError: cancelOnError); | 459 cancelOnError: cancelOnError); |
| 462 } | 460 } |
| 463 | 461 |
| 464 | 462 |
| 465 static _enableReadEvents(MojoEventSubscription subscription) { | 463 static _enableReadEvents(MojoEventSubscription subscription) { |
| 466 if (subscription == null) { | 464 if (subscription == null) { |
| 467 return; | 465 return; |
| 468 } | 466 } |
| 469 subscription.enableSignals(MojoHandleSignals.PEER_CLOSED + | 467 subscription.enableSignals(MojoHandleSignals.kPeerClosedReadable); |
| 470 MojoHandleSignals.READABLE); | |
| 471 } | 468 } |
| 472 | 469 |
| 473 static _enableWriteEvents(MojoEventSubscription subscription) { | 470 static _enableWriteEvents(MojoEventSubscription subscription) { |
| 474 if (subscription == null) { | 471 if (subscription == null) { |
| 475 return; | 472 return; |
| 476 } | 473 } |
| 477 subscription.enableSignals(MojoHandleSignals.PEER_CLOSED + | 474 subscription.enableSignals(MojoHandleSignals.kPeerClosedWritable); |
| 478 MojoHandleSignals.WRITABLE); | |
| 479 } | 475 } |
| 480 | 476 |
| 481 static _disableEvents(MojoEventSubscription subscription) { | 477 static _disableEvents(MojoEventSubscription subscription) { |
| 482 if (subscription == null) { | 478 if (subscription == null) { |
| 483 return; | 479 return; |
| 484 } | 480 } |
| 485 subscription.enableSignals(MojoHandleSignals.PEER_CLOSED); | 481 subscription.enableSignals(MojoHandleSignals.kPeerClosed); |
| 486 } | 482 } |
| 487 | 483 |
| 488 _pause() { | 484 _pause() { |
| 489 _disableEvents(_pipeInEvents); | 485 _disableEvents(_pipeInEvents); |
| 490 _disableEvents(_pipeOutEvents); | 486 _disableEvents(_pipeOutEvents); |
| 491 } | 487 } |
| 492 | 488 |
| 493 void _resume() { | 489 void _resume() { |
| 494 if (_pipeInEvents != null) { | 490 if (_pipeInEvents != null) { |
| 495 if (_readEventsEnabled) { | 491 if (_readEventsEnabled) { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 if (_raw != null) { | 812 if (_raw != null) { |
| 817 _raw.shutdown(SocketDirection.SEND); | 813 _raw.shutdown(SocketDirection.SEND); |
| 818 _disableWriteEvent(); | 814 _disableWriteEvent(); |
| 819 } | 815 } |
| 820 } | 816 } |
| 821 } | 817 } |
| 822 | 818 |
| 823 Map _toJSON(bool ref) => _raw._toJSON(ref); | 819 Map _toJSON(bool ref) => _raw._toJSON(ref); |
| 824 void set _owner(owner) { _raw._owner = owner; } | 820 void set _owner(owner) { _raw._owner = owner; } |
| 825 } | 821 } |
| OLD | NEW |