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

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

Issue 11361190: a === b -> identical(a, b) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | runtime/lib/array.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 patch class ServerSocket { 5 patch class ServerSocket {
6 /* patch */ factory ServerSocket(String bindAddress, int port, int backlog) { 6 /* patch */ factory ServerSocket(String bindAddress, int port, int backlog) {
7 return new _ServerSocket(bindAddress, port, backlog); 7 return new _ServerSocket(bindAddress, port, backlog);
8 } 8 }
9 } 9 }
10 10
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } else { 130 } else {
131 if (_closedRead) { data &= ~(1 << _IN_EVENT); } 131 if (_closedRead) { data &= ~(1 << _IN_EVENT); }
132 if (_closedWrite) { data &= ~(1 << _OUT_EVENT); } 132 if (_closedWrite) { data &= ~(1 << _OUT_EVENT); }
133 if (_isPipe()) data |= (1 << _PIPE); 133 if (_isPipe()) data |= (1 << _PIPE);
134 } 134 }
135 _sendToEventHandler(data); 135 _sendToEventHandler(data);
136 } 136 }
137 } 137 }
138 138
139 int get port { 139 int get port {
140 if (_port === null) { 140 if (_port == null) {
141 _port = _getPort(); 141 _port = _getPort();
142 } 142 }
143 return _port; 143 return _port;
144 } 144 }
145 145
146 void close([bool halfClose = false]) { 146 void close([bool halfClose = false]) {
147 if (!_closed) { 147 if (!_closed) {
148 if (halfClose) { 148 if (halfClose) {
149 _closeWrite(); 149 _closeWrite();
150 } else { 150 } else {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 void _close() { 183 void _close() {
184 if (!_closed) { 184 if (!_closed) {
185 _sendToEventHandler(1 << _CLOSE_COMMAND); 185 _sendToEventHandler(1 << _CLOSE_COMMAND);
186 _handler.close(); 186 _handler.close();
187 _handler = null; 187 _handler = null;
188 _closed = true; 188 _closed = true;
189 } 189 }
190 } 190 }
191 191
192 void _sendToEventHandler(int data) { 192 void _sendToEventHandler(int data) {
193 if (_handler === null) { 193 if (_handler == null) {
194 _handler = new ReceivePort(); 194 _handler = new ReceivePort();
195 _handler.receive((var message, ignored) { _multiplex(message); }); 195 _handler.receive((var message, ignored) { _multiplex(message); });
196 } 196 }
197 assert(!_closed); 197 assert(!_closed);
198 _EventHandler._sendData(this, _handler, data); 198 _EventHandler._sendData(this, _handler, data);
199 } 199 }
200 200
201 bool _reportError(error, String message) { 201 bool _reportError(error, String message) {
202 void doReportError(Exception e) { 202 void doReportError(Exception e) {
203 // Invoke the socket error callback if any. 203 // Invoke the socket error callback if any.
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 "Cannot set close handler when input stream is used"); 488 "Cannot set close handler when input stream is used");
489 _onClosed = callback; 489 _onClosed = callback;
490 } 490 }
491 491
492 bool _isListenSocket() => false; 492 bool _isListenSocket() => false;
493 493
494 bool _isPipe() => _pipe; 494 bool _isPipe() => _pipe;
495 495
496 InputStream get inputStream { 496 InputStream get inputStream {
497 if (_inputStream == null) { 497 if (_inputStream == null) {
498 if (_handlerMap[_SocketBase._IN_EVENT] !== null || 498 if (_handlerMap[_SocketBase._IN_EVENT] != null ||
499 _handlerMap[_SocketBase._CLOSE_EVENT] !== null) { 499 _handlerMap[_SocketBase._CLOSE_EVENT] != null) {
500 throw new StreamException( 500 throw new StreamException(
501 "Cannot get input stream when socket handlers are used"); 501 "Cannot get input stream when socket handlers are used");
502 } 502 }
503 _inputStream = new _SocketInputStream(this); 503 _inputStream = new _SocketInputStream(this);
504 } 504 }
505 return _inputStream; 505 return _inputStream;
506 } 506 }
507 507
508 OutputStream get outputStream { 508 OutputStream get outputStream {
509 if (_outputStream == null) { 509 if (_outputStream == null) {
510 if (_handlerMap[_SocketBase._OUT_EVENT] !== null) { 510 if (_handlerMap[_SocketBase._OUT_EVENT] != null) {
511 throw new StreamException( 511 throw new StreamException(
512 "Cannot get input stream when socket handlers are used"); 512 "Cannot get input stream when socket handlers are used");
513 } 513 }
514 _outputStream = new _SocketOutputStream(this); 514 _outputStream = new _SocketOutputStream(this);
515 } 515 }
516 return _outputStream; 516 return _outputStream;
517 } 517 }
518 518
519 void set _onWrite(void callback()) { 519 void set _onWrite(void callback()) {
520 _setHandler(_SocketBase._OUT_EVENT, callback); 520 _setHandler(_SocketBase._OUT_EVENT, callback);
(...skipping 20 matching lines...) Expand all
541 541
542 void _updateOutHandler() { 542 void _updateOutHandler() {
543 void firstWriteHandler() { 543 void firstWriteHandler() {
544 assert(!_seenFirstOutEvent); 544 assert(!_seenFirstOutEvent);
545 _seenFirstOutEvent = true; 545 _seenFirstOutEvent = true;
546 546
547 // From now on the write handler is only the client write 547 // From now on the write handler is only the client write
548 // handler (connect handler cannot be called again). Change this 548 // handler (connect handler cannot be called again). Change this
549 // before calling any handlers as handlers can change the 549 // before calling any handlers as handlers can change the
550 // handlers. 550 // handlers.
551 if (_clientWriteHandler === null) _onWrite = _clientWriteHandler; 551 if (_clientWriteHandler == null) _onWrite = _clientWriteHandler;
552 552
553 // First out event is socket connected event. 553 // First out event is socket connected event.
554 if (_clientConnectHandler !== null) _clientConnectHandler(); 554 if (_clientConnectHandler != null) _clientConnectHandler();
555 _clientConnectHandler = null; 555 _clientConnectHandler = null;
556 556
557 // Always (even for the first out event) call the write handler. 557 // Always (even for the first out event) call the write handler.
558 if (_clientWriteHandler !== null) _clientWriteHandler(); 558 if (_clientWriteHandler != null) _clientWriteHandler();
559 } 559 }
560 560
561 if (_clientConnectHandler === null && _clientWriteHandler === null) { 561 if (_clientConnectHandler == null && _clientWriteHandler == null) {
562 _onWrite = null; 562 _onWrite = null;
563 } else { 563 } else {
564 if (_seenFirstOutEvent) { 564 if (_seenFirstOutEvent) {
565 _onWrite = _clientWriteHandler; 565 _onWrite = _clientWriteHandler;
566 } else { 566 } else {
567 _onWrite = firstWriteHandler; 567 _onWrite = firstWriteHandler;
568 } 568 }
569 } 569 }
570 } 570 }
571 571
572 int get remotePort { 572 int get remotePort {
573 if (_remotePort === null) { 573 if (_remotePort == null) {
574 remoteHost; 574 remoteHost;
575 } 575 }
576 return _remotePort; 576 return _remotePort;
577 } 577 }
578 578
579 String get remoteHost { 579 String get remoteHost {
580 if (_remoteHost === null) { 580 if (_remoteHost == null) {
581 List peer = _getRemotePeer(); 581 List peer = _getRemotePeer();
582 _remoteHost = peer[0]; 582 _remoteHost = peer[0];
583 _remotePort = peer[1]; 583 _remotePort = peer[1];
584 } 584 }
585 return _remoteHost; 585 return _remoteHost;
586 } 586 }
587 587
588 List _getRemotePeer() native "Socket_GetRemotePeer"; 588 List _getRemotePeer() native "Socket_GetRemotePeer";
589 589
590 static SendPort _newServicePort() native "Socket_NewServicePort"; 590 static SendPort _newServicePort() native "Socket_NewServicePort";
591 591
592 static void _ensureSocketService() { 592 static void _ensureSocketService() {
593 if (_socketService == null) { 593 if (_socketService == null) {
594 _socketService = _Socket._newServicePort(); 594 _socketService = _Socket._newServicePort();
595 } 595 }
596 } 596 }
597 597
598 bool _seenFirstOutEvent = false; 598 bool _seenFirstOutEvent = false;
599 bool _pipe = false; 599 bool _pipe = false;
600 Function _clientConnectHandler; 600 Function _clientConnectHandler;
601 Function _clientWriteHandler; 601 Function _clientWriteHandler;
602 _SocketInputStream _inputStream; 602 _SocketInputStream _inputStream;
603 _SocketOutputStream _outputStream; 603 _SocketOutputStream _outputStream;
604 String _remoteHost; 604 String _remoteHost;
605 int _remotePort; 605 int _remotePort;
606 static SendPort _socketService; 606 static SendPort _socketService;
607 } 607 }
OLDNEW
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | runtime/lib/array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698