summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixSock.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-03-28 13:32:37 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-03-28 13:32:37 (GMT)
commit47e821e8297b9b9d7bb295a11f35c0307f2c1a7a (patch)
tree968af4744acfc6496b9611741040c3da171cb682 /unix/tclUnixSock.c
parent6540c1e7abc493b3684a2b1312717329494b96b1 (diff)
parent1251bcbcc6272da5c31c077c03ce238cfde19844 (diff)
downloadtcl-47e821e8297b9b9d7bb295a11f35c0307f2c1a7a.zip
tcl-47e821e8297b9b9d7bb295a11f35c0307f2c1a7a.tar.gz
tcl-47e821e8297b9b9d7bb295a11f35c0307f2c1a7a.tar.bz2
merge trunk
Diffstat (limited to 'unix/tclUnixSock.c')
-rw-r--r--unix/tclUnixSock.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 7b5c9e0..8c94e7f 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -1252,13 +1252,25 @@ Tcl_OpenTcpServer(
const char *errorMsg = NULL;
TcpFdList *fds = NULL, *newfds;
+ /*
+ * Try to record and return the most meaningful error message, i.e. the
+ * one from the first socket that went the farthest before it failed.
+ */
+ enum { START, SOCKET, BIND, LISTEN } howfar = START;
+ int my_errno = 0;
+
if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) {
goto error;
}
for (addrPtr = addrlist; addrPtr != NULL; addrPtr = addrPtr->ai_next) {
- sock = socket(addrPtr->ai_family, SOCK_STREAM, 0);
+ sock = socket(addrPtr->ai_family, addrPtr->ai_socktype,
+ addrPtr->ai_protocol);
if (sock == -1) {
+ if (howfar < SOCKET) {
+ howfar = SOCKET;
+ my_errno = errno;
+ }
continue;
}
@@ -1308,6 +1320,10 @@ Tcl_OpenTcpServer(
status = bind(sock, addrPtr->ai_addr, addrPtr->ai_addrlen);
if (status == -1) {
+ if (howfar < BIND) {
+ howfar = BIND;
+ my_errno = errno;
+ }
close(sock);
continue;
}
@@ -1326,6 +1342,10 @@ Tcl_OpenTcpServer(
}
status = listen(sock, SOMAXCONN);
if (status < 0) {
+ if (howfar < LISTEN) {
+ howfar = LISTEN;
+ my_errno = errno;
+ }
close(sock);
continue;
}
@@ -1367,6 +1387,7 @@ Tcl_OpenTcpServer(
return statePtr->channel;
}
if (interp != NULL) {
+ errno = my_errno;
Tcl_AppendResult(interp, "couldn't open socket: ",
Tcl_PosixError(interp), NULL);
if (errorMsg != NULL) {