| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // Socket close state | 279 // Socket close state |
| 280 bool isClosed = false; | 280 bool isClosed = false; |
| 281 bool isClosing = false; | 281 bool isClosing = false; |
| 282 bool isClosedRead = false; | 282 bool isClosedRead = false; |
| 283 bool isClosedWrite = false; | 283 bool isClosedWrite = false; |
| 284 Completer closeCompleter = new Completer.sync(); | 284 Completer closeCompleter = new Completer.sync(); |
| 285 | 285 |
| 286 // Handlers and receive port for socket events from the event handler. | 286 // Handlers and receive port for socket events from the event handler. |
| 287 final List eventHandlers = new List(EVENT_COUNT + 1); | 287 final List eventHandlers = new List(EVENT_COUNT + 1); |
| 288 RawReceivePort eventPort; | 288 RawReceivePort eventPort; |
| 289 bool flagsSent = false; |
| 289 | 290 |
| 290 // The type flags for this socket. | 291 // The type flags for this socket. |
| 291 final int typeFlags; | 292 final int typeFlags; |
| 292 | 293 |
| 293 // Holds the port of the socket, 0 if not known. | 294 // Holds the port of the socket, 0 if not known. |
| 294 int localPort = 0; | 295 int localPort = 0; |
| 295 | 296 |
| 296 // Holds the address used to connect or bind the socket. | 297 // Holds the address used to connect or bind the socket. |
| 297 InternetAddress address; | 298 InternetAddress address; |
| 298 | 299 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 port, | 451 port, |
| 451 backlog, | 452 backlog, |
| 452 v6Only); | 453 v6Only); |
| 453 if (result is OSError) { | 454 if (result is OSError) { |
| 454 throw new SocketException("Failed to create server socket", | 455 throw new SocketException("Failed to create server socket", |
| 455 osError: result, | 456 osError: result, |
| 456 address: address, | 457 address: address, |
| 457 port: port); | 458 port: port); |
| 458 } | 459 } |
| 459 if (port != 0) socket.localPort = port; | 460 if (port != 0) socket.localPort = port; |
| 461 socket.connectToEventHandler(); |
| 460 return socket; | 462 return socket; |
| 461 }); | 463 }); |
| 462 } | 464 } |
| 463 | 465 |
| 464 static Future<_NativeSocket> bindDatagram( | 466 static Future<_NativeSocket> bindDatagram( |
| 465 host, int port, bool reuseAddress) { | 467 host, int port, bool reuseAddress) { |
| 466 return new Future.value(host) | 468 return new Future.value(host) |
| 467 .then((host) { | 469 .then((host) { |
| 468 if (host is _InternetAddress) return host; | 470 if (host is _InternetAddress) return host; |
| 469 return lookup(host) | 471 return lookup(host) |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 } | 754 } |
| 753 } | 755 } |
| 754 } | 756 } |
| 755 if (!isListening) { | 757 if (!isListening) { |
| 756 tokens++; | 758 tokens++; |
| 757 returnTokens(NORMAL_TOKEN_BATCH_SIZE); | 759 returnTokens(NORMAL_TOKEN_BATCH_SIZE); |
| 758 } | 760 } |
| 759 } | 761 } |
| 760 | 762 |
| 761 void returnTokens(int tokenBatchSize) { | 763 void returnTokens(int tokenBatchSize) { |
| 762 if (eventPort != null && !isClosing && !isClosed) { | 764 if (!isClosing && !isClosed) { |
| 765 assert(eventPort != null); |
| 763 // Return in batches. | 766 // Return in batches. |
| 764 if (tokens == tokenBatchSize) { | 767 if (tokens == tokenBatchSize) { |
| 765 assert(tokens < (1 << FIRST_COMMAND)); | 768 assert(tokens < (1 << FIRST_COMMAND)); |
| 766 sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | tokens); | 769 sendToEventHandler((1 << RETURN_TOKEN_COMMAND) | tokens); |
| 767 tokens = 0; | 770 tokens = 0; |
| 768 } | 771 } |
| 769 } | 772 } |
| 770 } | 773 } |
| 771 | 774 |
| 772 void setHandlers({read, write, error, closed, destroyed}) { | 775 void setHandlers({read, write, error, closed, destroyed}) { |
| 773 eventHandlers[READ_EVENT] = read; | 776 eventHandlers[READ_EVENT] = read; |
| 774 eventHandlers[WRITE_EVENT] = write; | 777 eventHandlers[WRITE_EVENT] = write; |
| 775 eventHandlers[ERROR_EVENT] = error; | 778 eventHandlers[ERROR_EVENT] = error; |
| 776 eventHandlers[CLOSED_EVENT] = closed; | 779 eventHandlers[CLOSED_EVENT] = closed; |
| 777 eventHandlers[DESTROYED_EVENT] = destroyed; | 780 eventHandlers[DESTROYED_EVENT] = destroyed; |
| 778 } | 781 } |
| 779 | 782 |
| 780 void setListening({read: true, write: true}) { | 783 void setListening({read: true, write: true}) { |
| 781 sendReadEvents = read; | 784 sendReadEvents = read; |
| 782 sendWriteEvents = write; | 785 sendWriteEvents = write; |
| 783 if (read) issueReadEvent(); | 786 if (read) issueReadEvent(); |
| 784 if (write) issueWriteEvent(); | 787 if (write) issueWriteEvent(); |
| 785 if (eventPort == null && !isClosing) { | 788 if (!flagsSent && !isClosing) { |
| 789 flagsSent = true; |
| 786 int flags = typeFlags & TYPE_TYPE_MASK; | 790 int flags = typeFlags & TYPE_TYPE_MASK; |
| 787 if (!isClosedRead) flags |= 1 << READ_EVENT; | 791 if (!isClosedRead) flags |= 1 << READ_EVENT; |
| 788 if (!isClosedWrite) flags |= 1 << WRITE_EVENT; | 792 if (!isClosedWrite) flags |= 1 << WRITE_EVENT; |
| 789 sendToEventHandler(flags); | 793 sendToEventHandler(flags); |
| 790 } | 794 } |
| 791 } | 795 } |
| 792 | 796 |
| 793 Future close() { | 797 Future close() { |
| 794 if (!isClosing && !isClosed) { | 798 if (!isClosing && !isClosed) { |
| 795 sendToEventHandler(1 << CLOSE_COMMAND); | 799 sendToEventHandler(1 << CLOSE_COMMAND); |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 String address, | 1902 String address, |
| 1899 List<int> in_addr, | 1903 List<int> in_addr, |
| 1900 int port) { | 1904 int port) { |
| 1901 return new Datagram( | 1905 return new Datagram( |
| 1902 data, | 1906 data, |
| 1903 new _InternetAddress(address, null, in_addr), | 1907 new _InternetAddress(address, null, in_addr), |
| 1904 port); | 1908 port); |
| 1905 } | 1909 } |
| 1906 | 1910 |
| 1907 String _socketsStats() => _SocketsObservatory.toJSON(); | 1911 String _socketsStats() => _SocketsObservatory.toJSON(); |
| OLD | NEW |