Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: runtime/bin/socket_stream.dart

Issue 8318009: Update the streams interfaces (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Starting implementation Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/socket_stream.dart
diff --git a/runtime/bin/socket_stream.dart b/runtime/bin/socket_stream.dart
index 7bcd72e84700e5ee401fd7ee7025f4b7c2ed02d8..26a3a9410848c83368c72fedc8c639e48883ba63 100644
--- a/runtime/bin/socket_stream.dart
+++ b/runtime/bin/socket_stream.dart
@@ -2,6 +2,46 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+class SocketInputStream2 implements InputStream2 {
+ SocketInputStream2(Socket socket) {
+ _socket = socket;
+ }
+
+ List<int> read() {
+ // Return whatever data is available.
+ int available = _socket.available();
+ if (available == 0) {
+ return null;
+ }
+ List<int> buffer = new List<int>(available);
+ int read = _socket.readList(buffer, 0, available);
+ if (read < available) {
+ List<int> newBuffer = new List<int>(read);
+ newBuffer.copyFrom(buffer, 0, 0, read);
+ return newBuffer;
+ } else {
+ return buffer;
+ }
+ }
+
+ void set dataHandler(void callback()) {
+ _socket.setDataHandler(callback);
+ }
+
+ void set closeHandler(void callback()) {
+ _socket.setCloseHandler(callback);
+ }
+
+ void set errorHandler(void callback(int error)) {
+ _socket.setErrorHandler(
+ void _() { callback(-1); }
+ );
+ }
+
+ Socket _socket;
+}
+
+
class SocketInputStream implements InputStream {
SocketInputStream(Socket socket) {
_socket = socket;
@@ -154,9 +194,7 @@ class SocketInputStream implements InputStream {
}
class SocketOutputStream implements OutputStream {
- SocketOutputStream(Socket socket) {
- _socket = socket;
- }
+ SocketOutputStream(Socket socket) : _socket = socket;
bool write(List<int> buffer, int offset, int len, void callback()) {
int bytesWritten = _socket.writeList(buffer, offset, len);

Powered by Google App Engine
This is Rietveld 408576698