| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 233 } |
| 234 throw new | 234 throw new |
| 235 SocketIOException("Error: accept failed - invalid socket handle"); | 235 SocketIOException("Error: accept failed - invalid socket handle"); |
| 236 } | 236 } |
| 237 | 237 |
| 238 bool _accept(Socket socket) native "ServerSocket_Accept"; | 238 bool _accept(Socket socket) native "ServerSocket_Accept"; |
| 239 | 239 |
| 240 bool _createBindListen(String bindAddress, int port, int backlog) | 240 bool _createBindListen(String bindAddress, int port, int backlog) |
| 241 native "ServerSocket_CreateBindListen"; | 241 native "ServerSocket_CreateBindListen"; |
| 242 | 242 |
| 243 void set connectionHandler(void callback()) { | 243 void set connectionHandler(void callback(Socket connection)) { |
| 244 _setHandler(_IN_EVENT, callback); | 244 _clientConnectionHandler = callback; |
| 245 _setHandler(_IN_EVENT, |
| 246 _clientConnectionHandler != null ? _connectionHandler : null); |
| 247 } |
| 248 |
| 249 void _connectionHandler() { |
| 250 if (_id >= 0) { |
| 251 _Socket socket = new _Socket._internal(); |
| 252 if (_accept(socket)) _clientConnectionHandler(socket); |
| 253 } |
| 245 } | 254 } |
| 246 | 255 |
| 247 bool _isListenSocket() => true; | 256 bool _isListenSocket() => true; |
| 248 bool _isPipe() => false; | 257 bool _isPipe() => false; |
| 258 |
| 259 var _clientConnectionHandler; |
| 249 } | 260 } |
| 250 | 261 |
| 251 | 262 |
| 252 class _Socket extends _SocketBase implements Socket { | 263 class _Socket extends _SocketBase implements Socket { |
| 253 /* | 264 /* |
| 254 * Constructor for socket. First a socket object is allocated | 265 * Constructor for socket. First a socket object is allocated |
| 255 * in which the native socket is stored. After that _createConnect is | 266 * in which the native socket is stored. After that _createConnect is |
| 256 * called which creates a file discriptor and connects to the given | 267 * called which creates a file discriptor and connects to the given |
| 257 * host on the given port. Null is returned if file descriptor creation | 268 * host on the given port. Null is returned if file descriptor creation |
| 258 * or connect failed. | 269 * or connect failed. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 return _outputStream; | 396 return _outputStream; |
| 386 } | 397 } |
| 387 | 398 |
| 388 bool _closedRead = false; | 399 bool _closedRead = false; |
| 389 bool _closedWrite = false; | 400 bool _closedWrite = false; |
| 390 bool _pipe = false; | 401 bool _pipe = false; |
| 391 SocketInputStream _inputStream; | 402 SocketInputStream _inputStream; |
| 392 SocketOutputStream _outputStream; | 403 SocketOutputStream _outputStream; |
| 393 } | 404 } |
| 394 | 405 |
| OLD | NEW |