Skip to content

Commit

Permalink
Consider a channel sealed when the first send is queued, not when the…
Browse files Browse the repository at this point in the history
… headers are sent.
  • Loading branch information
tobias committed Apr 7, 2015
1 parent eafab77 commit 9069579
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Expand Up @@ -17,5 +17,5 @@
package org.projectodd.wunderboss.web.async;

public interface HttpChannel extends Channel {
boolean headersSent();
boolean sendStarted();
}
Expand Up @@ -73,19 +73,21 @@ public boolean isOpen() {
}

@Override
public boolean headersSent() {
return this.sendStarted;
public boolean sendStarted() {
return this.sendQueued;
}

// message must be String or byte[]. Allowing Object makes life easier from clojure
@Override
public boolean send(final Object message,
final boolean shouldClose,
final OnComplete onComplete) throws IOException {
public synchronized boolean send(final Object message,
final boolean shouldClose,
final OnComplete onComplete) throws IOException {
if (!isOpen()) {
return false;
}

this.sendQueued = true;

byte[] data;
if (message == null) {
data = null;
Expand Down Expand Up @@ -148,13 +150,13 @@ protected void doSend(final byte[] data,
final OnComplete onComplete) {
Throwable ex = null;
try {
if (!sendStarted) {
if (!headersSent) {
if (shouldClose &&
data != null) {
setContentLength(data.length);
}
this.stream = getOutputStream();
sendStarted = true;
headersSent = true;
}

if (data != null) {
Expand Down Expand Up @@ -205,7 +207,8 @@ public void run() {
};

private boolean open = false;
private boolean sendStarted = false;
private boolean sendQueued = false;
private boolean headersSent = false;
private OutputStream stream;
private final OnOpen onOpen;
private final OnError onError;
Expand Down

0 comments on commit 9069579

Please sign in to comment.