summaryrefslogtreecommitdiffstats
path: root/generic/tclIOCmd.c
diff options
context:
space:
mode:
authorlimeboy <that.lemon+tcl@gmai.com>2016-11-24 21:01:43 (GMT)
committerlimeboy <that.lemon+tcl@gmai.com>2016-11-24 21:01:43 (GMT)
commitc7c008ed87d396afec9a6f9879a22660d6afa490 (patch)
treea88dd559e9fef2fc47befe095b184127b9bc9480 /generic/tclIOCmd.c
parent994c07125e17358a895eddd8f573065b68d83d68 (diff)
downloadtcl-c7c008ed87d396afec9a6f9879a22660d6afa490.zip
tcl-c7c008ed87d396afec9a6f9879a22660d6afa490.tar.gz
tcl-c7c008ed87d396afec9a6f9879a22660d6afa490.tar.bz2
Allow a boolean argument to be passed.
Diffstat (limited to 'generic/tclIOCmd.c')
-rw-r--r--generic/tclIOCmd.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index b4696fd..49c7c06 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -1485,14 +1485,14 @@ Tcl_SocketObjCmd(
Tcl_Obj *const objv[]) /* Argument objects. */
{
static const char *const socketOptions[] = {
- "-async", "-myaddr", "-myport", "-server", "-reuseaddr", "-reuseport",
+ "-async", "-myaddr", "-myport", "-reuseaddr", "-reuseport", "server",
NULL
};
enum socketOptions {
- SKT_ASYNC, SKT_MYADDR, SKT_MYPORT, SKT_SERVER, SKT_REUSEADDR,
- SKT_REUSEPORT
+ SKT_ASYNC, SKT_MYADDR, SKT_MYPORT, SKT_REUSEADDR, SKT_REUSEPORT,
+ SKT_SERVER
};
- int optionIndex, a, server = 0, port, myport = 0, async = 0;
+ int optionIndex, a, server = 0, port, myport = 0, async = 0, boolTmp;
unsigned int flags = 0;
const char *host, *myaddr = NULL;
Tcl_Obj *script = NULL;
@@ -1552,6 +1552,7 @@ Tcl_SocketObjCmd(
return TCL_ERROR;
}
server = 1;
+ flags = TCL_TCPSERVER_REUSEADDR;
a++;
if (a >= objc) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
@@ -1561,10 +1562,36 @@ Tcl_SocketObjCmd(
script = objv[a];
break;
case SKT_REUSEADDR:
- flags |= TCL_TCPSERVER_REUSEADDR;
+ a++;
+ if (a >= objc) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "no argument given for -reuseaddr option", -1));
+ return TCL_ERROR;
+ }
+ if (Tcl_GetBooleanFromObj(interp, objv[a], &boolTmp) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (boolTmp) {
+ flags |= TCL_TCPSERVER_REUSEADDR;
+ } else {
+ flags &= ~TCL_TCPSERVER_REUSEADDR;
+ }
break;
case SKT_REUSEPORT:
- flags |= TCL_TCPSERVER_REUSEPORT;
+ a++;
+ if (a >= objc) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "no argument given for -reuseport option", -1));
+ return TCL_ERROR;
+ }
+ if (Tcl_GetBooleanFromObj(interp, objv[a], &boolTmp) != 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");
@@ -1589,7 +1616,8 @@ Tcl_SocketObjCmd(
"?-myaddr addr? ?-myport myport? ?-async? host port");
iPtr->flags |= INTERP_ALTERNATE_WRONG_ARGS;
Tcl_WrongNumArgs(interp, 1, objv,
- "-server command ?-reuseaddr? ?-reuseport? ?-myaddr addr? port");
+ "-server command ?-reuseaddr boolean? ?-reuseport boolean? "
+ "?-myaddr addr? port");
return TCL_ERROR;
}