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 10443008: Implement File.lastModified. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Return ms from C Created 8 years, 7 months 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/file_win.cc ('k') | tests/standalone/io/file_fuzz_test.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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 // For all errors we close the socket, call the error handler and 202 // For all errors we close the socket, call the error handler and
203 // disable further calls of the error handler. 203 // disable further calls of the error handler.
204 close(); 204 close();
205 if (error is OSError) { 205 if (error is OSError) {
206 doReportError(new SocketIOException(message, error)); 206 doReportError(new SocketIOException(message, error));
207 } else if (error is List) { 207 } else if (error is List) {
208 assert(_isErrorResponse(error)); 208 assert(_isErrorResponse(error));
209 switch (error[0]) { 209 switch (error[0]) {
210 case _FileUtils.kIllegalArgumentResponse: 210 case _FileUtils.ILLEGAL_ARGUMENT_RESPONSE:
211 doReportError(new IllegalArgumentException()); 211 doReportError(new IllegalArgumentException());
212 break; 212 break;
213 case _FileUtils.kOSErrorResponse: 213 case _FileUtils.OSERROR_RESPONSE:
214 doReportError(new SocketIOException( 214 doReportError(new SocketIOException(
215 message, new OSError(error[2], error[1]))); 215 message, new OSError(error[2], error[1])));
216 break; 216 break;
217 default: 217 default:
218 doReportError(new Exception("Unknown error")); 218 doReportError(new Exception("Unknown error"));
219 break; 219 break;
220 } 220 }
221 } else { 221 } else {
222 doReportError(new SocketIOException(message)); 222 doReportError(new SocketIOException(message));
223 } 223 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 306 }
307 307
308 bool _isListenSocket() => true; 308 bool _isListenSocket() => true;
309 bool _isPipe() => false; 309 bool _isPipe() => false;
310 310
311 var _clientConnectionHandler; 311 var _clientConnectionHandler;
312 } 312 }
313 313
314 314
315 class _Socket extends _SocketBase implements Socket { 315 class _Socket extends _SocketBase implements Socket {
316 static final kSuccessResponse = 0; 316 static final HOST_NAME_LOOKUP = 0;
317 static final kIllegalArgumentResponse = 1;
318 static final kOSErrorResponse = 2;
319
320 static final kHostNameLookup = 0;
321 317
322 // Constructs a new socket. During the construction an asynchronous 318 // Constructs a new socket. During the construction an asynchronous
323 // host name lookup is initiated. The returned socket is not yet 319 // host name lookup is initiated. The returned socket is not yet
324 // connected but ready for registration of callbacks. 320 // connected but ready for registration of callbacks.
325 factory _Socket(String host, int port) { 321 factory _Socket(String host, int port) {
326 Socket socket = new _Socket._internal(); 322 Socket socket = new _Socket._internal();
327 _ensureSocketService(); 323 _ensureSocketService();
328 List request = new List(2); 324 List request = new List(2);
329 request[0] = kHostNameLookup; 325 request[0] = HOST_NAME_LOOKUP;
330 request[1] = host; 326 request[1] = host;
331 _socketService.call(request).then((response) { 327 _socketService.call(request).then((response) {
332 if (socket._isErrorResponse(response)) { 328 if (socket._isErrorResponse(response)) {
333 socket._reportError(response, "Failed host name lookup"); 329 socket._reportError(response, "Failed host name lookup");
334 } else{ 330 } else{
335 var result = socket._createConnect(response, port); 331 var result = socket._createConnect(response, port);
336 if (result is OSError) { 332 if (result is OSError) {
337 socket.close(); 333 socket.close();
338 socket._reportError(result, "Connection failed"); 334 socket._reportError(result, "Connection failed");
339 } else { 335 } else {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 432 }
437 return result; 433 return result;
438 } 434 }
439 throw new SocketIOException("writeList failed - invalid socket handle"); 435 throw new SocketIOException("writeList failed - invalid socket handle");
440 } 436 }
441 437
442 _writeList(List<int> buffer, int offset, int bytes) 438 _writeList(List<int> buffer, int offset, int bytes)
443 native "Socket_WriteList"; 439 native "Socket_WriteList";
444 440
445 bool _isErrorResponse(response) { 441 bool _isErrorResponse(response) {
446 return response is List && response[0] != _FileUtils.kSuccessResponse; 442 return response is List && response[0] != _FileUtils.SUCCESS_RESPONSE;
447 } 443 }
448 444
449 bool _createConnect(String host, int port) native "Socket_CreateConnect"; 445 bool _createConnect(String host, int port) native "Socket_CreateConnect";
450 446
451 void set onWrite(void callback()) { 447 void set onWrite(void callback()) {
452 if (_outputStream != null) throw new StreamException( 448 if (_outputStream != null) throw new StreamException(
453 "Cannot set write handler when output stream is used"); 449 "Cannot set write handler when output stream is used");
454 _clientWriteHandler = callback; 450 _clientWriteHandler = callback;
455 _updateOutHandler(); 451 _updateOutHandler();
456 } 452 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 bool _seenFirstOutEvent = false; 585 bool _seenFirstOutEvent = false;
590 bool _pipe = false; 586 bool _pipe = false;
591 Function _clientConnectHandler; 587 Function _clientConnectHandler;
592 Function _clientWriteHandler; 588 Function _clientWriteHandler;
593 SocketInputStream _inputStream; 589 SocketInputStream _inputStream;
594 SocketOutputStream _outputStream; 590 SocketOutputStream _outputStream;
595 String _remoteHost; 591 String _remoteHost;
596 int _remotePort; 592 int _remotePort;
597 static SendPort _socketService; 593 static SendPort _socketService;
598 } 594 }
OLDNEW
« no previous file with comments | « runtime/bin/file_win.cc ('k') | tests/standalone/io/file_fuzz_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698