| OLD | NEW |
| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 275 |
| 276 _ServerSocket._internal(); | 276 _ServerSocket._internal(); |
| 277 | 277 |
| 278 _accept(Socket socket) native "ServerSocket_Accept"; | 278 _accept(Socket socket) native "ServerSocket_Accept"; |
| 279 | 279 |
| 280 _createBindListen(String bindAddress, int port, int backlog) | 280 _createBindListen(String bindAddress, int port, int backlog) |
| 281 native "ServerSocket_CreateBindListen"; | 281 native "ServerSocket_CreateBindListen"; |
| 282 | 282 |
| 283 void set onConnection(void callback(Socket connection)) { | 283 void set onConnection(void callback(Socket connection)) { |
| 284 _clientConnectionHandler = callback; | 284 _clientConnectionHandler = callback; |
| 285 _setHandler(_IN_EVENT, | 285 _setHandler(_SocketBase._IN_EVENT, |
| 286 _clientConnectionHandler != null ? _connectionHandler : null); | 286 _clientConnectionHandler != null ? _connectionHandler : null); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void _connectionHandler() { | 289 void _connectionHandler() { |
| 290 if (_id >= 0) { | 290 if (_id >= 0) { |
| 291 _Socket socket = new _Socket._internal(); | 291 _Socket socket = new _Socket._internal(); |
| 292 var result = _accept(socket); | 292 var result = _accept(socket); |
| 293 if (result is OSError) { | 293 if (result is OSError) { |
| 294 _reportError(result, "Accept failed"); | 294 _reportError(result, "Accept failed"); |
| 295 } else if (result) { | 295 } else if (result) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 "Cannot set close handler when input stream is used"); | 476 "Cannot set close handler when input stream is used"); |
| 477 _onClosed = callback; | 477 _onClosed = callback; |
| 478 } | 478 } |
| 479 | 479 |
| 480 bool _isListenSocket() => false; | 480 bool _isListenSocket() => false; |
| 481 | 481 |
| 482 bool _isPipe() => _pipe; | 482 bool _isPipe() => _pipe; |
| 483 | 483 |
| 484 InputStream get inputStream() { | 484 InputStream get inputStream() { |
| 485 if (_inputStream == null) { | 485 if (_inputStream == null) { |
| 486 if (_handlerMap[_IN_EVENT] !== null || | 486 if (_handlerMap[_SocketBase._IN_EVENT] !== null || |
| 487 _handlerMap[_CLOSE_EVENT] !== null) { | 487 _handlerMap[_SocketBase._CLOSE_EVENT] !== null) { |
| 488 throw new StreamException( | 488 throw new StreamException( |
| 489 "Cannot get input stream when socket handlers are used"); | 489 "Cannot get input stream when socket handlers are used"); |
| 490 } | 490 } |
| 491 _inputStream = new SocketInputStream(this); | 491 _inputStream = new SocketInputStream(this); |
| 492 } | 492 } |
| 493 return _inputStream; | 493 return _inputStream; |
| 494 } | 494 } |
| 495 | 495 |
| 496 OutputStream get outputStream() { | 496 OutputStream get outputStream() { |
| 497 if (_outputStream == null) { | 497 if (_outputStream == null) { |
| 498 if (_handlerMap[_OUT_EVENT] !== null) { | 498 if (_handlerMap[_SocketBase._OUT_EVENT] !== null) { |
| 499 throw new StreamException( | 499 throw new StreamException( |
| 500 "Cannot get input stream when socket handlers are used"); | 500 "Cannot get input stream when socket handlers are used"); |
| 501 } | 501 } |
| 502 _outputStream = new SocketOutputStream(this); | 502 _outputStream = new SocketOutputStream(this); |
| 503 } | 503 } |
| 504 return _outputStream; | 504 return _outputStream; |
| 505 } | 505 } |
| 506 | 506 |
| 507 void set _onWrite(void callback()) { | 507 void set _onWrite(void callback()) { |
| 508 _setHandler(_OUT_EVENT, callback); | 508 _setHandler(_SocketBase._OUT_EVENT, callback); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void set _onData(void callback()) { | 511 void set _onData(void callback()) { |
| 512 _setHandler(_IN_EVENT, callback); | 512 _setHandler(_SocketBase._IN_EVENT, callback); |
| 513 } | 513 } |
| 514 | 514 |
| 515 void set _onClosed(void callback()) { | 515 void set _onClosed(void callback()) { |
| 516 _setHandler(_CLOSE_EVENT, callback); | 516 _setHandler(_SocketBase._CLOSE_EVENT, callback); |
| 517 } | 517 } |
| 518 | 518 |
| 519 void _propagateError(Exception e) { | 519 void _propagateError(Exception e) { |
| 520 if (_inputStream != null) { | 520 if (_inputStream != null) { |
| 521 _inputStream._onError(e); | 521 _inputStream._onError(e); |
| 522 } | 522 } |
| 523 if (_outputStream != null) { | 523 if (_outputStream != null) { |
| 524 _outputStream._onError(e); | 524 _outputStream._onError(e); |
| 525 } | 525 } |
| 526 } | 526 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 bool _seenFirstOutEvent = false; | 584 bool _seenFirstOutEvent = false; |
| 585 bool _pipe = false; | 585 bool _pipe = false; |
| 586 Function _clientConnectHandler; | 586 Function _clientConnectHandler; |
| 587 Function _clientWriteHandler; | 587 Function _clientWriteHandler; |
| 588 SocketInputStream _inputStream; | 588 SocketInputStream _inputStream; |
| 589 SocketOutputStream _outputStream; | 589 SocketOutputStream _outputStream; |
| 590 String _remoteHost; | 590 String _remoteHost; |
| 591 int _remotePort; | 591 int _remotePort; |
| 592 static SendPort _socketService; | 592 static SendPort _socketService; |
| 593 } | 593 } |
| OLD | NEW |