System call needs to be made at least once so that it can fail when a user attempts to write on a closed channel
This commit is contained in:
parent
752e60a723
commit
de90cd6a3c
@ -530,20 +530,26 @@ class NioDatagramWorker implements Runnable {
|
||||
long localWrittenBytes = 0;
|
||||
SocketAddress raddr = evt.getRemoteAddress();
|
||||
if (raddr == null) {
|
||||
for (int i = writeSpinCount; i > 0 && !buf.finished(); i --) {
|
||||
for (int i = writeSpinCount; i > 0; i --) {
|
||||
localWrittenBytes = buf.transferTo(ch);
|
||||
if (localWrittenBytes != 0) {
|
||||
writtenBytes += localWrittenBytes;
|
||||
break;
|
||||
}
|
||||
if (buf.finished()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = writeSpinCount; i > 0 && !buf.finished(); i --) {
|
||||
for (int i = writeSpinCount; i > 0; i --) {
|
||||
localWrittenBytes = buf.transferTo(ch, raddr);
|
||||
if (localWrittenBytes != 0) {
|
||||
writtenBytes += localWrittenBytes;
|
||||
break;
|
||||
}
|
||||
if (buf.finished()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,12 +465,15 @@ class NioWorker implements Runnable {
|
||||
ChannelFuture future = evt.getFuture();
|
||||
try {
|
||||
long localWrittenBytes = 0;
|
||||
for (int i = writeSpinCount; i > 0 && !buf.finished(); i --) {
|
||||
for (int i = writeSpinCount; i > 0; i --) {
|
||||
localWrittenBytes = buf.transferTo(ch);
|
||||
if (localWrittenBytes != 0) {
|
||||
writtenBytes += localWrittenBytes;
|
||||
break;
|
||||
}
|
||||
if (buf.finished()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buf.finished()) {
|
||||
|
@ -101,7 +101,6 @@ class OioDatagramWorker implements Runnable {
|
||||
try {
|
||||
ChannelBuffer buf = (ChannelBuffer) message;
|
||||
int length = buf.readableBytes();
|
||||
if (length > 0) {
|
||||
ByteBuffer nioBuf = buf.toByteBuffer();
|
||||
DatagramPacket packet;
|
||||
if (nioBuf.hasArray()) {
|
||||
@ -120,7 +119,6 @@ class OioDatagramWorker implements Runnable {
|
||||
}
|
||||
channel.socket.send(packet);
|
||||
fireWriteComplete(channel, length);
|
||||
}
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
future.setFailure(t);
|
||||
|
@ -115,12 +115,10 @@ class OioWorker implements Runnable {
|
||||
try {
|
||||
ChannelBuffer a = (ChannelBuffer) message;
|
||||
int length = a.readableBytes();
|
||||
if (length > 0) {
|
||||
synchronized (out) {
|
||||
a.getBytes(a.readerIndex(), out, length);
|
||||
}
|
||||
fireWriteComplete(channel, length);
|
||||
}
|
||||
future.setSuccess();
|
||||
} catch (Throwable t) {
|
||||
// Convert 'SocketException: Socket closed' to
|
||||
|
Loading…
Reference in New Issue
Block a user