| 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 ServerSocket default _ServerSocket { |
| 6 /** | 6 /** |
| 7 * Constructs a new server socket, binds it to a given address and port, | 7 * Constructs a new server socket, binds it to a given address and port, |
| 8 * and listens on it. | 8 * and listens on it. |
| 9 */ | 9 */ |
| 10 ServerSocket(String bindAddress, int port, int backlog); | 10 ServerSocket(String bindAddress, int port, int backlog); |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * The connection handler gets called when there is a new incoming | 13 * The connection handler gets called when there is a new incoming |
| 14 * connection on the socket. | 14 * connection on the socket. |
| 15 */ | 15 */ |
| 16 void set onConnection(void callback(Socket connection)); | 16 void set onConnection(void callback(Socket connection)); |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * The error handler gets called when a socket error occurs. | 19 * The error handler gets called when a socket error occurs. |
| 20 */ | 20 */ |
| 21 void set onError(void callback()); | 21 void set onError(void callback(Exception e)); |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Returns the port used by this socket. | 24 * Returns the port used by this socket. |
| 25 */ | 25 */ |
| 26 int get port(); | 26 int get port(); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Closes the socket. | 29 * Closes the socket. |
| 30 */ | 30 */ |
| 31 void close(); | 31 void close(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 interface Socket extends Hashable default _Socket { | 35 interface Socket extends Hashable default _Socket { |
| 36 /** | 36 /** |
| 37 * Constructs a new socket and connects it to the given host on the given | 37 * Constructs a new socket and initiate connecting it to the given |
| 38 * port. | 38 * host on the given port. The returned socket is not yet connected |
| 39 * but ready for registration of callbacks. |
| 39 */ | 40 */ |
| 40 Socket(String host, int port); | 41 Socket(String host, int port); |
| 41 | 42 |
| 42 /** | 43 /** |
| 43 * Returns the number of received and non-read bytes in the socket that | 44 * Returns the number of received and non-read bytes in the socket that |
| 44 * can be read. | 45 * can be read. |
| 45 */ | 46 */ |
| 46 int available(); | 47 int available(); |
| 47 | 48 |
| 48 /** | 49 /** |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 /** | 82 /** |
| 82 * The close handler gets called when a the last byte have been read | 83 * The close handler gets called when a the last byte have been read |
| 83 * from a socket. At this point the socket might still be open for | 84 * from a socket. At this point the socket might still be open for |
| 84 * writing for sending more data. | 85 * writing for sending more data. |
| 85 */ | 86 */ |
| 86 void set onClosed(void callback()); | 87 void set onClosed(void callback()); |
| 87 | 88 |
| 88 /** | 89 /** |
| 89 * The error handler gets called when a socket error occurs. | 90 * The error handler gets called when a socket error occurs. |
| 90 */ | 91 */ |
| 91 void set onError(void callback()); | 92 void set onError(void callback(Exception e)); |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * Returns input stream to the socket. | 95 * Returns input stream to the socket. |
| 95 */ | 96 */ |
| 96 InputStream get inputStream(); | 97 InputStream get inputStream(); |
| 97 | 98 |
| 98 /** | 99 /** |
| 99 * Returns output stream of the socket. | 100 * Returns output stream of the socket. |
| 100 */ | 101 */ |
| 101 OutputStream get outputStream(); | 102 OutputStream get outputStream(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 void close([bool halfClose]); | 116 void close([bool halfClose]); |
| 116 | 117 |
| 117 /** | 118 /** |
| 118 * Socket is hashable. | 119 * Socket is hashable. |
| 119 */ | 120 */ |
| 120 int hashCode(); | 121 int hashCode(); |
| 121 } | 122 } |
| 122 | 123 |
| 123 | 124 |
| 124 class SocketIOException implements Exception { | 125 class SocketIOException implements Exception { |
| 125 const SocketIOException([String this.message = ""]); | 126 const SocketIOException([String this.message = "", |
| 126 String toString() => "SocketIOException: $message"; | 127 OSError this.osError = null]); |
| 128 String toString() { |
| 129 StringBuffer sb = new StringBuffer(); |
| 130 sb.add("SocketIOException"); |
| 131 if (!message.isEmpty()) { |
| 132 sb.add(": $message"); |
| 133 if (osError != null) { |
| 134 sb.add(" ($osError)"); |
| 135 } |
| 136 } else if (osError != null) { |
| 137 sb.add(": osError"); |
| 138 } |
| 139 return sb.toString(); |
| 140 } |
| 127 final String message; | 141 final String message; |
| 142 final OSError osError; |
| 128 } | 143 } |
| OLD | NEW |