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 patch class ServerSocket { |
| 6 /* patch */ factory ServerSocket(String bindAddress, int port, int backlog) { |
| 7 return new _ServerSocket(bindAddress, port, backlog); |
| 8 } |
| 9 } |
| 10 |
| 11 |
| 12 patch class Socket { |
| 13 /* patch */ factory Socket(String host, int port) => new _Socket(host, port); |
| 14 } |
| 15 |
5 | 16 |
6 class _SocketBase extends NativeFieldWrapperClass1 { | 17 class _SocketBase extends NativeFieldWrapperClass1 { |
7 // Bit flags used when communicating between the eventhandler and | 18 // Bit flags used when communicating between the eventhandler and |
8 // dart code. The EVENT flags are used to indicate events of | 19 // dart code. The EVENT flags are used to indicate events of |
9 // interest when sending a message from dart code to the | 20 // interest when sending a message from dart code to the |
10 // eventhandler. When receiving a message from the eventhandler the | 21 // eventhandler. When receiving a message from the eventhandler the |
11 // EVENT flags indicate the events that actually happened. The | 22 // EVENT flags indicate the events that actually happened. The |
12 // COMMAND flags are used to send commands from dart to the | 23 // COMMAND flags are used to send commands from dart to the |
13 // eventhandler. COMMAND flags are never received from the | 24 // eventhandler. COMMAND flags are never received from the |
14 // eventhandler. Additional flags are used to communicate other | 25 // eventhandler. Additional flags are used to communicate other |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 _handlerMask == 0 && | 101 _handlerMask == 0 && |
91 _handler != null) { | 102 _handler != null) { |
92 _handler.close(); | 103 _handler.close(); |
93 _handler = null; | 104 _handler = null; |
94 } else { | 105 } else { |
95 _activateHandlers(); | 106 _activateHandlers(); |
96 } | 107 } |
97 } | 108 } |
98 | 109 |
99 OSError _getError() native "Socket_GetError"; | 110 OSError _getError() native "Socket_GetError"; |
| 111 |
100 int _getPort() native "Socket_GetPort"; | 112 int _getPort() native "Socket_GetPort"; |
101 | 113 |
102 void set onError(void callback(e)) { | 114 void set onError(void callback(e)) { |
103 _setHandler(_ERROR_EVENT, callback); | 115 _setHandler(_ERROR_EVENT, callback); |
104 } | 116 } |
105 | 117 |
106 void _activateHandlers() { | 118 void _activateHandlers() { |
107 if (_canActivateHandlers && !_closed) { | 119 if (_canActivateHandlers && !_closed) { |
108 if (_handlerMask == 0) { | 120 if (_handlerMask == 0) { |
109 if (_handler != null) { | 121 if (_handler != null) { |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 _reportError(result, "Write failed"); | 428 _reportError(result, "Write failed"); |
417 // If writing fails we return 0 as the number of bytes and | 429 // If writing fails we return 0 as the number of bytes and |
418 // report the error on the error handler. | 430 // report the error on the error handler. |
419 result = 0; | 431 result = 0; |
420 } | 432 } |
421 return result; | 433 return result; |
422 } | 434 } |
423 throw new SocketIOException("writeList failed - invalid socket handle"); | 435 throw new SocketIOException("writeList failed - invalid socket handle"); |
424 } | 436 } |
425 | 437 |
426 _writeList(List<int> buffer, int offset, int bytes) | 438 _writeList(List<int> buffer, int offset, int bytes) native "Socket_WriteList"; |
427 native "Socket_WriteList"; | |
428 | 439 |
429 bool _isErrorResponse(response) { | 440 bool _isErrorResponse(response) { |
430 return response is List && response[0] != _SUCCESS_RESPONSE; | 441 return response is List && response[0] != _SUCCESS_RESPONSE; |
431 } | 442 } |
432 | 443 |
433 bool _createConnect(String host, int port) native "Socket_CreateConnect"; | 444 bool _createConnect(String host, int port) native "Socket_CreateConnect"; |
434 | 445 |
435 void set onWrite(void callback()) { | 446 void set onWrite(void callback()) { |
436 if (_outputStream != null) throw new StreamException( | 447 if (_outputStream != null) throw new StreamException( |
437 "Cannot set write handler when output stream is used"); | 448 "Cannot set write handler when output stream is used"); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 bool _seenFirstOutEvent = false; | 584 bool _seenFirstOutEvent = false; |
574 bool _pipe = false; | 585 bool _pipe = false; |
575 Function _clientConnectHandler; | 586 Function _clientConnectHandler; |
576 Function _clientWriteHandler; | 587 Function _clientWriteHandler; |
577 _SocketInputStream _inputStream; | 588 _SocketInputStream _inputStream; |
578 _SocketOutputStream _outputStream; | 589 _SocketOutputStream _outputStream; |
579 String _remoteHost; | 590 String _remoteHost; |
580 int _remotePort; | 591 int _remotePort; |
581 static SendPort _socketService; | 592 static SendPort _socketService; |
582 } | 593 } |
OLD | NEW |