summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorlimeboy <that.lemon+tcl@gmai.com>2016-12-14 15:49:27 (GMT)
committerlimeboy <that.lemon+tcl@gmai.com>2016-12-14 15:49:27 (GMT)
commitfdc5267c5f6488e6f8065453fc078e0ebc45d861 (patch)
tree252d57e9f2c63147b2b616e30c2c54e1fe47a086 /generic
parentbba3b008ba9e94fbe9a9ffce00aaf90077136fca (diff)
downloadtcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.zip
tcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.tar.gz
tcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.tar.bz2
Make OpenTcpServerEx accept a 'service' string parameter instead of a port.
Diffstat (limited to 'generic')
-rw-r--r--generic/tcl.decls2
-rw-r--r--generic/tclDecls.h7
-rw-r--r--generic/tclIOCmd.c25
3 files changed, 20 insertions, 14 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index af496b3..ba047a0 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -2328,7 +2328,7 @@ declare 630 {
# TIP #456
declare 631 {
- Tcl_Channel Tcl_OpenTcpServerEx(Tcl_Interp *interp, int port,
+ Tcl_Channel Tcl_OpenTcpServerEx(Tcl_Interp *interp, const char *service,
const char *host, unsigned int flags, Tcl_TcpAcceptProc *acceptProc,
ClientData callbackData)
}
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index 4810c51..49ac440 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1817,8 +1817,9 @@ EXTERN void Tcl_ZlibStreamSetCompressionDictionary(
Tcl_ZlibStream zhandle,
Tcl_Obj *compressionDictionaryObj);
/* 631 */
-EXTERN Tcl_Channel Tcl_OpenTcpServerEx(Tcl_Interp *interp, int port,
- const char *host, unsigned int flags,
+EXTERN Tcl_Channel Tcl_OpenTcpServerEx(Tcl_Interp *interp,
+ const char *service, const char *host,
+ unsigned int flags,
Tcl_TcpAcceptProc *acceptProc,
ClientData callbackData);
@@ -2487,7 +2488,7 @@ typedef struct TclStubs {
void * (*tcl_FindSymbol) (Tcl_Interp *interp, Tcl_LoadHandle handle, const char *symbol); /* 628 */
int (*tcl_FSUnloadFile) (Tcl_Interp *interp, Tcl_LoadHandle handlePtr); /* 629 */
void (*tcl_ZlibStreamSetCompressionDictionary) (Tcl_ZlibStream zhandle, Tcl_Obj *compressionDictionaryObj); /* 630 */
- Tcl_Channel (*tcl_OpenTcpServerEx) (Tcl_Interp *interp, int port, const char *host, unsigned int flags, Tcl_TcpAcceptProc *acceptProc, ClientData callbackData); /* 631 */
+ Tcl_Channel (*tcl_OpenTcpServerEx) (Tcl_Interp *interp, const char *service, const char *host, unsigned int flags, Tcl_TcpAcceptProc *acceptProc, ClientData callbackData); /* 631 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index d6637a0..951fb5a 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -1492,9 +1492,9 @@ Tcl_SocketObjCmd(
SKT_ASYNC, SKT_MYADDR, SKT_MYPORT, SKT_REUSEADDR, SKT_REUSEPORT,
SKT_SERVER
};
- int optionIndex, a, server = 0, port, myport = 0, async = 0, boolTmp;
+ int optionIndex, a, server = 0, myport = 0, async = 0, boolTmp;
unsigned int flags = 0;
- const char *host, *myaddr = NULL;
+ const char *host, *port, *myaddr = NULL;
Tcl_Obj *script = NULL;
Tcl_Channel chan;
@@ -1628,15 +1628,14 @@ Tcl_SocketObjCmd(
return TCL_ERROR;
}
- if (a == objc-1) {
- if (TclSockGetPort(interp, TclGetString(objv[a]), "tcp",
- &port) != TCL_OK) {
- return TCL_ERROR;
- }
- } else {
+ // All the arguments should have been parsed by now, 'a' points to the last
+ // one, the port number.
+ if (a != objc-1) {
goto wrongNumArgs;
}
+ port = TclGetString(objv[a]);
+
if (server) {
AcceptCallback *acceptCallbackPtr =
ckalloc(sizeof(AcceptCallback));
@@ -1646,7 +1645,7 @@ Tcl_SocketObjCmd(
acceptCallbackPtr->interp = interp;
chan = Tcl_OpenTcpServerEx(interp, port, host, flags, AcceptCallbackProc,
- acceptCallbackPtr);
+ acceptCallbackPtr);
if (chan == NULL) {
Tcl_DecrRefCount(script);
ckfree(acceptCallbackPtr);
@@ -1670,7 +1669,13 @@ Tcl_SocketObjCmd(
Tcl_CreateCloseHandler(chan, TcpServerCloseProc, acceptCallbackPtr);
} else {
- chan = Tcl_OpenTcpClient(interp, port, host, myaddr, myport, async);
+ int portNum;
+
+ if (TclSockGetPort(interp, port, "tcp", &portNum) != TCL_OK) {
+ return TCL_ERROR;
+ }
+
+ chan = Tcl_OpenTcpClient(interp, portNum, host, myaddr, myport, async);
if (chan == NULL) {
return TCL_ERROR;
}