Skip to content

Commit

Permalink
Improved for socket closing
Browse files Browse the repository at this point in the history
  • Loading branch information
Heromyth committed Feb 18, 2022
1 parent 1482cd6 commit af40c57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion source/hunt/io/TcpStream.d
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ protected:
warningf("Some data has not been sent yet: fd=%d", this.handle);
}
}
version(HUNT_DEBUG) {
version(HUNT_NET_DEBUG) {
infof("Closing a connection with: %s, fd=%d", this.remoteAddress, this.handle);
}

Expand Down
9 changes: 5 additions & 4 deletions source/hunt/io/channel/AbstractChannel.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,18 @@ abstract class AbstractChannel : Channel {
version (HUNT_IO_DEBUG)
tracef("onClose [fd=%d]...", this.handle);
_isRegistered = false;
_inLoop.deregister(this);
_isClosed = true;
clear();

_inLoop.deregister(this);
version (HUNT_IO_DEBUG_MORE)
tracef("onClose done [fd=%d]...", this.handle);

_isClosed = true;
}

protected void errorOccurred(ErrorCode code, string msg) {
debug warningf("isRegistered: %s, isClosed: %s, msg=%s", _isRegistered, _isClosed, msg);
debug warningf("isRegistered: %s, _isClosing: %s, isClosed: %s, code: %s, msg=%s",
_isRegistered, _isClosing, _isClosed, code, msg);

if (errorHandler !is null) {
errorHandler(new IoError(code, msg));
}
Expand Down
9 changes: 8 additions & 1 deletion source/hunt/io/channel/posix/AbstractStream.d
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ abstract class AbstractStream : AbstractSocketChannel {
if (_error) {
this._errorMessage = getErrorMessage(errno);

version(HUNT_NET_DEBUG) {
warningf("Error occurred on read, code: %d, msg: %s, isClosing: %s, isClosed: %s",
errno, _errorMessage, isClosing(), isClosed());
}

if(errno == ECONNRESET) {
// https://stackoverflow.com/questions/1434451/what-does-connection-reset-by-peer-mean
onDisconnected();
errorOccurred(ErrorCode.CONNECTIONEESET , "connection reset by peer");
} else {
errorOccurred(ErrorCode.INTERRUPTED , "Error occurred on read");
if(!isClosed()) {
errorOccurred(ErrorCode.INTERRUPTED , format("Error occurred on read, code: %d", errno));
}
}
} else {
debug warningf("warning on read: fd=%d, errno=%d, message=%s", this.handle,
Expand Down

0 comments on commit af40c57

Please sign in to comment.