Chromium Code Reviews| 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 interface ServerSocket default _ServerSocket { | 5 interface TlsSocket extends Socket, Hashable default _TlsSocket { |
| 6 /** | |
| 7 * Constructs a new server socket, binds it to a given address and port, | |
| 8 * and listens on it. | |
| 9 */ | |
| 10 ServerSocket(String bindAddress, int port, int backlog); | |
| 11 | |
| 12 /** | |
| 13 * The connection handler gets called when there is a new incoming | |
| 14 * connection on the socket. | |
| 15 */ | |
| 16 void set onConnection(void callback(Socket connection)); | |
| 17 | |
| 18 /** | |
| 19 * The error handler gets called when a socket error occurs. | |
| 20 */ | |
| 21 void set onError(void callback(e)); | |
| 22 | |
| 23 /** | |
| 24 * Returns the port used by this socket. | |
| 25 */ | |
| 26 int get port(); | |
| 27 | |
| 28 /** | |
| 29 * Closes the socket. | |
| 30 */ | |
| 31 void close(); | |
| 32 } | |
| 33 | |
| 34 | |
| 35 interface Socket extends Hashable default _Socket { | |
| 36 /** | 6 /** |
| 37 * Constructs a new socket and initiate connecting it to the given | 7 * Constructs a new socket and initiate connecting it to the given |
| 38 * host on the given port. The returned socket is not yet connected | 8 * host on the given port. The returned socket is not yet connected |
| 39 * but ready for registration of callbacks. | 9 * but ready for registration of callbacks. |
| 40 */ | 10 */ |
| 41 Socket(String host, int port); | 11 TlsSocket(String host, int port); |
| 42 | 12 |
| 43 /** | 13 /** |
| 44 * Returns the number of received and non-read bytes in the socket that | 14 * Returns the number of received and non-read bytes in the socket that |
| 45 * can be read. | 15 * can be read. |
| 46 */ | 16 */ |
| 47 int available(); | 17 int available(); |
| 48 | 18 |
| 49 /** | 19 /** |
| 50 * Reads up to [count] bytes of data from the socket and stores them into | 20 * Reads up to [count] bytes of data from the socket and stores them into |
| 51 * buffer after buffer offset [offset]. The number of successfully read | 21 * buffer after buffer offset [offset]. The number of successfully read |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 67 * succeeded. | 37 * succeeded. |
| 68 */ | 38 */ |
| 69 void set onConnect(void callback()); | 39 void set onConnect(void callback()); |
| 70 | 40 |
| 71 /** | 41 /** |
| 72 * The data handler gets called when data becomes available at the socket. | 42 * The data handler gets called when data becomes available at the socket. |
| 73 */ | 43 */ |
| 74 void set onData(void callback()); | 44 void set onData(void callback()); |
| 75 | 45 |
| 76 /** | 46 /** |
| 77 * The write handler gets called once when the socket becomes | 47 * The write handler gets called when the socket becomes available for |
|
Anders Johnsen
2012/07/27 15:58:49
The logic should be the same as for any other Sock
Bill Hesse
2012/08/08 17:00:05
All of this code is removed.
On 2012/07/27 15:58:
| |
| 78 * available for writing. Then the handler is automatically reset to null. | 48 * writing. |
| 79 * This handler is mainly used when writeList has reported an incomplete | |
| 80 * write, to schedule writing the remaining data to the socket. | |
| 81 */ | 49 */ |
| 82 void set onWrite(void callback()); | 50 void set onWrite(void callback()); |
| 83 | 51 |
| 84 /** | 52 /** |
| 85 * The close handler gets called when a the last byte have been read | 53 * The close handler gets called when a the last byte have been read |
| 86 * from a socket. At this point the socket might still be open for | 54 * from a socket. At this point the socket might still be open for |
| 87 * writing for sending more data. | 55 * writing for sending more data. |
| 88 */ | 56 */ |
| 89 void set onClosed(void callback()); | 57 void set onClosed(void callback()); |
| 90 | 58 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 118 */ | 86 */ |
| 119 String get remoteHost(); | 87 String get remoteHost(); |
| 120 | 88 |
| 121 /** | 89 /** |
| 122 * Closes the socket. Calling [close] will never throw an exception | 90 * Closes the socket. Calling [close] will never throw an exception |
| 123 * and calling it several times is supported. If [halfClose] is true | 91 * and calling it several times is supported. If [halfClose] is true |
| 124 * the socket will only be closed for writing and it might still be | 92 * the socket will only be closed for writing and it might still be |
| 125 * possible to read data. Calling [close] will not trigger a call to | 93 * possible to read data. Calling [close] will not trigger a call to |
| 126 * [onClosed]. | 94 * [onClosed]. |
| 127 */ | 95 */ |
| 128 void close([bool halfClose]); | 96 void close([bool halfClose = false]); |
|
Anders Johnsen
2012/07/27 15:58:49
Should not be here.
Bill Hesse
2012/08/08 17:00:05
Done.
| |
| 129 | 97 |
| 130 /** | 98 /** |
| 131 * Socket is hashable. | 99 * Socket is hashable. |
| 132 */ | 100 */ |
| 133 int hashCode(); | 101 int hashCode(); |
| 134 } | 102 } |
| 135 | |
| 136 | |
| 137 class SocketIOException implements Exception { | |
| 138 const SocketIOException([String this.message = "", | |
| 139 OSError this.osError = null]); | |
| 140 String toString() { | |
| 141 StringBuffer sb = new StringBuffer(); | |
| 142 sb.add("SocketIOException"); | |
| 143 if (!message.isEmpty()) { | |
| 144 sb.add(": $message"); | |
| 145 if (osError != null) { | |
| 146 sb.add(" ($osError)"); | |
| 147 } | |
| 148 } else if (osError != null) { | |
| 149 sb.add(": $osError"); | |
| 150 } | |
| 151 return sb.toString(); | |
| 152 } | |
| 153 final String message; | |
| 154 final OSError osError; | |
| 155 } | |
| OLD | NEW |