From d302d0e71085efc1f3c7d150e571cd9bb1901600 Mon Sep 17 00:00:00 2001 From: stanton Date: Wed, 3 Feb 1999 00:51:19 +0000 Subject: * unix/tclUnixChan.c: * win/tclWinSock.c: * doc/socket.n: Applied Gordon Chaffee's patch to handle failures during asynchronous socket connection operations. This adds a new "-error" fconfgure option to socket channels. [Bug: 893] --- doc/socket.n | 13 +++++++++++-- unix/tclUnixChan.c | 19 ++++++++++++++++++- win/tclWinSock.c | 24 +++++++++++++++++++++--- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/doc/socket.n b/doc/socket.n index 27f166f..ebb7383 100644 --- a/doc/socket.n +++ b/doc/socket.n @@ -1,12 +1,13 @@ '\" '\" Copyright (c) 1996 Sun Microsystems, Inc. +'\" Copyright (c) 1998-1999 by Scriptics Corporation. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: socket.n,v 1.2 1998/09/14 18:39:55 stanton Exp $ +'\" RCS: @(#) $Id: socket.n,v 1.3 1999/02/03 00:51:19 stanton Exp $ .so man.macros -.TH socket n 7.5 Tcl "Tcl Built-In Commands" +.TH socket n 8.0 Tcl "Tcl Built-In Commands" .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME @@ -103,6 +104,14 @@ will be accepted. .SH CONFIGURATION OPTIONS The \fBfconfigure\fR command can be used to query several readonly configuration options for socket channels: +.VS +.TP +\fB\-error\fR +This option gets the current error status of the given socket. This +is useful when you need to determine if an asynchronous connect +operation succeeded. If there was an error, the error message is +returned. If there was no error, an empty string is returned. +.VE .TP \fB\-sockname\fR This option returns a list of three elements, the address, the host name diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 4fe0144..2759a41 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixChan.c,v 1.8 1999/01/04 19:25:04 rjohnson Exp $ + * RCS: @(#) $Id: tclUnixChan.c,v 1.9 1999/02/03 00:51:20 stanton Exp $ */ #include "tclInt.h" /* Internal definitions for Tcl. */ @@ -1659,6 +1659,23 @@ TcpGetOptionProc(instanceData, interp, optionName, dsPtr) len = strlen(optionName); } + if ((len > 1) && (optionName[1] == 'e') && + (strncmp(optionName, "-error", len) == 0)) { + int optlen; + int err, ret; + + optlen = sizeof(int); + ret = getsockopt(statePtr->fd, SOL_SOCKET, SO_ERROR, + (char *)&err, &optlen); + if (ret < 0) { + err = errno; + } + if (err != 0) { + Tcl_DStringAppend(dsPtr, Tcl_ErrnoMsg(err), -1); + } + return TCL_OK; + } + if ((len == 0) || ((len > 1) && (optionName[1] == 'p') && (strncmp(optionName, "-peername", len) == 0))) { diff --git a/win/tclWinSock.c b/win/tclWinSock.c index 00e7f22..a8f2a2f 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinSock.c,v 1.4 1998/12/04 01:01:55 stanton Exp $ + * RCS: @(#) $Id: tclWinSock.c,v 1.5 1999/02/03 00:51:20 stanton Exp $ */ #include "tclInt.h" @@ -699,7 +699,7 @@ SocketEventProc(evPtr, flags) } } - if (events & FD_WRITE) { + if (events & (FD_WRITE | FD_CONNECT)) { mask |= TCL_WRITABLE; } @@ -1741,6 +1741,24 @@ TcpGetOptionProc(instanceData, interp, optionName, dsPtr) len = strlen(optionName); } + if ((len > 1) && (optionName[1] == 'e') && + (strncmp(optionName, "-error", len) == 0)) { + int optlen; + int err, ret; + + optlen = sizeof(int); + ret = TclWinGetSockOpt(sock, SOL_SOCKET, SO_ERROR, + (char *)&err, &optlen); + if (ret == SOCKET_ERROR) { + err = (*winSock.WSAGetLastError)(); + } + if (err) { + TclWinConvertWSAError(err); + Tcl_DStringAppend(dsPtr, Tcl_ErrnoMsg(Tcl_GetErrno()), -1); + } + return TCL_OK; + } + if ((len == 0) || ((len > 1) && (optionName[1] == 'p') && (strncmp(optionName, "-peername", len) == 0))) { @@ -1868,7 +1886,7 @@ TcpWatchProc(instanceData, mask) infoPtr->watchEvents |= (FD_READ|FD_CLOSE|FD_ACCEPT); } if (mask & TCL_WRITABLE) { - infoPtr->watchEvents |= (FD_WRITE); + infoPtr->watchEvents |= (FD_WRITE|FD_CONNECT); } /* -- cgit v0.12