summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlimeboy <that.lemon+tcl@gmai.com>2016-12-20 10:56:53 (GMT)
committerlimeboy <that.lemon+tcl@gmai.com>2016-12-20 10:56:53 (GMT)
commitbbe8ae73e2e5c693a20ea16c964949279ff83045 (patch)
tree4e3d83e3e03fc60198caab1518a2c2b5cd3d5bfe
parentd4daeaf6fdc234980b6b7e28b281185896c2dd11 (diff)
downloadtcl-bbe8ae73e2e5c693a20ea16c964949279ff83045.zip
tcl-bbe8ae73e2e5c693a20ea16c964949279ff83045.tar.gz
tcl-bbe8ae73e2e5c693a20ea16c964949279ff83045.tar.bz2
Decouple the switch handling.
-rw-r--r--generic/tclIOCmd.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index fb37ff6..e64e31d 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -1492,7 +1492,8 @@ Tcl_SocketObjCmd(
SKT_ASYNC, SKT_MYADDR, SKT_MYPORT, SKT_REUSEADDR, SKT_REUSEPORT,
SKT_SERVER
};
- int optionIndex, a, server = 0, myport = 0, async = 0, boolTmp;
+ int optionIndex, a, server = 0, myport = 0, async = 0, reusep = 0,
+ reusea = 0;
unsigned int flags = 0;
const char *host, *port, *myaddr = NULL;
Tcl_Obj *script = NULL;
@@ -1552,7 +1553,8 @@ Tcl_SocketObjCmd(
return TCL_ERROR;
}
server = 1;
- flags |= TCL_TCPSERVER_REUSEADDR;
+ /* [TIP#456] Set for backward-compatibility. */
+ reusea = 1;
a++;
if (a >= objc) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
@@ -1568,14 +1570,9 @@ Tcl_SocketObjCmd(
"no argument given for -reuseaddr option", -1));
return TCL_ERROR;
}
- if (Tcl_GetBooleanFromObj(interp, objv[a], &boolTmp) != TCL_OK) {
+ if (Tcl_GetBooleanFromObj(interp, objv[a], &reusea) != TCL_OK) {
return TCL_ERROR;
}
- if (boolTmp) {
- flags |= TCL_TCPSERVER_REUSEADDR;
- } else {
- flags &= ~TCL_TCPSERVER_REUSEADDR;
- }
break;
case SKT_REUSEPORT:
a++;
@@ -1584,14 +1581,9 @@ Tcl_SocketObjCmd(
"no argument given for -reuseport option", -1));
return TCL_ERROR;
}
- if (Tcl_GetBooleanFromObj(interp, objv[a], &boolTmp) != TCL_OK) {
+ if (Tcl_GetBooleanFromObj(interp, objv[a], &reusep) != TCL_OK) {
return TCL_ERROR;
}
- if (boolTmp) {
- flags |= TCL_TCPSERVER_REUSEPORT;
- } else {
- flags &= ~TCL_TCPSERVER_REUSEPORT;
- }
break;
default:
Tcl_Panic("Tcl_SocketObjCmd: bad option index to SocketOptions");
@@ -1621,13 +1613,16 @@ Tcl_SocketObjCmd(
return TCL_ERROR;
}
- if (!server && flags != 0) {
+ if (!server && (reusea != 0 || reusep != 0)) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"options -reuseaddr and -reuseport are only valid for servers",
-1));
return TCL_ERROR;
}
+ flags |= reusea ? TCL_TCPSERVER_REUSEADDR : 0;
+ flags |= reusep ? TCL_TCPSERVER_REUSEPORT : 0;
+
// All the arguments should have been parsed by now, 'a' points to the last
// one, the port number.
if (a != objc-1) {