summaryrefslogtreecommitdiffstats
path: root/win/tclWinSock.c
diff options
context:
space:
mode:
authorferrieux <ferrieux@users.sourceforge.net>2008-12-18 01:14:16 (GMT)
committerferrieux <ferrieux@users.sourceforge.net>2008-12-18 01:14:16 (GMT)
commita189e6bf469919f77d6e9884d112c93599363de5 (patch)
tree087ebe5ba2e9e57828831c8ad3ba41d50edb7eb4 /win/tclWinSock.c
parentcd0108cccb852eff4a8a65fa1e68297e85bc12ec (diff)
downloadtcl-a189e6bf469919f77d6e9884d112c93599363de5.zip
tcl-a189e6bf469919f77d6e9884d112c93599363de5.tar.gz
tcl-a189e6bf469919f77d6e9884d112c93599363de5.tar.bz2
TIP #332 IMPLEMENTATION - Half-Close for Bidirectional Channels
Diffstat (limited to 'win/tclWinSock.c')
-rw-r--r--win/tclWinSock.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index df04b8e..9f5b9bc 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinSock.c,v 1.63 2008/10/26 18:43:27 dkf Exp $
+ * RCS: @(#) $Id: tclWinSock.c,v 1.64 2008/12/18 01:14:17 ferrieux Exp $
*/
#include "tclWinInt.h"
@@ -168,6 +168,7 @@ static Tcl_EventProc SocketEventProc;
static Tcl_EventSetupProc SocketSetupProc;
static Tcl_DriverBlockModeProc TcpBlockProc;
static Tcl_DriverCloseProc TcpCloseProc;
+static Tcl_DriverClose2Proc TcpClose2Proc;
static Tcl_DriverSetOptionProc TcpSetOptionProc;
static Tcl_DriverGetOptionProc TcpGetOptionProc;
static Tcl_DriverInputProc TcpInputProc;
@@ -191,7 +192,7 @@ static Tcl_ChannelType tcpChannelType = {
TcpGetOptionProc, /* Get option proc. */
TcpWatchProc, /* Set up notifier to watch this channel. */
TcpGetHandleProc, /* Get an OS handle from channel. */
- NULL, /* close2proc. */
+ TcpClose2Proc, /* Close2proc. */
TcpBlockProc, /* Set socket into (non-)blocking mode. */
NULL, /* flush proc. */
NULL, /* handler proc. */
@@ -818,6 +819,58 @@ TcpCloseProc(
/*
*----------------------------------------------------------------------
*
+ * TcpClose2Proc --
+ *
+ * This function is called by the generic IO level to perform the channel
+ * type specific part of a half-close: namely, a shutdown() on a socket.
+ *
+ * Results:
+ * 0 if successful, the value of errno if failed.
+ *
+ * Side effects:
+ * Shuts down one side of the socket.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+TcpClose2Proc(
+ ClientData instanceData, /* The socket to close. */
+ Tcl_Interp *interp, /* For error reporting. */
+ int flags) /* Flags that indicate which side to close. */
+{
+ SocketInfo *infoPtr = (SocketInfo *) 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_AppendResult(interp, "Socket close2proc called bidirectionally", NULL);
+ }
+ return TCL_ERROR;
+ }
+ if (shutdown(infoPtr->socket,sd) == SOCKET_ERROR) {
+ TclWinConvertWSAError((DWORD) WSAGetLastError());
+ errorCode = Tcl_GetErrno();
+ }
+
+ return errorCode;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* NewSocketInfo --
*
* This function allocates and initializes a new SocketInfo structure.