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

Side by Side Diff: examples/dart/netcat/lib/main.dart

Issue 1439993003: Dart: Avoid MojoResult and MojoHandleSignals constructors. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | mojo/dart/embedder/io/socket_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!mojo mojo:dart_content_handler 1 #!mojo mojo:dart_content_handler
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:core'; 7 import 'dart:core';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'package:mojo/application.dart'; 10 import 'package:mojo/application.dart';
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 118
119 // TODO(vtl): Handle the send data pipe being full (or closed). 119 // TODO(vtl): Handle the send data pipe being full (or closed).
120 _socketSender 120 _socketSender
121 .write(new ByteData.view(_writeBuffer.buffer, 0, p.bytesRead.length)); 121 .write(new ByteData.view(_writeBuffer.buffer, 0, p.bytesRead.length));
122 122
123 _startReadingFromTerminal(); 123 _startReadingFromTerminal();
124 } 124 }
125 125
126 void _onSocketReceiverEvent(List<int> event) { 126 void _onSocketReceiverEvent(List<int> event) {
127 var mojoSignals = new MojoHandleSignals(event[1]); 127 int mojoSignals = event[1];
128 var shouldShutDown = false; 128 var shouldShutDown = false;
129 if (mojoSignals.isReadable) { 129 if (MojoHandleSignals.isReadable(mojoSignals)) {
130 var numBytesRead = _socketReceiver.read(_readBuffer); 130 var numBytesRead = _socketReceiver.read(_readBuffer);
131 if (_socketReceiver.status.isOk) { 131 if (_socketReceiver.status == MojoResult.kOk) {
132 assert(numBytesRead > 0); 132 assert(numBytesRead > 0);
133 _terminal.ptr 133 _terminal.ptr
134 .write(_readBuffer.buffer.asUint8List(0, numBytesRead), 0, 134 .write(_readBuffer.buffer.asUint8List(0, numBytesRead), 0,
135 files.Whence.FROM_CURRENT) 135 files.Whence.FROM_CURRENT)
136 .catchError((e) { 136 .catchError((e) {
137 _shutDown(); 137 _shutDown();
138 }); 138 });
139 _socketReceiverEventSubscription.enableReadEvents(); 139 _socketReceiverEventSubscription.enableReadEvents();
140 } else { 140 } else {
141 shouldShutDown = true; 141 shouldShutDown = true;
142 } 142 }
143 } else if (mojoSignals.isPeerClosed) { 143 } else if (MojoHandleSignals.isPeerClosed(mojoSignals)) {
144 shouldShutDown = true; 144 shouldShutDown = true;
145 } else { 145 } else {
146 throw 'Unexpected handle event: $mojoSignals'; 146 String signals = MojoHandleSignals.string(mojoSignals);
147 throw 'Unexpected handle event: $signals';
147 } 148 }
148 if (shouldShutDown) { 149 if (shouldShutDown) {
149 _shutDown(); 150 _shutDown();
150 } 151 }
151 } 152 }
152 153
153 void _shutDown() { 154 void _shutDown() {
154 if (_socketReceiverEventSubscription != null) { 155 if (_socketReceiverEventSubscription != null) {
155 ignoreFuture(_socketReceiverEventSubscription.close()); 156 ignoreFuture(_socketReceiverEventSubscription.close());
156 _socketReceiverEventSubscription = null; 157 _socketReceiverEventSubscription = null;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 234 }
234 235
235 main(List args) { 236 main(List args) {
236 MojoHandle appHandle = new MojoHandle(args[0]); 237 MojoHandle appHandle = new MojoHandle(args[0]);
237 String url = args[1]; 238 String url = args[1];
238 new NetcatApplication.fromHandle(appHandle) 239 new NetcatApplication.fromHandle(appHandle)
239 ..onError = ((Object e) { 240 ..onError = ((Object e) {
240 MojoHandle.reportLeakedHandles(); 241 MojoHandle.reportLeakedHandles();
241 }); 242 });
242 } 243 }
OLDNEW
« no previous file with comments | « no previous file | mojo/dart/embedder/io/socket_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698