OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 RawServerSocket { | 5 patch class RawServerSocket { |
6 /* patch */ static Future<RawServerSocket> bind(address, | 6 /* patch */ static Future<RawServerSocket> bind(address, |
7 int port, | 7 int port, |
8 {int backlog: 0, | 8 {int backlog: 0, |
9 bool v6Only: false}) { | 9 bool v6Only: false}) { |
10 return _RawServerSocket.bind(address, port, backlog, v6Only); | 10 return _RawServerSocket.bind(address, port, backlog, v6Only); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 static const int ERROR_EVENT = 2; | 348 static const int ERROR_EVENT = 2; |
349 static const int CLOSED_EVENT = 3; | 349 static const int CLOSED_EVENT = 3; |
350 static const int DESTROYED_EVENT = 4; | 350 static const int DESTROYED_EVENT = 4; |
351 static const int FIRST_EVENT = READ_EVENT; | 351 static const int FIRST_EVENT = READ_EVENT; |
352 static const int LAST_EVENT = DESTROYED_EVENT; | 352 static const int LAST_EVENT = DESTROYED_EVENT; |
353 static const int EVENT_COUNT = LAST_EVENT - FIRST_EVENT + 1; | 353 static const int EVENT_COUNT = LAST_EVENT - FIRST_EVENT + 1; |
354 | 354 |
355 static const int CLOSE_COMMAND = 8; | 355 static const int CLOSE_COMMAND = 8; |
356 static const int SHUTDOWN_READ_COMMAND = 9; | 356 static const int SHUTDOWN_READ_COMMAND = 9; |
357 static const int SHUTDOWN_WRITE_COMMAND = 10; | 357 static const int SHUTDOWN_WRITE_COMMAND = 10; |
358 static const int RETURN_TOKEN_COMMAND = 11; | 358 static const int RETURN_TOKEN_COMMAND = 11; |
Søren Gjesse
2014/03/25 13:31:22
Please update this section with information that t
Anders Johnsen
2014/03/25 13:43:35
Done.
| |
359 static const int FIRST_COMMAND = CLOSE_COMMAND; | 359 static const int FIRST_COMMAND = CLOSE_COMMAND; |
360 static const int LAST_COMMAND = RETURN_TOKEN_COMMAND; | 360 static const int LAST_COMMAND = RETURN_TOKEN_COMMAND; |
361 | 361 |
362 // Type flag send to the eventhandler providing additional | 362 // Type flag send to the eventhandler providing additional |
363 // information on the type of the file descriptor. | 363 // information on the type of the file descriptor. |
364 static const int LISTENING_SOCKET = 16; | 364 static const int LISTENING_SOCKET = 16; |
365 static const int PIPE_SOCKET = 17; | 365 static const int PIPE_SOCKET = 17; |
366 static const int TYPE_NORMAL_SOCKET = 0; | 366 static const int TYPE_NORMAL_SOCKET = 0; |
367 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET; | 367 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET; |
368 static const int TYPE_PIPE = 1 << PIPE_SOCKET; | 368 static const int TYPE_PIPE = 1 << PIPE_SOCKET; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 final int typeFlags; | 403 final int typeFlags; |
404 | 404 |
405 // Holds the port of the socket, 0 if not known. | 405 // Holds the port of the socket, 0 if not known. |
406 int localPort = 0; | 406 int localPort = 0; |
407 | 407 |
408 // Holds the address used to connect or bind the socket. | 408 // Holds the address used to connect or bind the socket. |
409 InternetAddress address; | 409 InternetAddress address; |
410 | 410 |
411 int available = 0; | 411 int available = 0; |
412 | 412 |
413 int returnTokens = 0; | |
414 | |
413 bool sendReadEvents = false; | 415 bool sendReadEvents = false; |
414 bool readEventIssued = false; | 416 bool readEventIssued = false; |
415 | 417 |
416 bool sendWriteEvents = false; | 418 bool sendWriteEvents = false; |
417 bool writeEventIssued = false; | 419 bool writeEventIssued = false; |
418 bool writeAvailable = false; | 420 bool writeAvailable = false; |
419 | 421 |
420 // Statistics. | 422 // Statistics. |
421 int totalRead = 0; | 423 int totalRead = 0; |
422 int totalWritten = 0; | 424 int totalWritten = 0; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 if (!isClosing) { | 813 if (!isClosing) { |
812 reportError(nativeGetError(), ""); | 814 reportError(nativeGetError(), ""); |
813 } | 815 } |
814 } else if (!isClosed) { | 816 } else if (!isClosed) { |
815 // If the connection is closed right after it's accepted, there's a | 817 // If the connection is closed right after it's accepted, there's a |
816 // chance the close-handler is not set. | 818 // chance the close-handler is not set. |
817 if (handler != null) handler(); | 819 if (handler != null) handler(); |
818 } | 820 } |
819 } | 821 } |
820 } | 822 } |
821 if (eventPort != null && !isClosing && !isClosed) { | 823 if (eventPort != null && !isClosing && !isClosed && !isListening) { |
822 sendToEventHandler(1 << RETURN_TOKEN_COMMAND); | 824 returnTokens++; |
825 if (returnTokens == 8) { | |
826 // Return in batches of 8. | |
Søren Gjesse
2014/03/25 13:31:22
assert(1 << FIRST_COMMAND < returnTokens)
Anders Johnsen
2014/03/25 13:43:35
Done.
| |
827 sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | returnTokens); | |
828 returnTokens = 0; | |
829 } | |
823 } | 830 } |
824 } | 831 } |
825 | 832 |
826 void setHandlers({read, write, error, closed, destroyed}) { | 833 void setHandlers({read, write, error, closed, destroyed}) { |
827 eventHandlers[READ_EVENT] = read; | 834 eventHandlers[READ_EVENT] = read; |
828 eventHandlers[WRITE_EVENT] = write; | 835 eventHandlers[WRITE_EVENT] = write; |
829 eventHandlers[ERROR_EVENT] = error; | 836 eventHandlers[ERROR_EVENT] = error; |
830 eventHandlers[CLOSED_EVENT] = closed; | 837 eventHandlers[CLOSED_EVENT] = closed; |
831 eventHandlers[DESTROYED_EVENT] = destroyed; | 838 eventHandlers[DESTROYED_EVENT] = destroyed; |
832 } | 839 } |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1754 String address, | 1761 String address, |
1755 List<int> in_addr, | 1762 List<int> in_addr, |
1756 int port) { | 1763 int port) { |
1757 return new Datagram( | 1764 return new Datagram( |
1758 data, | 1765 data, |
1759 new _InternetAddress(address, null, in_addr), | 1766 new _InternetAddress(address, null, in_addr), |
1760 port); | 1767 port); |
1761 } | 1768 } |
1762 | 1769 |
1763 String _socketsStats() => _SocketsObservatory.toJSON(); | 1770 String _socketsStats() => _SocketsObservatory.toJSON(); |
OLD | NEW |