summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--unix/tclUnixSock.c23
-rw-r--r--win/tclWinSock.c23
2 files changed, 13 insertions, 33 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 90c72c0..ba36d7b 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -659,30 +659,19 @@ TcpClose2Proc(
{
TcpState *statePtr = instanceData;
int errorCode = 0;
- int sd;
/*
* Shutdown the OS socket handle.
*/
-
- switch(flags) {
- case TCL_CLOSE_READ:
- sd = SHUT_RD;
- break;
- case TCL_CLOSE_WRITE:
- sd = SHUT_WR;
- break;
- default:
- if (interp) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "socket close2proc called bidirectionally", -1));
- }
- return TCL_ERROR;
+ if ((flags & (TCL_CLOSE_READ|TCL_CLOSE_WRITE)) == 0) {
+ return TcpCloseProc(instanceData, interp);
}
- if (shutdown(statePtr->fds.fd,sd) < 0) {
+ if ((flags & TCL_CLOSE_READ) && (shutdown(statePtr->fds.fd, SHUT_RD) < 0)) {
+ errorCode = errno;
+ }
+ if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->fds.fd, SHUT_WR) < 0) && (errorCode != 0)) {
errorCode = errno;
}
-
return errorCode;
}
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index a397a30..565b525 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -1069,34 +1069,25 @@ TcpClose2Proc(
{
TcpState *statePtr = instanceData;
int errorCode = 0;
- int sd;
/*
* Shutdown the OS socket handle.
*/
- switch(flags) {
- case TCL_CLOSE_READ:
- sd = SD_RECEIVE;
- break;
- case TCL_CLOSE_WRITE:
- sd = SD_SEND;
- break;
- default:
- if (interp) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "socket close2proc called bidirectionally", -1));
- }
- return TCL_ERROR;
+ if ((flags & (TCL_CLOSE_READ|TCL_CLOSE_WRITE)) == 0) {
+ return TcpCloseProc(instanceData, interp);
}
/* single fd operation: Tcl_OpenTcpServer() does not set TCL_READABLE or
* TCL_WRITABLE so this should never be called for a server socket. */
- if (shutdown(statePtr->sockets->fd, sd) == SOCKET_ERROR) {
+ if ((flags & TCL_CLOSE_READ) && (shutdown(statePtr->sockets->fd, SD_RECEIVE) == SOCKET_ERROR)) {
+ TclWinConvertError((DWORD) WSAGetLastError());
+ errorCode = Tcl_GetErrno();
+ }
+ if ((flags & TCL_CLOSE_WRITE) && (shutdown(statePtr->sockets->fd, SD_SEND) == SOCKET_ERROR) && (errorCode != 0)) {
TclWinConvertError((DWORD) WSAGetLastError());
errorCode = Tcl_GetErrno();
}
-
return errorCode;
}