Skip to content

Commit

Permalink
Fix some Autobahn websocket issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Aug 13, 2015
1 parent 58465d8 commit c2d6636
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Expand Up @@ -296,6 +296,10 @@ public synchronized R receive() throws IOException {
//we have received the last frame, we just shut down and return
//it would probably make more sense to have the last channel responsible for this
//however it is much simpler just to have it here
if(readData != null) {
readData.free();
readData = null;
}
channel.getSourceChannel().suspendReads();
channel.getSourceChannel().shutdownReads();
return null;
Expand Down Expand Up @@ -899,6 +903,9 @@ public void run() {
while (readData != null && !readData.isFreed()) {
int rem = readData.getResource().remaining();
ChannelListeners.invokeChannelListener(AbstractFramedChannel.this, (ChannelListener) receiveSetter.get());
if(!AbstractFramedChannel.this.isOpen()) {
break;
}
if (readData != null && rem == readData.getResource().remaining()) {
break;//make sure we are making progress
}
Expand Down
Expand Up @@ -166,8 +166,9 @@ public int read(ByteBuffer dst) throws IOException {
extensionResult = applyExtensions(dst, position, r);
}
if (r > 0) {
boolean complete = isComplete() && extensionResult == null;
checker(dst, position, dst.position() - position, complete);
checker(dst, position, dst.position() - position, false);
} else if(r == -1) {
checkComplete();
}
return r;
} else {
Expand Down Expand Up @@ -202,10 +203,23 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
int oldPos = old[i - offset].position;
afterRead(dst, oldPos, dst.position() - oldPos);
}
} else if(b == -1){
checkComplete();
}
return b;
}

private void checkComplete() throws IOException {
try {
for (ChannelFunction func : functions) {
func.complete();
}
} catch (UnsupportedEncodingException e) {
getFramedChannel().markReadsBroken(e);
throw e;
}
}

/**
* Called after data was read into the {@link ByteBuffer}
*
Expand All @@ -220,14 +234,7 @@ protected void afterRead(ByteBuffer buffer, int position, int length) throws IOE
func.afterRead(buffer, position, length);
}
if (isComplete()) {
try {
for (ChannelFunction func : functions) {
func.complete();
}
} catch (UnsupportedEncodingException e) {
getFramedChannel().markReadsBroken(e);
throw e;
}
checkComplete();
}
} catch (UnsupportedEncodingException e) {
getFramedChannel().markReadsBroken(e);
Expand Down
Expand Up @@ -64,7 +64,7 @@ public void afterRead(ByteBuffer buf, int position, int length) throws IOExcepti
if(statusBytesRead == 2) {
// Must have 2 byte integer within the valid range
if (status >= 0 && status <= 999 || status >= 1004 && status <= 1006
|| status >= 1012 && status <= 2999) {
|| status >= 1012 && status <= 2999 || status >= 5000) {
IOException exception = WebSocketMessages.MESSAGES.invalidCloseFrameStatusCode(status);
wsChannel.markReadsBroken(exception);
throw exception;
Expand Down

0 comments on commit c2d6636

Please sign in to comment.