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

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

Issue 11606020: Reapply "Fixes to eventhandler and HTTP"" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove invalid assert (fixes Windows test) Created 8 years 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/socket.cc ('k') | sdk/lib/io/http_impl.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 _canActivateHandlers = false; 59 _canActivateHandlers = false;
60 for (int i = _FIRST_EVENT; i <= _LAST_EVENT; i++) { 60 for (int i = _FIRST_EVENT; i <= _LAST_EVENT; i++) {
61 if (((event_mask & (1 << i)) != 0)) { 61 if (((event_mask & (1 << i)) != 0)) {
62 if ((i == _CLOSE_EVENT) && this is _Socket && !_closed) { 62 if ((i == _CLOSE_EVENT) && this is _Socket && !_closed) {
63 _closedRead = true; 63 _closedRead = true;
64 if (_closedWrite) _close(); 64 if (_closedWrite) _close();
65 } 65 }
66 66
67 var eventHandler = _handlerMap[i]; 67 var eventHandler = _handlerMap[i];
68 if (eventHandler != null || i == _ERROR_EVENT) { 68 if (eventHandler != null || i == _ERROR_EVENT) {
69 // Unregister the out handler before executing it. 69 // Unregister the out handler before executing it. There is
70 if (i == _OUT_EVENT) _setHandler(i, null); 70 // no need to notify the eventhandler as handlers are
71 // disabled while the event is handled.
72 if (i == _OUT_EVENT) _setHandler(i, null, notifyEventhandler: false);
71 73
72 // Don't call the in handler if there is no data available 74 // Don't call the in handler if there is no data available
73 // after all. 75 // after all.
74 if ((i == _IN_EVENT) && (this is _Socket) && (available() == 0)) { 76 if ((i == _IN_EVENT) && (this is _Socket) && (available() == 0)) {
75 continue; 77 continue;
76 } 78 }
77 if (i == _ERROR_EVENT) { 79 if (i == _ERROR_EVENT) {
78 _reportError(_getError(), ""); 80 _reportError(_getError(), "");
79 close(); 81 close();
80 } else { 82 } else {
81 eventHandler(); 83 eventHandler();
82 } 84 }
83 } 85 }
84 } 86 }
85 } 87 }
86 _canActivateHandlers = true; 88 _canActivateHandlers = true;
87 _activateHandlers(); 89 _activateHandlers();
88 } 90 }
89 91
90 void _setHandler(int event, Function callback) { 92 void _setHandler(int event,
93 Function callback,
94 {bool notifyEventhandler: true}) {
91 if (callback == null) { 95 if (callback == null) {
92 _handlerMask &= ~(1 << event); 96 _handlerMask &= ~(1 << event);
93 } else { 97 } else {
94 _handlerMask |= (1 << event); 98 _handlerMask |= (1 << event);
95 } 99 }
96 _handlerMap[event] = callback; 100 _handlerMap[event] = callback;
97 // If the socket is only for writing then close the receive port 101 // If the socket is only for writing then close the receive port
98 // when not waiting for any events. 102 // when not waiting for any events.
99 if (this is _Socket && 103 if (this is _Socket &&
100 _closedRead && 104 _closedRead &&
101 _handlerMask == 0 && 105 _handlerMask == 0 &&
102 _handler != null) { 106 _handler != null) {
103 _handler.close(); 107 _handler.close();
104 _handler = null; 108 _handler = null;
105 } else { 109 } else {
106 _activateHandlers(); 110 if (notifyEventhandler) _activateHandlers();
107 } 111 }
108 } 112 }
109 113
110 OSError _getError() native "Socket_GetError"; 114 OSError _getError() native "Socket_GetError";
111 115
112 int _getPort() native "Socket_GetPort"; 116 int _getPort() native "Socket_GetPort";
113 117
114 void set onError(void callback(e)) { 118 void set onError(void callback(e)) {
115 _setHandler(_ERROR_EVENT, callback); 119 _setHandler(_ERROR_EVENT, callback);
116 } 120 }
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 bool _seenFirstOutEvent = false; 598 bool _seenFirstOutEvent = false;
595 bool _pipe = false; 599 bool _pipe = false;
596 Function _clientConnectHandler; 600 Function _clientConnectHandler;
597 Function _clientWriteHandler; 601 Function _clientWriteHandler;
598 _SocketInputStream _inputStream; 602 _SocketInputStream _inputStream;
599 _SocketOutputStream _outputStream; 603 _SocketOutputStream _outputStream;
600 String _remoteHost; 604 String _remoteHost;
601 int _remotePort; 605 int _remotePort;
602 static SendPort _socketService; 606 static SendPort _socketService;
603 } 607 }
OLDNEW
« no previous file with comments | « runtime/bin/socket.cc ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698