Skip to content
This repository has been archived by the owner on Feb 14, 2018. It is now read-only.

Commit

Permalink
Increasing version to 0.2-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
cgordon committed Jun 10, 2015
1 parent c4a0ce9 commit cd7dac3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -8,7 +8,7 @@ targetCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

group = "com.pinterest"
version = "0.1-SNAPSHOT"
version = "0.2-SNAPSHOT"
status = "integration"
description = "Thrift integration with the Quasar libraries"
ext.url = "https://github.com/pinterest/quasar-thrift"
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/pinterest/quasar/thrift/TFramedFiberSocket.java
Expand Up @@ -79,20 +79,29 @@ private void readFrame() throws TTransportException {
try {
header.clear();
while (header.position() < header.capacity()) {
socketChannel.read(header);
LOG.info("reading header bytes");
long bytesRead = socketChannel.read(header);
if (bytesRead == -1) {
throw new TTransportException(TTransportException.END_OF_FILE);
}
}

header.flip();
int len = header.getInt();

if (buffer.capacity() < len) {
LOG.info("allocating a new buffer of size {}", len);
buffer = ByteBuffer.allocate(len);
} else {
buffer.clear();
}

while (buffer.position() < len) {
socketChannel.read(buffer, timeout, timeoutUnit);
LOG.info("reading body bytes with timeout");
long bytesRead = socketChannel.read(buffer, timeout, timeoutUnit);
if (bytesRead == -1) {
throw new TTransportException(TTransportException.END_OF_FILE);
}
}

buffer.flip();
Expand All @@ -111,6 +120,7 @@ public int read(byte[] bytes, int offset, int limit) throws TTransportException
state = STATE_READ;
}

LOG.info("Returning bytes from buffer");
buffer.get(bytes, offset, limit);
return limit;
}
Expand All @@ -131,6 +141,7 @@ public void write(byte[] bytes, int offset, int limit) throws TTransportExceptio
buffer = newBuffer;
}

LOG.info("writing bytes into buffer");
buffer.put(bytes, offset, limit);
}

Expand All @@ -143,6 +154,7 @@ public void flush() throws TTransportException {
header.putInt(buffer.remaining()).flip();
ByteBuffer[] buffers = {header, buffer};
while (buffer.hasRemaining()) {
LOG.info("writing out header and body bytes");
long bytesWritten = socketChannel.write(buffers);
if (bytesWritten == 0) {
throw new TTransportException(TTransportException.END_OF_FILE);
Expand Down

0 comments on commit cd7dac3

Please sign in to comment.