Fix send() return value handling.

A value of 0 doesn't indicate a closed connection as for recv().
This commit is contained in:
Sönke Ludwig 2017-07-19 10:42:33 +02:00
parent 9518ec4dce
commit 1c666a0191
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C

View file

@ -350,21 +350,16 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
on_write_finish(socket, IOStatus.error, 0); on_write_finish(socket, IOStatus.error, 0);
return; return;
} }
if (mode == IOMode.immediate) {
on_write_finish(socket, IOStatus.wouldBlock, 0);
return;
}
} }
size_t bytes_written = 0; size_t bytes_written = 0;
if (ret == 0) { if (ret >= 0) {
on_write_finish(socket, IOStatus.disconnected, 0);
return;
}
if (ret < 0 && mode == IOMode.immediate) {
on_write_finish(socket, IOStatus.wouldBlock, 0);
return;
}
if (ret > 0) {
bytes_written += ret; bytes_written += ret;
buffer = buffer[ret .. $]; buffer = buffer[ret .. $];
if (mode != IOMode.all || buffer.length == 0) { if (mode != IOMode.all || buffer.length == 0) {
@ -380,7 +375,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
with (m_loop.m_fds[socket].streamSocket) { with (m_loop.m_fds[socket].streamSocket) {
writeCallback = on_write_finish; writeCallback = on_write_finish;
writeMode = mode; writeMode = mode;
bytesWritten = ret > 0 ? ret : 0; bytesWritten = ret >= 0 ? ret : 0;
writeBuffer = buffer; writeBuffer = buffer;
} }
@ -411,13 +406,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
} }
} }
if (ret == 0) { if (ret >= 0) {
m_loop.setNotifyCallback!(EventType.write)(socket, null);
slot.writeCallback(cast(StreamSocketFD)socket, IOStatus.disconnected, slot.bytesWritten);
return;
}
if (ret > 0) {
slot.bytesWritten += ret; slot.bytesWritten += ret;
slot.writeBuffer = slot.writeBuffer[ret .. $]; slot.writeBuffer = slot.writeBuffer[ret .. $];
if (slot.writeMode != IOMode.all || slot.writeBuffer.length == 0) { if (slot.writeMode != IOMode.all || slot.writeBuffer.length == 0) {