summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-01-30 13:52:58 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-01-30 13:52:58 (GMT)
commitf58b90fb022b744619f4a7af445bac8a561bde7a (patch)
tree38cb1824e11c8346597a8004c9edf05c4805e4c4
parentee66478056af217424f2052723fbd89ee0d0f933 (diff)
downloadtcl-f58b90fb022b744619f4a7af445bac8a561bde7a.zip
tcl-f58b90fb022b744619f4a7af445bac8a561bde7a.tar.gz
tcl-f58b90fb022b744619f4a7af445bac8a561bde7a.tar.bz2
Reset WSAGetLastError()/errno always, even when this error is not reported due to the earlier error.
-rw-r--r--unix/tclUnixSock.c11
-rw-r--r--win/tclWinSock.c11
2 files changed, 12 insertions, 10 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index ba36d7b..a00559a 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -658,7 +658,8 @@ TcpClose2Proc(
int flags) /* Flags that indicate which side to close. */
{
TcpState *statePtr = instanceData;
- int errorCode = 0;
+ int readError = 0;
+ int writeError = 0;
/*
* Shutdown the OS socket handle.
@@ -667,12 +668,12 @@ TcpClose2Proc(
return TcpCloseProc(instanceData, interp);
}
if ((flags & TCL_CLOSE_READ) && (shutdown(statePtr->fds.fd, SHUT_RD) < 0)) {
- errorCode = errno;
+ readError = errno;
}
- if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->fds.fd, SHUT_WR) < 0) && (errorCode != 0)) {
- errorCode = errno;
+ if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->fds.fd, SHUT_WR) < 0)) {
+ writeError = errno;
}
- return errorCode;
+ return (readError != 0) ? readError : writeError;
}
/*
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index 565b525..e52e509 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -1068,7 +1068,8 @@ TcpClose2Proc(
int flags) /* Flags that indicate which side to close. */
{
TcpState *statePtr = instanceData;
- int errorCode = 0;
+ int readError = 0;
+ int writeError = 0;
/*
* Shutdown the OS socket handle.
@@ -1082,13 +1083,13 @@ TcpClose2Proc(
* TCL_WRITABLE so this should never be called for a server socket. */
if ((flags & TCL_CLOSE_READ) && (shutdown(statePtr->sockets->fd, SD_RECEIVE) == SOCKET_ERROR)) {
TclWinConvertError((DWORD) WSAGetLastError());
- errorCode = Tcl_GetErrno();
+ readError = Tcl_GetErrno();
}
- if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->sockets->fd, SD_SEND) == SOCKET_ERROR) && (errorCode != 0)) {
+ if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->sockets->fd, SD_SEND) == SOCKET_ERROR)) {
TclWinConvertError((DWORD) WSAGetLastError());
- errorCode = Tcl_GetErrno();
+ writeError = Tcl_GetErrno();
}
- return errorCode;
+ return (readError != 0) ? readError : writeError;
}
/*