[#4170] Shutdown socket before close fd when using epoll transport
Motivation: We should call shutdown(...) on the socket before closing the filedescriptor to ensure it is closed gracefully. Modifications: Call shutdown(...) before close. Result: Sockets are gracefully shutdown when using native transport.
This commit is contained in:
parent
3de8768601
commit
3e4cc9d23f
@ -101,17 +101,29 @@ abstract class AbstractEpollChannel extends AbstractChannel implements UnixChann
|
||||
|
||||
@Override
|
||||
protected void doClose() throws Exception {
|
||||
active = false;
|
||||
boolean active = this.active;
|
||||
this.active = false;
|
||||
FileDescriptor fd = fileDescriptor;
|
||||
try {
|
||||
// deregister from epoll now
|
||||
// deregister from epoll now and shutdown the socket.
|
||||
doDeregister();
|
||||
if (active) {
|
||||
shutdown(fd.intValue());
|
||||
}
|
||||
} finally {
|
||||
// Ensure the file descriptor is closed in all cases.
|
||||
FileDescriptor fd = fileDescriptor;
|
||||
fd.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on {@link #doClose()} before the actual {@link FileDescriptor} is closed.
|
||||
* This implementation does nothing.
|
||||
*/
|
||||
protected void shutdown(int fd) throws IOException {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() throws Exception {
|
||||
doClose();
|
||||
|
@ -94,6 +94,11 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel {
|
||||
flags |= Native.EPOLLRDHUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(int fd) throws IOException {
|
||||
Native.shutdown(fd, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractEpollUnsafe newUnsafe() {
|
||||
return new EpollStreamUnsafe();
|
||||
|
Loading…
Reference in New Issue
Block a user