diff options
author | Koushik Dutta <koushd@gmail.com> | 2014-07-28 02:16:24 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2014-07-28 02:16:24 -0700 |
commit | c5d92d36e9613a47e54a8591484900277a2137fb (patch) | |
tree | 1f053a42c72880205c1ef585a1f0c7bc0f2e1762 /AndroidAsync | |
parent | 87387af1b33156c1a20e3948f14f0e5abf3addf9 (diff) | |
download | AndroidAsync-c5d92d36e9613a47e54a8591484900277a2137fb.tar.gz AndroidAsync-c5d92d36e9613a47e54a8591484900277a2137fb.tar.bz2 AndroidAsync-c5d92d36e9613a47e54a8591484900277a2137fb.zip |
New writer seems to work?
Diffstat (limited to 'AndroidAsync')
6 files changed, 158 insertions, 140 deletions
diff --git a/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java b/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java index 84c3307..b42a58a 100644 --- a/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java +++ b/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java @@ -41,9 +41,16 @@ public class ByteBufferList { add(b); } - public void addAll(ByteBuffer... bb) { + public ByteBufferList addAll(ByteBuffer... bb) { for (ByteBuffer b: bb) add(b); + return this; + } + + public ByteBufferList addAll(ByteBufferList... bb) { + for (ByteBufferList b: bb) + b.get(this); + return this; } public byte[] getBytes(int length) { @@ -268,12 +275,17 @@ public class ByteBufferList { // this clears out buffers that are empty in the beginning of the list read(0); } - - public void add(ByteBuffer b) { + + public ByteBufferList add(ByteBufferList b) { + b.get(this); + return this; + } + + public ByteBufferList add(ByteBuffer b) { if (b.remaining() <= 0) { // System.out.println("reclaiming remaining: " + b.remaining()); reclaim(b); - return; + return this; } addRemaining(b.remaining()); // see if we can fit the entirety of the buffer into the end @@ -289,11 +301,12 @@ public class ByteBufferList { last.reset(); reclaim(b); trim(); - return; + return this; } } mBuffers.add(b); trim(); + return this; } public void addFirst(ByteBuffer b) { diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java index 1987832..a961cbf 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java @@ -2,7 +2,6 @@ package com.koushikdutta.async.http.spdy; import com.koushikdutta.async.AsyncServer; import com.koushikdutta.async.AsyncSocket; -import com.koushikdutta.async.BufferedDataEmitter; import com.koushikdutta.async.BufferedDataSink; import com.koushikdutta.async.ByteBufferList; import com.koushikdutta.async.Util; @@ -23,7 +22,6 @@ import com.koushikdutta.async.http.spdy.okhttp.internal.spdy.Spdy3; import com.koushikdutta.async.http.spdy.okhttp.internal.spdy.Variant; import com.koushikdutta.async.http.spdy.okio.BufferedSink; import com.koushikdutta.async.http.spdy.okio.ByteString; -import com.koushikdutta.async.http.spdy.okio.Okio; import java.io.IOException; import java.util.Hashtable; @@ -97,10 +95,6 @@ public class AsyncSpdyConnection implements FrameReader.Handler { writer.pushPromise(associatedStreamId, streamId, requestHeaders); } - if (!out) { - writer.flush(); - } - return socket; } catch (IOException e) { @@ -154,12 +148,6 @@ public class AsyncSpdyConnection implements FrameReader.Handler { public SpdySocket(int id, boolean outFinished, boolean inFinished, List<Header> headerBlock) { this.id = id; - try { - writer.windowUpdate(id, DEFAULT_INITIAL_WINDOW_SIZE); - } - catch (IOException e) { - throw new AssertionError(e); - } } public boolean isLocallyInitiated() { @@ -285,7 +273,7 @@ public class AsyncSpdyConnection implements FrameReader.Handler { variant = new Http20Draft13(); } reader = variant.newReader(socket, this, true); - writer = variant.newWriter(bufferedSink = Okio.buffer(sink), true); + writer = variant.newWriter(bufferedSocket, true); boolean client = true; nextStreamId = client ? 1 : 2; diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/FrameWriter.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/FrameWriter.java index f878176..5bbf060 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/FrameWriter.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/FrameWriter.java @@ -16,7 +16,7 @@ package com.koushikdutta.async.http.spdy.okhttp.internal.spdy; -import com.koushikdutta.async.http.spdy.okio.Buffer; +import com.koushikdutta.async.ByteBufferList; import java.io.Closeable; import java.io.IOException; @@ -47,7 +47,6 @@ public interface FrameWriter extends Closeable { throws IOException; /** SPDY/3 only. */ - void flush() throws IOException; void synStream(boolean outFinished, boolean inFinished, int streamId, int associatedStreamId, List<Header> headerBlock) throws IOException; void synReply(boolean outFinished, int streamId, List<Header> headerBlock) @@ -61,9 +60,7 @@ public interface FrameWriter extends Closeable { * * @param source the buffer to draw bytes from. May be null if byteCount is 0. */ - void data(boolean outFinished, int streamId, Buffer source, int byteCount) throws IOException; - - void data(boolean outFinished, int streamId, Buffer source) throws IOException; + void data(boolean outFinished, int streamId, ByteBufferList source) throws IOException; /** Write okhttp's settings to the peer. */ void settings(Settings okHttpSettings) throws IOException; diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/HpackDraft08.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/HpackDraft08.java index f578cb2..b58d029 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/HpackDraft08.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/HpackDraft08.java @@ -17,13 +17,10 @@ package com.koushikdutta.async.http.spdy.okhttp.internal.spdy; import com.koushikdutta.async.ByteBufferList; import com.koushikdutta.async.http.spdy.okhttp.internal.BitArray; -import com.koushikdutta.async.http.spdy.okio.Buffer; -import com.koushikdutta.async.http.spdy.okio.BufferedSource; import com.koushikdutta.async.http.spdy.okio.ByteString; -import com.koushikdutta.async.http.spdy.okio.Okio; -import com.koushikdutta.async.http.spdy.okio.Source; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -434,57 +431,64 @@ final class HpackDraft08 { } static final class Writer { - private final Buffer out; - - Writer(Buffer out) { - this.out = out; + Writer() { } /** * This does not use "never indexed" semantics for sensitive headers. */ // https://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08#section-4.3.3 - void writeHeaders(List<Header> headerBlock) throws IOException { + ByteBufferList writeHeaders(List<Header> headerBlock) throws IOException { + ByteBufferList out = new ByteBufferList(); // TODO: implement index tracking + ByteBuffer current = ByteBufferList.obtain(8192); for (int i = 0, size = headerBlock.size(); i < size; i++) { + if (current.remaining() < current.capacity() / 2) { + current.flip(); + out.add(current); + current = ByteBufferList.obtain(current.capacity() * 2); + } ByteString name = headerBlock.get(i).name.toAsciiLowercase(); Integer staticIndex = NAME_TO_FIRST_INDEX.get(name); if (staticIndex != null) { // Literal Header Field without Indexing - Indexed Name. - writeInt(staticIndex + 1, PREFIX_4_BITS, 0); - writeByteString(headerBlock.get(i).value); + writeInt(current, staticIndex + 1, PREFIX_4_BITS, 0); + writeByteString(current, headerBlock.get(i).value); } else { - out.writeByte(0x00); // Literal Header without Indexing - New Name. - writeByteString(name); - writeByteString(headerBlock.get(i).value); + current.put((byte) 0x00); // Literal Header without Indexing - New Name. + writeByteString(current, name); + writeByteString(current, headerBlock.get(i).value); } } + + out.add(current); + return out; } // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08#section-4.1.1 - void writeInt(int value, int prefixMask, int bits) throws IOException { + void writeInt(ByteBuffer out, int value, int prefixMask, int bits) throws IOException { // Write the raw value for a single byte value. if (value < prefixMask) { - out.writeByte(bits | value); + out.put((byte) (bits | value)); return; } // Write the mask to start a multibyte value. - out.writeByte(bits | prefixMask); + out.put((byte)(bits | prefixMask)); value -= prefixMask; // Write 7 bits at a time 'til we're done. while (value >= 0x80) { int b = value & 0x7f; - out.writeByte(b | 0x80); + out.put((byte) (b | 0x80)); value >>>= 7; } - out.writeByte(value); + out.put((byte) value); } - void writeByteString(ByteString data) throws IOException { - writeInt(data.size(), PREFIX_7_BITS, 0); - out.write(data); + void writeByteString(ByteBuffer out, ByteString data) throws IOException { + writeInt(out, data.size(), PREFIX_7_BITS, 0); + out.put(data.toByteArray()); } } diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Spdy3.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Spdy3.java index f4e7d4e..3db6223 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Spdy3.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Spdy3.java @@ -15,23 +15,19 @@ */ package com.koushikdutta.async.http.spdy.okhttp.internal.spdy; +import com.koushikdutta.async.BufferedDataSink; import com.koushikdutta.async.ByteBufferList; import com.koushikdutta.async.DataEmitter; import com.koushikdutta.async.DataEmitterReader; import com.koushikdutta.async.callback.DataCallback; import com.koushikdutta.async.http.Protocol; -import com.koushikdutta.async.http.spdy.okhttp.internal.Util; -import com.koushikdutta.async.http.spdy.okio.Buffer; -import com.koushikdutta.async.http.spdy.okio.BufferedSink; import com.koushikdutta.async.http.spdy.okio.ByteString; -import com.koushikdutta.async.http.spdy.okio.DeflaterSink; -import com.koushikdutta.async.http.spdy.okio.Okio; import com.koushikdutta.async.util.Charsets; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.io.Writer; import java.net.ProtocolException; +import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.List; import java.util.zip.Deflater; @@ -111,7 +107,7 @@ public final class Spdy3 implements Variant { } @Override - public FrameWriter newWriter(BufferedSink sink, boolean client) { + public FrameWriter newWriter(BufferedDataSink sink, boolean client) { return new Writer(sink, client); } @@ -349,20 +345,17 @@ public final class Spdy3 implements Variant { * Write spdy/3 frames. */ static final class Writer implements FrameWriter { - private final BufferedSink sink; - private final Buffer headerBlockBuffer; - private final BufferedSink headerBlockOut; + private final BufferedDataSink sink; private final boolean client; private boolean closed; + private ByteBufferList frameHeader = new ByteBufferList(); + private final Deflater deflater = new Deflater(); - Writer(BufferedSink sink, boolean client) { + Writer(BufferedDataSink sink, boolean client) { this.sink = sink; this.client = client; - Deflater deflater = new Deflater(); deflater.setDictionary(DICTIONARY); - headerBlockBuffer = new Buffer(); - headerBlockOut = Okio.buffer(new DeflaterSink(headerBlockBuffer, deflater)); } @Override @@ -382,60 +375,58 @@ public final class Spdy3 implements Variant { } @Override - public synchronized void flush() throws IOException { - if (closed) throw new IOException("closed"); - sink.flush(); - } - - @Override public synchronized void synStream(boolean outFinished, boolean inFinished, int streamId, int associatedStreamId, List<Header> headerBlock) throws IOException { if (closed) throw new IOException("closed"); - writeNameValueBlockToBuffer(headerBlock); - int length = (int) (10 + headerBlockBuffer.size()); + ByteBufferList headerBlockBuffer = writeNameValueBlockToBuffer(headerBlock); + int length = (int) (10 + headerBlockBuffer.remaining()); int type = TYPE_SYN_STREAM; int flags = (outFinished ? FLAG_FIN : 0) | (inFinished ? FLAG_UNIDIRECTIONAL : 0); int unused = 0; - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(streamId & 0x7fffffff); - sink.writeInt(associatedStreamId & 0x7fffffff); - sink.writeShort((unused & 0x7) << 13 | (unused & 0x1f) << 8 | (unused & 0xff)); - sink.writeAll(headerBlockBuffer); - sink.flush(); + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(streamId & 0x7fffffff); + sink.putInt(associatedStreamId & 0x7fffffff); + sink.putShort((short) ((unused & 0x7) << 13 | (unused & 0x1f) << 8 | (unused & 0xff))); + sink.flip(); + this.sink.write(frameHeader.add(sink).add(headerBlockBuffer)); } @Override public synchronized void synReply(boolean outFinished, int streamId, List<Header> headerBlock) throws IOException { if (closed) throw new IOException("closed"); - writeNameValueBlockToBuffer(headerBlock); + ByteBufferList headerBlockBuffer = writeNameValueBlockToBuffer(headerBlock); int type = TYPE_SYN_REPLY; int flags = (outFinished ? FLAG_FIN : 0); - int length = (int) (headerBlockBuffer.size() + 4); - - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(streamId & 0x7fffffff); - sink.writeAll(headerBlockBuffer); - sink.flush(); + int length = (int) (headerBlockBuffer.remaining() + 4); + + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(streamId & 0x7fffffff); + sink.flip(); + this.sink.write(frameHeader.add(sink).add(headerBlockBuffer)); } @Override public synchronized void headers(int streamId, List<Header> headerBlock) throws IOException { if (closed) throw new IOException("closed"); - writeNameValueBlockToBuffer(headerBlock); + ByteBufferList headerBlockBuffer = writeNameValueBlockToBuffer(headerBlock); int flags = 0; int type = TYPE_HEADERS; - int length = (int) (headerBlockBuffer.size() + 4); - - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(streamId & 0x7fffffff); - sink.writeAll(headerBlockBuffer); + int length = (int) (headerBlockBuffer.remaining() + 4); + + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(streamId & 0x7fffffff); + sink.flip(); + this.sink.write(frameHeader.add(sink).add(headerBlockBuffer)); } @Override @@ -446,51 +437,69 @@ public final class Spdy3 implements Variant { int flags = 0; int type = TYPE_RST_STREAM; int length = 8; - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(streamId & 0x7fffffff); - sink.writeInt(errorCode.spdyRstCode); - sink.flush(); + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(streamId & 0x7fffffff); + sink.putInt(errorCode.spdyRstCode); + sink.flip(); + this.sink.write(frameHeader.addAll(sink)); } @Override - public synchronized void data(boolean outFinished, int streamId, Buffer source) - throws IOException { - data(outFinished, streamId, source, (int) source.size()); - } - - @Override - public synchronized void data(boolean outFinished, int streamId, Buffer source, - int byteCount) throws IOException { + public synchronized void data(boolean outFinished, int streamId, ByteBufferList source) throws IOException { int flags = (outFinished ? FLAG_FIN : 0); - sendDataFrame(streamId, flags, source, byteCount); + sendDataFrame(streamId, flags, source); } - void sendDataFrame(int streamId, int flags, Buffer buffer, int byteCount) + ByteBufferList dataList = new ByteBufferList(); + void sendDataFrame(int streamId, int flags, ByteBufferList buffer) throws IOException { if (closed) throw new IOException("closed"); + int byteCount = buffer.remaining(); if (byteCount > 0xffffffL) { throw new IllegalArgumentException("FRAME_TOO_LARGE max size is 16Mib: " + byteCount); } - sink.writeInt(streamId & 0x7fffffff); - sink.writeInt((flags & 0xff) << 24 | byteCount & 0xffffff); - if (byteCount > 0) { - sink.write(buffer, byteCount); - } + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(streamId & 0x7fffffff); + sink.putInt((flags & 0xff) << 24 | byteCount & 0xffffff); + sink.flip(); + dataList.add(sink).add(buffer); + this.sink.write(dataList); } - private void writeNameValueBlockToBuffer(List<Header> headerBlock) throws IOException { - if (headerBlockBuffer.size() != 0) throw new IllegalStateException(); - headerBlockOut.writeInt(headerBlock.size()); + ByteBufferList headerBlockList = new ByteBufferList(); + private ByteBufferList writeNameValueBlockToBuffer(List<Header> headerBlock) throws IOException { + if (headerBlockList.hasRemaining()) throw new IllegalStateException(); + ByteBuffer headerBlockOut = ByteBufferList.obtain(8192).order(ByteOrder.BIG_ENDIAN); + headerBlockOut.putInt(headerBlock.size()); for (int i = 0, size = headerBlock.size(); i < size; i++) { ByteString name = headerBlock.get(i).name; - headerBlockOut.writeInt(name.size()); - headerBlockOut.write(name); + headerBlockOut.putInt(name.size()); + headerBlockOut.put(name.toByteArray()); ByteString value = headerBlock.get(i).value; - headerBlockOut.writeInt(value.size()); - headerBlockOut.write(value); + headerBlockOut.putInt(value.size()); + headerBlockOut.put(value.toByteArray()); + if (headerBlockOut.remaining() < headerBlockOut.capacity() / 2) { + ByteBuffer newOut = ByteBufferList.obtain(headerBlockOut.capacity() * 2).order(ByteOrder.BIG_ENDIAN); + headerBlockOut.flip(); + newOut.put(headerBlockOut); + ByteBufferList.reclaim(headerBlockOut); + headerBlockOut = newOut; + } } - headerBlockOut.flush(); + + headerBlockOut.flip(); + deflater.setInput(headerBlockOut.array(), 0, headerBlockOut.remaining()); + while (!deflater.needsInput()) { + ByteBuffer deflated = ByteBufferList.obtain(headerBlockOut.capacity()).order(ByteOrder.BIG_ENDIAN); + int read = deflater.deflate(deflated.array(), 0, deflated.capacity(), Deflater.SYNC_FLUSH); + deflated.limit(read); + headerBlockList.add(deflated); + } + ByteBufferList.reclaim(headerBlockOut); + + return headerBlockList; } @Override @@ -500,16 +509,18 @@ public final class Spdy3 implements Variant { int flags = 0; int size = settings.size(); int length = 4 + size * 8; - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(size); + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(size); for (int i = 0; i <= Settings.COUNT; i++) { if (!settings.isSet(i)) continue; int settingsFlags = settings.flags(i); - sink.writeInt((settingsFlags & 0xff) << 24 | (i & 0xffffff)); - sink.writeInt(settings.get(i)); + sink.putInt((settingsFlags & 0xff) << 24 | (i & 0xffffff)); + sink.putInt(settings.get(i)); } - sink.flush(); + sink.flip(); + this.sink.write(frameHeader.addAll(sink)); } @Override @@ -521,10 +532,12 @@ public final class Spdy3 implements Variant { int type = TYPE_PING; int flags = 0; int length = 4; - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(payload1); - sink.flush(); + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(payload1); + sink.flip(); + this.sink.write(frameHeader.addAll(sink)); } @Override @@ -537,11 +550,13 @@ public final class Spdy3 implements Variant { int type = TYPE_GOAWAY; int flags = 0; int length = 8; - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(lastGoodStreamId); - sink.writeInt(errorCode.spdyGoAwayCode); - sink.flush(); + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(lastGoodStreamId); + sink.putInt(errorCode.spdyGoAwayCode); + sink.flip(); + this.sink.write(frameHeader.addAll(sink)); } @Override @@ -555,17 +570,18 @@ public final class Spdy3 implements Variant { int type = TYPE_WINDOW_UPDATE; int flags = 0; int length = 8; - sink.writeInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); - sink.writeInt((flags & 0xff) << 24 | length & 0xffffff); - sink.writeInt(streamId); - sink.writeInt((int) increment); - sink.flush(); + ByteBuffer sink = ByteBufferList.obtain(256).order(ByteOrder.BIG_ENDIAN); + sink.putInt(0x80000000 | (VERSION & 0x7fff) << 16 | type & 0xffff); + sink.putInt((flags & 0xff) << 24 | length & 0xffffff); + sink.putInt(streamId); + sink.putInt((int) increment); + sink.flip(); + this.sink.write(frameHeader.addAll(sink)); } @Override public synchronized void close() throws IOException { closed = true; - Util.closeAll(sink, headerBlockOut); } } } diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Variant.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Variant.java index eeb7c15..00b12ff 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Variant.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okhttp/internal/spdy/Variant.java @@ -16,9 +16,9 @@ package com.koushikdutta.async.http.spdy.okhttp.internal.spdy; +import com.koushikdutta.async.BufferedDataSink; import com.koushikdutta.async.DataEmitter; import com.koushikdutta.async.http.Protocol; -import com.koushikdutta.async.http.spdy.okio.BufferedSink; /** A version and dialect of the framed socket protocol. */ public interface Variant { @@ -34,7 +34,7 @@ public interface Variant { /** * @param client true if this is the HTTP client's writer, writing frames to a server. */ - FrameWriter newWriter(BufferedSink sink, boolean client); + FrameWriter newWriter(BufferedDataSink sink, boolean client); int maxFrameSize(); } |