summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2014-09-26 12:05:30 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2014-09-26 12:05:30 (GMT)
commitd9a8b078d1c03a51b8835666ddd27e0e54a2817d (patch)
tree35d0f303ead76ff1561141cdab4bddf7e94f4615 /unix
parent43921a6b7f362d8ae47b70eb98a7c9b0ff3ee665 (diff)
downloadtcl-d9a8b078d1c03a51b8835666ddd27e0e54a2817d.zip
tcl-d9a8b078d1c03a51b8835666ddd27e0e54a2817d.tar.gz
tcl-d9a8b078d1c03a51b8835666ddd27e0e54a2817d.tar.bz2
Implemented tip-427: socket fconfigure option -connecting plus no -peername,-sockname when still connecting.
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixSock.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 96700ce..ca25435 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -823,7 +823,20 @@ TcpGetOptionProc(
address peername;
socklen_t size = sizeof(peername);
- if (getpeername(statePtr->fds.fd, &peername.sa, &size) >= 0) {
+ if ( (statePtr->flags & TCP_ASYNC_CONNECT) ) {
+ /*
+ * In async connect output an empty string
+ */
+ if (len == 0) {
+ Tcl_DStringAppendElement(dsPtr, "-peername");
+ Tcl_DStringAppendElement(dsPtr, "");
+ } else {
+ return TCL_OK;
+ }
+ } else if (getpeername(statePtr->fds.fd, &peername.sa, &size) >= 0) {
+ /*
+ * Peername fetch succeeded - output list
+ */
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-peername");
Tcl_DStringStartSublist(dsPtr);
@@ -863,11 +876,18 @@ TcpGetOptionProc(
Tcl_DStringAppendElement(dsPtr, "-sockname");
Tcl_DStringStartSublist(dsPtr);
}
- for (fds = &statePtr->fds; fds != NULL; fds = fds->next) {
- size = sizeof(sockname);
- if (getsockname(fds->fd, &(sockname.sa), &size) >= 0) {
- found = 1;
- TcpHostPortList(interp, dsPtr, sockname, size);
+ if ( (statePtr->flags & TCP_ASYNC_CONNECT) ) {
+ /*
+ * In async connect output an empty string
+ */
+ found = 1;
+ } else {
+ for (fds = &statePtr->fds; fds != NULL; fds = fds->next) {
+ size = sizeof(sockname);
+ if (getsockname(fds->fd, &(sockname.sa), &size) >= 0) {
+ found = 1;
+ TcpHostPortList(interp, dsPtr, sockname, size);
+ }
}
}
if (found) {
@@ -885,7 +905,7 @@ TcpGetOptionProc(
}
if (len > 0) {
- return Tcl_BadChannelOption(interp, optionName, "peername sockname");
+ return Tcl_BadChannelOption(interp, optionName, "connecting peername sockname");
}
return TCL_OK;