summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tcl.decls5
-rw-r--r--generic/tclDecls.h12
-rw-r--r--generic/tclIOCmd.c19
-rw-r--r--generic/tclIOSock.c13
-rw-r--r--generic/tclInt.h2
-rw-r--r--generic/tclStubInit.c1
-rw-r--r--unix/tclUnixSock.c33
-rw-r--r--win/tclWinSock.c31
8 files changed, 75 insertions, 41 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index c7ca44f..f37d4d1 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -2332,6 +2332,11 @@ declare 631 {
const char *host, unsigned int flags, int backlog,
Tcl_TcpAcceptProc *acceptProc, ClientData callbackData)
}
+declare 632 {
+ Tcl_Channel Tcl_OpenTcpClientEx(Tcl_Interp *interp, const char *service,
+ const char *host, const char *myaddr, const char *myservice,
+ unsigned int flags)
+}
# ----- BASELINE -- FOR -- 8.7.0 ----- #
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index d543238..67cf1e5 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1819,9 +1819,14 @@ EXTERN void Tcl_ZlibStreamSetCompressionDictionary(
/* 631 */
EXTERN Tcl_Channel Tcl_OpenTcpServerEx(Tcl_Interp *interp,
const char *service, const char *host,
- unsigned int flags,
+ unsigned int flags, int backlog,
Tcl_TcpAcceptProc *acceptProc,
ClientData callbackData);
+/* 632 */
+EXTERN Tcl_Channel Tcl_OpenTcpClientEx(Tcl_Interp *interp,
+ const char *service, const char *host,
+ const char *myaddr, const char *myservice,
+ unsigned int flags);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
@@ -2488,7 +2493,8 @@ 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, const char *service, 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, int backlog, Tcl_TcpAcceptProc *acceptProc, ClientData callbackData); /* 631 */
+ Tcl_Channel (*tcl_OpenTcpClientEx) (Tcl_Interp *interp, const char *service, const char *host, const char *myaddr, const char *myservice, unsigned int flags); /* 632 */
} TclStubs;
extern const TclStubs *tclStubsPtr;
@@ -3783,6 +3789,8 @@ extern const TclStubs *tclStubsPtr;
(tclStubsPtr->tcl_ZlibStreamSetCompressionDictionary) /* 630 */
#define Tcl_OpenTcpServerEx \
(tclStubsPtr->tcl_OpenTcpServerEx) /* 631 */
+#define Tcl_OpenTcpClientEx \
+ (tclStubsPtr->tcl_OpenTcpClientEx) /* 632 */
#endif /* defined(USE_TCL_STUBS) */
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index 712f773..94a74cd 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -1492,10 +1492,10 @@ Tcl_SocketObjCmd(
SKT_ASYNC, SKT_BACKLOG, SKT_MYADDR, SKT_MYPORT, SKT_REUSEADDR,
SKT_REUSEPORT, SKT_SERVER
};
- int optionIndex, a, server = 0, myport = 0, async = 0, reusep = -1,
+ int optionIndex, a, server = 0, async = 0, reusep = -1,
reusea = -1, backlog = -1;
unsigned int flags = 0;
- const char *host, *port, *myaddr = NULL;
+ const char *host, *port, *myaddr = NULL, *myport = NULL;
Tcl_Obj *script = NULL;
Tcl_Channel chan;
@@ -1532,18 +1532,13 @@ Tcl_SocketObjCmd(
myaddr = TclGetString(objv[a]);
break;
case SKT_MYPORT: {
- const char *myPortName;
-
a++;
if (a >= objc) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"no argument given for -myport option", -1));
return TCL_ERROR;
}
- myPortName = TclGetString(objv[a]);
- if (TclSockGetPort(interp, myPortName, "tcp", &myport) != TCL_OK) {
- return TCL_ERROR;
- }
+ myport = TclGetString(objv[a]);
break;
}
case SKT_SERVER:
@@ -1695,13 +1690,7 @@ Tcl_SocketObjCmd(
Tcl_CreateCloseHandler(chan, TcpServerCloseProc, acceptCallbackPtr);
} else {
- int portNum;
-
- if (TclSockGetPort(interp, port, "tcp", &portNum) != TCL_OK) {
- return TCL_ERROR;
- }
-
- chan = Tcl_OpenTcpClient(interp, portNum, host, myaddr, myport, async);
+ chan = Tcl_OpenTcpClientEx(interp, port, host, myaddr, myport, async);
if (chan == NULL) {
return TCL_ERROR;
}
diff --git a/generic/tclIOSock.c b/generic/tclIOSock.c
index 5038775..fb8c002 100644
--- a/generic/tclIOSock.c
+++ b/generic/tclIOSock.c
@@ -163,7 +163,7 @@ TclCreateSocketAddress(
* family */
struct addrinfo **addrlist, /* Socket address list */
const char *host, /* Host. NULL implies INADDR_ANY */
- int port, /* Port number */
+ const char *service, /* Service */
int willBind, /* Is this an address to bind() to or to
* connect() to? */
const char **errorMsgPtr) /* Place to store the error message detail, if
@@ -173,7 +173,7 @@ TclCreateSocketAddress(
struct addrinfo *p;
struct addrinfo *v4head = NULL, *v4ptr = NULL;
struct addrinfo *v6head = NULL, *v6ptr = NULL;
- char *native = NULL, portbuf[TCL_INTEGER_SPACE], *portstring;
+ char *native = NULL;
const char *family = NULL;
Tcl_DString ds;
int result;
@@ -187,11 +187,8 @@ TclCreateSocketAddress(
* when the loopback device is the only available network interface.
*/
- if (host != NULL && port == 0) {
- portstring = NULL;
- } else {
- TclFormatInt(portbuf, port);
- portstring = portbuf;
+ if (host != NULL && service != NULL && !strcmp(service, "0")) {
+ service = NULL;
}
(void) memset(&hints, 0, sizeof(hints));
@@ -236,7 +233,7 @@ TclCreateSocketAddress(
hints.ai_flags |= AI_PASSIVE;
}
- result = getaddrinfo(native, portstring, &hints, addrlist);
+ result = getaddrinfo(native, service, &hints, addrlist);
if (host != NULL) {
Tcl_DStringFree(&ds);
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 1fbc541..56c0e82 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3078,7 +3078,7 @@ MODULE_SCOPE void TclpFinalizePipes(void);
MODULE_SCOPE void TclpFinalizeSockets(void);
MODULE_SCOPE int TclCreateSocketAddress(Tcl_Interp *interp,
struct addrinfo **addrlist,
- const char *host, int port, int willBind,
+ const char *host, const char *service, int willBind,
const char **errorMsgPtr);
MODULE_SCOPE int TclpThreadCreate(Tcl_ThreadId *idPtr,
Tcl_ThreadCreateProc *proc, ClientData clientData,
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 59325b7..8a6e367 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -1519,6 +1519,7 @@ const TclStubs tclStubs = {
Tcl_FSUnloadFile, /* 629 */
Tcl_ZlibStreamSetCompressionDictionary, /* 630 */
Tcl_OpenTcpServerEx, /* 631 */
+ Tcl_OpenTcpClientEx, /* 632 */
};
/* !END!: Do not edit above this line. */
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 95e134b..98d34a4 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -1320,17 +1320,32 @@ Tcl_OpenTcpClient(
* connect. Otherwise we do a blocking
* connect. */
{
+ char service[TCL_INTEGER_SPACE], myservice[TCL_INTEGER_SPACE];
+
+ TclFormatInt(service, port);
+ TclFormatInt(myservice, myport);
+
+ return Tcl_OpenTcpClientEx(interp, service, host, myaddr, myservice, async!=0);
+}
+
+Tcl_Channel
+Tcl_OpenTcpClientEx(
+ Tcl_Interp *interp, /* For error reporting; can be NULL. */
+ const char *service, /* Port number to open. */
+ const char *host, /* Host on which to open port. */
+ const char *myaddr, /* Client-side address */
+ const char *myservice, /* Client-side port */
+ unsigned int flags) /* If nonzero, attempt to do an asynchronous
+ * connect. Otherwise we do a blocking
+ * connect. */
+{
TcpState *statePtr;
const char *errorMsg = NULL;
struct addrinfo *addrlist = NULL, *myaddrlist = NULL;
char channelName[SOCK_CHAN_LENGTH];
- /*
- * Do the name lookups for the local and remote addresses.
- */
-
- if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
- || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
+ if (!TclCreateSocketAddress(interp, &addrlist, host, service, 0, &errorMsg)
+ || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myservice, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
@@ -1348,7 +1363,7 @@ Tcl_OpenTcpClient(
statePtr = ckalloc(sizeof(TcpState));
memset(statePtr, 0, sizeof(TcpState));
- statePtr->flags = async ? TCP_ASYNC_CONNECT : 0;
+ statePtr->flags = (flags&1) ? TCP_ASYNC_CONNECT : 0;
statePtr->cachedBlocking = TCL_MODE_BLOCKING;
statePtr->addrlist = addrlist;
statePtr->myaddrlist = myaddrlist;
@@ -1523,8 +1538,8 @@ Tcl_OpenTcpServerEx(
goto error;
}
- if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1,
- &errorMsg)) {
+ if (!TclCreateSocketAddress(interp, &addrlist, myHost, service, 1,
+ &errorMsg)) {
my_errno = errno;
goto error;
}
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index e42cafd..01cefb5 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -1993,7 +1993,7 @@ TcpConnect(
/*
*----------------------------------------------------------------------
*
- * Tcl_OpenTcpClient --
+ * Tcl_OpenTcpClient, Tcl_OpenTcpClientEx --
*
* Opens a TCP client socket and creates a channel around it.
*
@@ -2018,6 +2018,25 @@ Tcl_OpenTcpClient(
* connect. Otherwise we do a blocking
* connect. */
{
+ char service[TCL_INTEGER_SPACE], myservice[TCL_INTEGER_SPACE];
+
+ TclFormatInt(service, port);
+ TclFormatInt(myservice, myport);
+
+ return Tcl_OpenTcpClientEx(interp, service, host, myaddr, myservice, async!=0);
+}
+
+Tcl_Channel
+Tcl_OpenTcpClientEx(
+ Tcl_Interp *interp, /* For error reporting; can be NULL. */
+ const char *service, /* Port number to open. */
+ const char *host, /* Host on which to open port. */
+ const char *myaddr, /* Client-side address */
+ const char *myservice, /* Client-side port */
+ unsigned int flags) /* If nonzero, attempt to do an asynchronous
+ * connect. Otherwise we do a blocking
+ * connect. */
+{
TcpState *statePtr;
const char *errorMsg = NULL;
struct addrinfo *addrlist = NULL, *myaddrlist = NULL;
@@ -2041,8 +2060,8 @@ Tcl_OpenTcpClient(
* Do the name lookups for the local and remote addresses.
*/
- if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
- || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
+ if (!TclCreateSocketAddress(interp, &addrlist, host, service, 0, &errorMsg)
+ || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myservice, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
@@ -2057,7 +2076,7 @@ Tcl_OpenTcpClient(
statePtr = NewSocketInfo(INVALID_SOCKET);
statePtr->addrlist = addrlist;
statePtr->myaddrlist = myaddrlist;
- if (async) {
+ if (flags&1) {
SET_BITS(statePtr->flags, TCP_ASYNC_CONNECT);
}
@@ -2201,8 +2220,8 @@ Tcl_OpenTcpServerEx(
goto error;
}
- if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1,
- &errorMsg)) {
+ if (!TclCreateSocketAddress(interp, &addrlist, myHost, service, 1,
+ &errorMsg)) {
goto error;
}