summaryrefslogtreecommitdiffstats
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
parentbba3b008ba9e94fbe9a9ffce00aaf90077136fca (diff)
downloadtcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.zip
tcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.tar.gz
tcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.tar.bz2
Make OpenTcpServerEx accept a 'service' string parameter instead of a port.
-rw-r--r--generic/tcl.decls2
-rw-r--r--generic/tclDecls.h7
-rw-r--r--generic/tclIOCmd.c25
-rw-r--r--unix/tclUnixSock.c9
-rw-r--r--win/tclWinSock.c9
5 files changed, 34 insertions, 18 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;
}
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 187c157..8e97543 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -1422,7 +1422,7 @@ TclpMakeTcpClientChannelMode(
Tcl_Channel
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,
@@ -1430,7 +1430,7 @@ Tcl_OpenTcpServerEx(
* clients. */
ClientData acceptProcData) /* Data for the callback. */
{
- int status = 0, sock = -1, optvalue, chosenport;
+ int status = 0, sock = -1, optvalue, port, chosenport;
struct addrinfo *addrlist = NULL, *addrPtr; /* socket address */
TcpState *statePtr = NULL;
char channelName[SOCK_CHAN_LENGTH];
@@ -1476,6 +1476,11 @@ Tcl_OpenTcpServerEx(
retry++;
chosenport = 0;
+ if (TclSockGetPort(interp, service, "tcp", &port) != TCL_OK) {
+ errorMsg = "invalid port number";
+ goto error;
+ }
+
if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) {
my_errno = errno;
goto error;
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index af22cf8..5e0d7c8 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -2037,7 +2037,7 @@ Tcl_MakeTcpClientChannel(
Tcl_Channel
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,
@@ -2053,7 +2053,7 @@ Tcl_OpenTcpServerEx(
char channelName[SOCK_CHAN_LENGTH];
u_long flag = 1; /* Indicates nonblocking mode. */
const char *errorMsg = NULL;
- int optvalue;
+ int optvalue, port;
if (TclpHasSockets(interp) != TCL_OK) {
return NULL;
@@ -2073,6 +2073,11 @@ Tcl_OpenTcpServerEx(
* 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;
}