Skip to content

Commit

Permalink
Atmosphere#136 - Add null checks for NettyWebSocket#channel.
Browse files Browse the repository at this point in the history
Revert "Atmosphere#136 - Remove setting channel to null in NettyWebSocket#recycle()."

This reverts commit 73c8792.
  • Loading branch information
YaroslavSaakyan committed Dec 25, 2018
1 parent 73c8792 commit ba5f34e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public WebSocket resource(AtmosphereResource r) {
@Override
public WebSocket write(String data) throws IOException {
firstWrite.set(true);
if (!channel.isOpen()) throw REMOTELY_CLOSED;
if (channel == null || !channel.isOpen()) throw REMOTELY_CLOSED;

if (binaryWrite) {
channel.write(new BinaryWebSocketFrame(ChannelBuffers.wrappedBuffer(data.getBytes("UTF-8"))));
Expand Down Expand Up @@ -111,7 +111,7 @@ public WebSocket write(byte[] data, int offset, int length) throws IOException {
void _write(byte[] data, int offset, int length) throws IOException {
firstWrite.set(true);

if (!channel.isOpen()) throw REMOTELY_CLOSED;
if (channel == null || !channel.isOpen()) throw REMOTELY_CLOSED;

if (binaryWrite) {
channel.write(new BinaryWebSocketFrame(ChannelBuffers.wrappedBuffer(data, offset, length)));
Expand All @@ -123,6 +123,9 @@ void _write(byte[] data, int offset, int length) throws IOException {

@Override
public boolean isOpen() {
if (channel == null) {
return false;
}
return channel.isOpen();
}

Expand All @@ -146,6 +149,7 @@ public void close() {

public void recycle() {
if (headers != null) headers.clear();
channel = null;
}

/**
Expand Down

0 comments on commit ba5f34e

Please sign in to comment.