summaryrefslogtreecommitdiffstats
path: root/win/tclWinSock.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-01-04 12:55:27 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-01-04 12:55:27 (GMT)
commit1aef6cddbf5ff7fe047f3a0a1a0e5e9ab45c6a86 (patch)
tree821da9f44bd3dcf3d64624eb0a1cec59b7015104 /win/tclWinSock.c
parent2d45ce8f574a9204a0462d5e27867fda53f09f05 (diff)
parent7628e8f3871e65f729e55364626f5684b172bddc (diff)
downloadtcl-1aef6cddbf5ff7fe047f3a0a1a0e5e9ab45c6a86.zip
tcl-1aef6cddbf5ff7fe047f3a0a1a0e5e9ab45c6a86.tar.gz
tcl-1aef6cddbf5ff7fe047f3a0a1a0e5e9ab45c6a86.tar.bz2
TIP [http://www.tcl.tk/cgi-bin/tct/tip/456|456] implementation: Extend the C API to Support Passing Options to TCP Server Creationtip_456
Diffstat (limited to 'win/tclWinSock.c')
-rw-r--r--win/tclWinSock.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index ec881d2..5e0d7c8 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -2020,7 +2020,7 @@ Tcl_MakeTcpClientChannel(
/*
*----------------------------------------------------------------------
*
- * Tcl_OpenTcpServer --
+ * Tcl_OpenTcpServerEx --
*
* Opens a TCP server socket and creates a channel around it.
*
@@ -2035,10 +2035,11 @@ Tcl_MakeTcpClientChannel(
*/
Tcl_Channel
-Tcl_OpenTcpServer(
+Tcl_OpenTcpServerEx(
Tcl_Interp *interp, /* For error reporting - may be NULL. */
- int port, /* Port number to open. */
+ const char *service, /* Port number to open. */
const char *myHost, /* Name of local host. */
+ unsigned int flags, /* Flags. */
Tcl_TcpAcceptProc *acceptProc,
/* Callback for accepting connections from new
* clients. */
@@ -2052,6 +2053,7 @@ Tcl_OpenTcpServer(
char channelName[SOCK_CHAN_LENGTH];
u_long flag = 1; /* Indicates nonblocking mode. */
const char *errorMsg = NULL;
+ int optvalue, port;
if (TclpHasSockets(interp) != TCL_OK) {
return NULL;
@@ -2071,6 +2073,11 @@ Tcl_OpenTcpServer(
* Construct the addresses for each end of the socket.
*/
+ if (TclSockGetPort(interp, service, "tcp", &port) != TCL_OK) {
+ errorMsg = "invalid port number";
+ goto error;
+ }
+
if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) {
goto error;
}
@@ -2110,9 +2117,17 @@ Tcl_OpenTcpServer(
}
/*
- * Bind to the specified port. Note that we must not call
- * setsockopt with SO_REUSEADDR because Microsoft allows addresses
- * to be reused even if they are still in use.
+ * The SO_REUSEADDR option on Windows behaves like SO_REUSEPORT on unix
+ * systems.
+ */
+ if (flags & TCL_TCPSERVER_REUSEPORT) {
+ optvalue = 1;
+ (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &optvalue, sizeof(optvalue));
+ }
+
+ /*
+ * Bind to the specified port.
*
* Bind should not be affected by the socket having already been
* set into nonblocking mode. If there is trouble, this is one