diff options
Diffstat (limited to 'unix')
-rw-r--r-- | unix/Makefile.in | 4 | ||||
-rw-r--r-- | unix/tclConfig.sh.in | 2 | ||||
-rw-r--r-- | unix/tclUnixChan.c | 17 | ||||
-rw-r--r-- | unix/tclUnixInit.c | 76 | ||||
-rw-r--r-- | unix/tclUnixNotfy.c | 4 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 360 | ||||
-rw-r--r-- | unix/tclUnixThrd.c | 2 | ||||
-rw-r--r-- | unix/tclUnixTime.c | 7 |
8 files changed, 294 insertions, 178 deletions
diff --git a/unix/Makefile.in b/unix/Makefile.in index c4f6136..3af93d1 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -841,8 +841,8 @@ install-libraries: libraries do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/http1.0; \ done; - @echo "Installing package http 2.8.10 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/http/http.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.6/http-2.8.10.tm; + @echo "Installing package http 2.8.11 as a Tcl Module"; + @$(INSTALL_DATA) $(TOP_DIR)/library/http/http.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.6/http-2.8.11.tm; @echo "Installing package opt0.4 files to $(SCRIPT_INSTALL_DIR)/opt0.4/"; @for i in $(TOP_DIR)/library/opt/*.tcl ; \ do \ diff --git a/unix/tclConfig.sh.in b/unix/tclConfig.sh.in index 27fd513..fdc56b7 100644 --- a/unix/tclConfig.sh.in +++ b/unix/tclConfig.sh.in @@ -81,7 +81,7 @@ TCL_DL_LIBS='@DL_LIBS@' # an executable tclsh or tcltest binary. TCL_LD_FLAGS='@LDFLAGS@' -# Flags to pass to ld, such as "-R /usr/local/tcl/lib", that tell the +# Flags to pass to cc/ld, such as "-R /usr/local/tcl/lib", that tell the # run-time dynamic linker where to look for shared libraries such as # libtcl.so. Used when linking applications. Only works if there # is a variable "LIB_RUNTIME_DIR" defined in the Makefile. diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 6418f48..3bf64d6 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -605,7 +605,6 @@ TtySetOptionProc( return TCL_OK; } - /* * Option -handshake none|xonxoff|rtscts|dtrdsr */ @@ -706,6 +705,7 @@ TtySetOptionProc( /* * Option -ttycontrol {DTR 1 RTS 0 BREAK 0} */ + if ((len > 4) && (strncmp(optionName, "-ttycontrol", len) == 0)) { #if defined(TIOCMGET) && defined(TIOCMSET) int i, control, flag; @@ -882,6 +882,7 @@ TtyGetOptionProc( * Option is readonly and returned by [fconfigure chan -ttystatus] but not * returned by unnamed [fconfigure chan]. */ + if ((len > 4) && (strncmp(optionName, "-ttystatus", len) == 0)) { int status; @@ -894,12 +895,10 @@ TtyGetOptionProc( if (valid) { return TCL_OK; } - return Tcl_BadChannelOption(interp, optionName, "mode" - " queue ttystatus xchar" - ); + return Tcl_BadChannelOption(interp, optionName, + "mode queue ttystatus xchar"); } - static const struct {int baud; speed_t speed;} speeds[] = { #ifdef B0 {0, B0}, @@ -1023,7 +1022,7 @@ static const struct {int baud; speed_t speed;} speeds[] = { #endif {-1, 0} }; - + /* *--------------------------------------------------------------------------- * @@ -1315,7 +1314,8 @@ TtyParseMode( static void TtyInit( - int fd) /* Open file descriptor for serial port to be initialized. */ + int fd) /* Open file descriptor for serial port to be + * initialized. */ { struct termios iostate; tcgetattr(fd, &iostate); @@ -1325,8 +1325,7 @@ TtyInit( || iostate.c_lflag != 0 || iostate.c_cflag & CREAD || iostate.c_cc[VMIN] != 1 - || iostate.c_cc[VTIME] != 0) - { + || iostate.c_cc[VTIME] != 0) { iostate.c_iflag = IGNBRK; iostate.c_oflag = 0; iostate.c_lflag = 0; diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 1e35b92..feeffa6 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -14,11 +14,11 @@ #ifdef HAVE_LANGINFO # include <langinfo.h> # ifdef __APPLE__ -# if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1030 +# if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1030 /* Support for weakly importing nl_langinfo on Darwin. */ # define WEAK_IMPORT_NL_LANGINFO extern char *nl_langinfo(nl_item) WEAK_IMPORT_ATTRIBUTE; -# endif +# endif # endif #endif #include <sys/resource.h> @@ -34,7 +34,7 @@ #ifdef __CYGWIN__ DLLIMPORT extern __stdcall unsigned char GetVersionExW(void *); -DLLIMPORT extern __stdcall void *LoadLibraryW(const void *); +DLLIMPORT extern __stdcall void *GetModuleHandleW(const void *); DLLIMPORT extern __stdcall void FreeLibrary(void *); DLLIMPORT extern __stdcall void *GetProcAddress(void *, const char *); DLLIMPORT extern __stdcall void GetSystemInfo(void *); @@ -45,12 +45,12 @@ static const char *const platforms[NUMPLATFORMS] = { }; #define NUMPROCESSORS 11 -static const char *const processors[NUMPROCESSORS] = { +static const char *const processors[NUMPROCESSORS] = { "intel", "mips", "alpha", "ppc", "shx", "arm", "ia64", "alpha64", "msil", "amd64", "ia32_on_win64" }; -typedef struct _SYSTEM_INFO { +typedef struct { union { DWORD dwOemId; struct { @@ -69,7 +69,7 @@ typedef struct _SYSTEM_INFO { int wProcessorRevision; } SYSTEM_INFO; -typedef struct _OSVERSIONINFOW { +typedef struct { DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; DWORD dwMinorVersion; @@ -737,6 +737,43 @@ Tcl_GetEncodingNameFromEnvironment( *---------------------------------------------------------------------- */ +#if defined(HAVE_COREFOUNDATION) && MAC_OS_X_VERSION_MAX_ALLOWED > 1020 +/* + * Helper because whether CFLocaleCopyCurrent and CFLocaleGetIdentifier are + * strongly or weakly bound varies by version of OSX, triggering warnings. + */ + +static inline void +InitMacLocaleInfoVar( + CFLocaleRef (*localeCopyCurrent)(void), + CFStringRef (*localeGetIdentifier)(CFLocaleRef), + Tcl_Interp *interp) +{ + CFLocaleRef localeRef; + CFStringRef locale; + char loc[256]; + + if (localeCopyCurrent == NULL || localeGetIdentifier == NULL) { + return; + } + + localeRef = localeCopyCurrent(); + if (!localeRef) { + return; + } + + locale = localeGetIdentifier(localeRef); + if (locale && CFStringGetCString(locale, loc, 256, + kCFStringEncodingUTF8)) { + if (!Tcl_CreateNamespace(interp, "::tcl::mac", NULL, NULL)) { + Tcl_ResetResult(interp); + } + Tcl_SetVar2(interp, "::tcl::mac::locale", NULL, loc, TCL_GLOBAL_ONLY); + } + CFRelease(localeRef); +} +#endif /*defined(HAVE_COREFOUNDATION) && MAC_OS_X_VERSION_MAX_ALLOWED > 1020*/ + void TclpSetVariables( Tcl_Interp *interp) @@ -755,29 +792,12 @@ TclpSetVariables( #ifdef HAVE_COREFOUNDATION char tclLibPath[MAXPATHLEN + 1]; -#if MAC_OS_X_VERSION_MAX_ALLOWED > 1020 /* * Set msgcat fallback locale to current CFLocale identifier. */ - CFLocaleRef localeRef; - - if (&CFLocaleCopyCurrent != NULL && &CFLocaleGetIdentifier != NULL && - (localeRef = CFLocaleCopyCurrent())) { - CFStringRef locale = CFLocaleGetIdentifier(localeRef); - - if (locale) { - char loc[256]; - - if (CFStringGetCString(locale, loc, 256, kCFStringEncodingUTF8)) { - if (!Tcl_CreateNamespace(interp, "::tcl::mac", NULL, NULL)) { - Tcl_ResetResult(interp); - } - Tcl_SetVar2(interp, "::tcl::mac::locale", NULL, loc, TCL_GLOBAL_ONLY); - } - } - CFRelease(localeRef); - } +#if MAC_OS_X_VERSION_MAX_ALLOWED > 1020 + InitMacLocaleInfoVar(CFLocaleCopyCurrent, CFLocaleGetIdentifier, interp); #endif /* MAC_OS_X_VERSION_MAX_ALLOWED > 1020 */ if (MacOSXGetLibraryPath(interp, MAXPATHLEN, tclLibPath) == TCL_OK) { @@ -858,16 +878,13 @@ TclpSetVariables( #ifdef __CYGWIN__ unameOK = 1; if (!osInfoInitialized) { - HANDLE handle = LoadLibraryW(L"NTDLL"); + HANDLE handle = GetModuleHandleW(L"NTDLL"); int(__stdcall *getversion)(void *) = (int(__stdcall *)(void *))GetProcAddress(handle, "RtlGetVersion"); osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); if (!getversion || getversion(&osInfo)) { GetVersionExW(&osInfo); } - if (handle) { - FreeLibrary(handle); - } osInfoInitialized = 1; } @@ -1025,7 +1042,6 @@ TclpFindVariable( return result; } - /* *---------------------------------------------------------------------- * diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c index e37962d..6b7669d 100644 --- a/unix/tclUnixNotfy.c +++ b/unix/tclUnixNotfy.c @@ -193,7 +193,7 @@ static Tcl_ThreadId notifierThread; */ #ifdef TCL_THREADS -static void NotifierThreadProc(ClientData clientData); +static TCL_NORETURN void NotifierThreadProc(ClientData clientData); #if defined(HAVE_PTHREAD_ATFORK) static int atForkInit = 0; static void AtForkChild(void); @@ -1139,7 +1139,7 @@ Tcl_WaitForEvent( *---------------------------------------------------------------------- */ -static void +static TCL_NORETURN void NotifierThreadProc( ClientData clientData) /* Not used. */ { diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 9387d05..2353f94 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -19,6 +19,7 @@ #define SET_BITS(var, bits) ((var) |= (bits)) #define CLEAR_BITS(var, bits) ((var) &= ~(bits)) +#define GOT_BITS(var, bits) (((var) & (bits)) != 0) /* "sock" + a pointer in hex + \0 */ #define SOCK_CHAN_LENGTH (4 + sizeof(void *) * 2 + 1) @@ -52,6 +53,8 @@ typedef struct TcpFdList { struct TcpState { Tcl_Channel channel; /* Channel associated with this file. */ + int testFlags; /* bit field for tests. Is set by testsocket + * test procedure */ TcpFdList fds; /* The file descriptors of the sockets. */ int flags; /* ORed combination of the bitfields defined * below. */ @@ -93,6 +96,15 @@ struct TcpState { #define TCP_ASYNC_FAILED (1<<5) /* An async connect finally failed */ /* + * These bits may be ORed together into the "testFlags" field of a TcpState + * structure. + */ + +#define TCP_ASYNC_TEST_MODE (1<<0) /* Async testing activated. Do not + * automatically continue connection + * process. */ + +/* * The following defines the maximum length of the listen queue. This is the * number of outstanding yet-to-be-serviced requests for a connection on a * server socket, more than this number of outstanding requests and the @@ -117,8 +129,7 @@ struct TcpState { * Static routines for this file: */ -static int TcpConnect(Tcl_Interp *interp, - TcpState *state); +static int TcpConnect(Tcl_Interp *interp, TcpState *state); static void TcpAccept(ClientData data, int mask); static int TcpBlockModeProc(ClientData data, int mode); static int TcpCloseProc(ClientData instanceData, @@ -173,21 +184,24 @@ static ProcessGlobalValue hostName = #if 0 /* printf debugging */ -void printaddrinfo(struct addrinfo *addrlist, char *prefix) +void +printaddrinfo( + struct addrinfo *addrlist, + char *prefix) { char host[NI_MAXHOST], port[NI_MAXSERV]; struct addrinfo *ai; + for (ai = addrlist; ai != NULL; ai = ai->ai_next) { getnameinfo(ai->ai_addr, ai->ai_addrlen, - host, sizeof(host), - port, sizeof(port), - NI_NUMERICHOST|NI_NUMERICSERV); + host, sizeof(host), port, sizeof(port), + NI_NUMERICHOST|NI_NUMERICSERV); fprintf(stderr,"%s: %s:%s\n", prefix, host, port); } } #endif /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * InitializeHostName -- * @@ -197,7 +211,7 @@ void printaddrinfo(struct addrinfo *addrlist, char *prefix) * Results: * None. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ static void @@ -276,7 +290,7 @@ InitializeHostName( } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * Tcl_GetHostName -- * @@ -290,7 +304,7 @@ InitializeHostName( * Side effects: * Caches the name to return for future calls. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ const char * @@ -300,7 +314,7 @@ Tcl_GetHostName(void) } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TclpHasSockets -- * @@ -312,7 +326,7 @@ Tcl_GetHostName(void) * Side effects: * None. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ int @@ -323,7 +337,7 @@ TclpHasSockets( } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TclpFinalizeSockets -- * @@ -335,7 +349,7 @@ TclpHasSockets( * Side effects: * None. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ void @@ -345,7 +359,7 @@ TclpFinalizeSockets(void) } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TcpBlockModeProc -- * @@ -358,7 +372,7 @@ TclpFinalizeSockets(void) * Side effects: * Sets the device into blocking or nonblocking mode. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /* ARGSUSED */ @@ -376,7 +390,7 @@ TcpBlockModeProc( } else { SET_BITS(statePtr->flags, TCP_NONBLOCKING); } - if (statePtr->flags & TCP_ASYNC_CONNECT) { + if (GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT)) { statePtr->cachedBlocking = mode; return 0; } @@ -387,33 +401,32 @@ TcpBlockModeProc( } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * WaitForConnect -- * - * Check the state of an async connect process. If a connection - * attempt terminated, process it, which may finalize it or may - * start the next attempt. If a connect error occures, it is saved - * in statePtr->connectError to be reported by 'fconfigure -error'. + * Check the state of an async connect process. If a connection attempt + * terminated, process it, which may finalize it or may start the next + * attempt. If a connect error occures, it is saved in + * statePtr->connectError to be reported by 'fconfigure -error'. * * There are two modes of operation, defined by errorCodePtr: - * * non-NULL: Called by explicite read/write command. block if + * * non-NULL: Called by explicite read/write command. Blocks if the * socket is blocking. * May return two error codes: * * EWOULDBLOCK: if connect is still in progress - * * ENOTCONN: if connect failed. This would be the error - * message of a rect or sendto syscall so this is - * emulated here. - * * NULL: Called by a backround operation. Do not block and - * don't return any error code. + * * ENOTCONN: if connect failed. This would be the error message + * of a rect or sendto syscall so this is emulated here. + * * NULL: Called by a backround operation. Do not block and do not + * return any error code. * * Results: - * 0 if the connection has completed, -1 if still in progress - * or there is an error. + * 0 if the connection has completed, -1 if still in progress or there is + * an error. * * Side effects: - * Processes socket events off the system queue. - * May process asynchroneous connect. + * Processes socket events off the system queue. May process + * asynchroneous connects. * *---------------------------------------------------------------------- */ @@ -426,11 +439,11 @@ WaitForConnect( int timeout; /* - * Check if an async connect failed already and error reporting is demanded, - * return the error ENOTCONN + * Check if an async connect failed already and error reporting is + * demanded, return the error ENOTCONN */ - if (errorCodePtr != NULL && (statePtr->flags & TCP_ASYNC_FAILED)) { + if (errorCodePtr != NULL && GOT_BITS(statePtr->flags, TCP_ASYNC_FAILED)) { *errorCodePtr = ENOTCONN; return -1; } @@ -439,26 +452,43 @@ WaitForConnect( * Check if an async connect is running. If not return ok */ - if (!(statePtr->flags & TCP_ASYNC_PENDING)) { + if (!GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING)) { return 0; } - if (errorCodePtr == NULL || (statePtr->flags & TCP_NONBLOCKING)) { + /* + * In socket test mode do not continue with the connect. + * Exceptions are: + * - Call by recv/send and blocking socket + * (errorCodePtr != NULL && !GOT_BITS(flags, TCP_NONBLOCKING)) + */ + + if (GOT_BITS(statePtr->testFlags, TCP_ASYNC_TEST_MODE) + && !(errorCodePtr != NULL + && !GOT_BITS(statePtr->flags, TCP_NONBLOCKING))) { + *errorCodePtr = EWOULDBLOCK; + return -1; + } + + if (errorCodePtr == NULL || GOT_BITS(statePtr->flags, TCP_NONBLOCKING)) { timeout = 0; } else { timeout = -1; } do { if (TclUnixWaitForFile(statePtr->fds.fd, - TCL_WRITABLE | TCL_EXCEPTION, timeout) != 0) { + TCL_WRITABLE | TCL_EXCEPTION, timeout) != 0) { TcpConnect(NULL, statePtr); } - /* Do this only once in the nonblocking case and repeat it until the - * socket is final when blocking */ - } while (timeout == -1 && statePtr->flags & TCP_ASYNC_CONNECT); + + /* + * Do this only once in the nonblocking case and repeat it until the + * socket is final when blocking. + */ + } while (timeout == -1 && GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT)); if (errorCodePtr != NULL) { - if (statePtr->flags & TCP_ASYNC_PENDING) { + if (GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING)) { *errorCodePtr = EAGAIN; return -1; } else if (statePtr->connectError != 0) { @@ -615,6 +645,7 @@ TcpCloseProc( fds = statePtr->fds.next; while (fds != NULL) { TcpFdList *next = fds->next; + ckfree(fds); fds = next; } @@ -685,10 +716,9 @@ TcpClose2Proc( * * TcpHostPortList -- * - * This function is called by the -gethostname and -getpeername - * switches of TcpGetOptionProc() to add three list elements - * with the textual representation of the given address to the - * given DString. + * This function is called by the -gethostname and -getpeername switches + * of TcpGetOptionProc() to add three list elements with the textual + * representation of the given address to the given DString. * * Results: * None. @@ -698,6 +728,33 @@ TcpClose2Proc( * *---------------------------------------------------------------------- */ + +#ifndef NEED_FAKE_RFC2553 +static inline int +IPv6AddressNeedsNumericRendering( + struct in6_addr addr) +{ + if (IN6_ARE_ADDR_EQUAL(&addr, &in6addr_any)) { + return 1; + } + + /* + * The IN6_IS_ADDR_V4MAPPED macro has a problem with aliasing warnings on + * at least some versions of OSX. + */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" + if (!IN6_IS_ADDR_V4MAPPED(&addr)) { +#pragma GCC diagnostic pop + return 0; + } + + return (addr.s6_addr[12] == 0 && addr.s6_addr[13] == 0 + && addr.s6_addr[14] == 0 && addr.s6_addr[15] == 0); +} +#endif /* NEED_FAKE_RFC2553 */ + static void TcpHostPortList( Tcl_Interp *interp, @@ -709,40 +766,47 @@ TcpHostPortList( char host[NI_MAXHOST], nhost[NI_MAXHOST], nport[NI_MAXSERV]; int flags = 0; - getnameinfo(&addr.sa, salen, - nhost, sizeof(nhost), nport, sizeof(nport), - NI_NUMERICHOST | NI_NUMERICSERV); + getnameinfo(&addr.sa, salen, nhost, sizeof(nhost), nport, sizeof(nport), + NI_NUMERICHOST | NI_NUMERICSERV); Tcl_DStringAppendElement(dsPtr, nhost); + /* - * We don't want to resolve INADDR_ANY and sin6addr_any; they - * can sometimes cause problems (and never have a name). + * We don't want to resolve INADDR_ANY and sin6addr_any; they can + * sometimes cause problems (and never have a name). */ + if (addr.sa.sa_family == AF_INET) { if (addr.sa4.sin_addr.s_addr == INADDR_ANY) { flags |= NI_NUMERICHOST; } #ifndef NEED_FAKE_RFC2553 } else if (addr.sa.sa_family == AF_INET6) { - if ((IN6_ARE_ADDR_EQUAL(&addr.sa6.sin6_addr, - &in6addr_any)) - || (IN6_IS_ADDR_V4MAPPED(&addr.sa6.sin6_addr) && - addr.sa6.sin6_addr.s6_addr[12] == 0 && - addr.sa6.sin6_addr.s6_addr[13] == 0 && - addr.sa6.sin6_addr.s6_addr[14] == 0 && - addr.sa6.sin6_addr.s6_addr[15] == 0)) { + if (IPv6AddressNeedsNumericRendering(addr.sa6.sin6_addr)) { flags |= NI_NUMERICHOST; } #endif /* NEED_FAKE_RFC2553 */ } - /* Check if reverse DNS has been switched off globally */ - if (interp != NULL && Tcl_GetVar2(interp, SUPPRESS_RDNS_VAR, NULL, 0) != NULL) { + + /* + * Check if reverse DNS has been switched off globally. + */ + + if (interp != NULL && + Tcl_GetVar2(interp, SUPPRESS_RDNS_VAR, NULL, 0) != NULL) { flags |= NI_NUMERICHOST; } - if (getnameinfo(&addr.sa, salen, host, sizeof(host), NULL, 0, flags) == 0) { - /* Reverse mapping worked */ + if (getnameinfo(&addr.sa, salen, host, sizeof(host), NULL, 0, + flags) == 0) { + /* + * Reverse mapping worked. + */ + Tcl_DStringAppendElement(dsPtr, host); } else { - /* Reverse mappong failed - use the numeric rep once more */ + /* + * Reverse mapping failed - use the numeric rep once more. + */ + Tcl_DStringAppendElement(dsPtr, nhost); } Tcl_DStringAppendElement(dsPtr, nport); @@ -792,16 +856,20 @@ TcpGetOptionProc( (strncmp(optionName, "-error", len) == 0)) { socklen_t optlen = sizeof(int); - if (statePtr->flags & TCP_ASYNC_CONNECT) { - /* Suppress errors as long as we are not done */ + if (GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT)) { + /* + * Suppress errors as long as we are not done. + */ + errno = 0; } else if (statePtr->connectError != 0) { errno = statePtr->connectError; statePtr->connectError = 0; } else { int err; - getsockopt(statePtr->fds.fd, SOL_SOCKET, SO_ERROR, - (char *) &err, &optlen); + + getsockopt(statePtr->fds.fd, SOL_SOCKET, SO_ERROR, (char *) &err, + &optlen); errno = err; } if (errno != 0) { @@ -812,9 +880,8 @@ TcpGetOptionProc( if ((len > 1) && (optionName[1] == 'c') && (strncmp(optionName, "-connecting", len) == 0)) { - Tcl_DStringAppend(dsPtr, - (statePtr->flags & TCP_ASYNC_CONNECT) ? "1" : "0", -1); + GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT) ? "1" : "0", -1); return TCL_OK; } @@ -823,10 +890,11 @@ TcpGetOptionProc( address peername; socklen_t size = sizeof(peername); - if ( (statePtr->flags & TCP_ASYNC_CONNECT) ) { + if (GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT)) { /* * In async connect output an empty string */ + if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-peername"); Tcl_DStringAppendElement(dsPtr, ""); @@ -837,6 +905,7 @@ TcpGetOptionProc( /* * Peername fetch succeeded - output list */ + if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-peername"); Tcl_DStringStartSublist(dsPtr); @@ -876,11 +945,12 @@ TcpGetOptionProc( Tcl_DStringAppendElement(dsPtr, "-sockname"); Tcl_DStringStartSublist(dsPtr); } - if ( (statePtr->flags & TCP_ASYNC_CONNECT) ) { + if (GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT)) { /* * In async connect output an empty string */ - found = 1; + + found = 1; } else { for (fds = &statePtr->fds; fds != NULL; fds = fds->next) { size = sizeof(sockname); @@ -905,14 +975,15 @@ TcpGetOptionProc( } if (len > 0) { - return Tcl_BadChannelOption(interp, optionName, "connecting peername sockname"); + return Tcl_BadChannelOption(interp, optionName, + "connecting peername sockname"); } return TCL_OK; } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TcpWatchProc -- * @@ -925,7 +996,7 @@ TcpGetOptionProc( * Sets up the notifier so that a future event on the channel will be * seen by Tcl. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ static void @@ -938,17 +1009,17 @@ WrapNotify( if (newmask == 0) { /* - * There was no overlap between the states the channel is - * interested in notifications for, and the states that are - * reported present on the file descriptor by select(). The - * only way that can happen is when the channel is interested - * in a writable condition, and only a readable state is reported - * present (see TcpWatchProc() below). In that case, signal back - * to the caller the writable state, which is really an error - * condition. As an extra check on that assumption, check for - * a non-zero value of errno before reporting an artificial + * There was no overlap between the states the channel is interested + * in notifications for, and the states that are reported present on + * the file descriptor by select(). The only way that can happen is + * when the channel is interested in a writable condition, and only a + * readable state is reported present (see TcpWatchProc() below). In + * that case, signal back to the caller the writable state, which is + * really an error condition. As an extra check on that assumption, + * check for a non-zero value of errno before reporting an artificial * writable state. */ + if (errno == 0) { return; } @@ -972,33 +1043,36 @@ TcpWatchProc( * be readable or writable at the Tcl level. This keeps Tcl scripts * from interfering with the -accept behavior (bug #3394732). */ + return; } - if (statePtr->flags & TCP_ASYNC_PENDING) { - /* Async sockets use a FileHandler internally while connecting, so we - * need to cache this request until the connection has succeeded. */ + if (GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING)) { + /* + * Async sockets use a FileHandler internally while connecting, so we + * need to cache this request until the connection has succeeded. + */ + statePtr->filehandlers = mask; } else if (mask) { /* - * Whether it is a bug or feature or otherwise, it is a fact - * of life that on at least some Linux kernels select() fails - * to report that a socket file descriptor is writable when - * the other end of the socket is closed. This is in contrast - * to the guarantees Tcl makes that its channels become - * writable and fire writable events on an error conditon. - * This has caused a leak of file descriptors in a state of + * Whether it is a bug or feature or otherwise, it is a fact of life + * that on at least some Linux kernels select() fails to report that a + * socket file descriptor is writable when the other end of the socket + * is closed. This is in contrast to the guarantees Tcl makes that + * its channels become writable and fire writable events on an error + * conditon. This has caused a leak of file descriptors in a state of * background flushing. See Tcl ticket 1758a0b603. * - * As a workaround, when our caller indicates an interest in - * writable notifications, we must tell the notifier built - * around select() that we are interested in the readable state - * of the file descriptor as well, as that is the only reliable - * means to get notified of error conditions. Then it is the - * task of WrapNotify() above to untangle the meaning of these - * channel states and report the chan events as best it can. - * We save a copy of the mask passed in to assist with that. + * As a workaround, when our caller indicates an interest in writable + * notifications, we must tell the notifier built around select() that + * we are interested in the readable state of the file descriptor as + * well, as that is the only reliable means to get notified of error + * conditions. Then it is the task of WrapNotify() above to untangle + * the meaning of these channel states and report the chan events as + * best it can. We save a copy of the mask passed in to assist with + * that. */ statePtr->interest = mask; @@ -1010,7 +1084,7 @@ TcpWatchProc( } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TcpGetHandleProc -- * @@ -1024,7 +1098,7 @@ TcpWatchProc( * Side effects: * None. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ /* ARGSUSED */ @@ -1041,16 +1115,17 @@ TcpGetHandleProc( } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TcpAsyncCallback -- * - * Called by the event handler that TcpConnect sets up - * internally for [socket -async] to get notified when the - * asyncronous connection attempt has succeeded or failed. + * Called by the event handler that TcpConnect sets up internally for + * [socket -async] to get notified when the asyncronous connection + * attempt has succeeded or failed. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ + static void TcpAsyncCallback( ClientData clientData, /* The socket state. */ @@ -1062,7 +1137,7 @@ TcpAsyncCallback( } /* - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- * * TcpConnect -- * @@ -1088,7 +1163,7 @@ TcpAsyncCallback( * return and the loops resume as if they had never been interrupted. * For syncronously connecting sockets, the loops work the usual way. * - *---------------------------------------------------------------------- + * ---------------------------------------------------------------------- */ static int @@ -1097,9 +1172,9 @@ TcpConnect( TcpState *statePtr) { socklen_t optlen; - int async_callback = statePtr->flags & TCP_ASYNC_PENDING; + int async_callback = GOT_BITS(statePtr->flags, TCP_ASYNC_PENDING); int ret = -1, error = EHOSTUNREACH; - int async = statePtr->flags & TCP_ASYNC_CONNECT; + int async = GOT_BITS(statePtr->flags, TCP_ASYNC_CONNECT); if (async_callback) { goto reenter; @@ -1107,8 +1182,8 @@ TcpConnect( for (statePtr->addr = statePtr->addrlist; statePtr->addr != NULL; statePtr->addr = statePtr->addr->ai_next) { - - for (statePtr->myaddr = statePtr->myaddrlist; statePtr->myaddr != NULL; + for (statePtr->myaddr = statePtr->myaddrlist; + statePtr->myaddr != NULL; statePtr->myaddr = statePtr->myaddr->ai_next) { int reuseaddr = 1; @@ -1132,7 +1207,8 @@ TcpConnect( errno = 0; } - statePtr->fds.fd = socket(statePtr->addr->ai_family, SOCK_STREAM, 0); + statePtr->fds.fd = socket(statePtr->addr->ai_family, SOCK_STREAM, + 0); if (statePtr->fds.fd < 0) { continue; } @@ -1151,14 +1227,18 @@ TcpConnect( TclSockMinimumBuffers(INT2PTR(statePtr->fds.fd), SOCKET_BUFSIZE); if (async) { - ret = TclUnixSetBlockingMode(statePtr->fds.fd,TCL_MODE_NONBLOCKING); + ret = TclUnixSetBlockingMode(statePtr->fds.fd, + TCL_MODE_NONBLOCKING); if (ret < 0) { continue; } } - /* Gotta reset the error variable here, before we use it for the - * first time in this iteration. */ + /* + * Must reset the error variable here, before we use it for the + * first time in this iteration. + */ + error = 0; (void) setsockopt(statePtr->fds.fd, SOL_SOCKET, SO_REUSEADDR, @@ -1179,10 +1259,13 @@ TcpConnect( ret = connect(statePtr->fds.fd, statePtr->addr->ai_addr, statePtr->addr->ai_addrlen); - if (ret < 0) error = errno; + if (ret < 0) { + error = errno; + } if (ret < 0 && errno == EINPROGRESS) { Tcl_CreateFileHandler(statePtr->fds.fd, - TCL_WRITABLE|TCL_EXCEPTION, TcpAsyncCallback, statePtr); + TCL_WRITABLE | TCL_EXCEPTION, TcpAsyncCallback, + statePtr); errno = EWOULDBLOCK; SET_BITS(statePtr->flags, TCP_ASYNC_PENDING); return TCL_OK; @@ -1210,7 +1293,7 @@ TcpConnect( } } -out: + out: statePtr->connectError = error; CLEAR_BITS(statePtr->flags, TCP_ASYNC_CONNECT); if (async_callback) { @@ -1308,6 +1391,7 @@ Tcl_OpenTcpClient( /* * Allocate a new TcpState for this socket. */ + statePtr = ckalloc(sizeof(TcpState)); memset(statePtr, 0, sizeof(TcpState)); statePtr->flags = async ? TCP_ASYNC_CONNECT : 0; @@ -1319,6 +1403,7 @@ Tcl_OpenTcpClient( /* * Create a new client socket and wrap it in a channel. */ + if (TcpConnect(interp, statePtr) != TCL_OK) { TcpCloseProc(statePtr, NULL); return NULL; @@ -1326,8 +1411,8 @@ Tcl_OpenTcpClient( sprintf(channelName, SOCK_TEMPLATE, (long) statePtr); - statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, statePtr, - (TCL_READABLE | TCL_WRITABLE)); + statePtr->channel = Tcl_CreateChannel(&tcpChannelType, channelName, + statePtr, TCL_READABLE | TCL_WRITABLE); if (Tcl_SetChannelOption(interp, statePtr->channel, "-translation", "auto crlf") == TCL_ERROR) { Tcl_Close(NULL, statePtr->channel); @@ -1356,7 +1441,8 @@ Tcl_Channel Tcl_MakeTcpClientChannel( ClientData sock) /* The socket to wrap up into a channel. */ { - return (Tcl_Channel) TclpMakeTcpClientChannelMode(sock, (TCL_READABLE | TCL_WRITABLE)); + return (Tcl_Channel) TclpMakeTcpClientChannelMode(sock, + TCL_READABLE | TCL_WRITABLE); } /* @@ -1456,6 +1542,7 @@ Tcl_OpenTcpServerEx( * families. We try this at most MAXRETRY times to avoid an endless loop * if all ports are taken. */ + int retry = 0; #define MAXRETRY 10 @@ -1481,7 +1568,8 @@ Tcl_OpenTcpServerEx( goto error; } - if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) { + if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, + &errorMsg)) { my_errno = errno; goto error; } @@ -1514,24 +1602,25 @@ Tcl_OpenTcpServerEx( * Set up to reuse server addresses and/or ports if requested. */ - if (flags & TCL_TCPSERVER_REUSEADDR) { + if (GOT_BITS(flags, TCL_TCPSERVER_REUSEADDR)) { optvalue = 1; (void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - (char *) &optvalue, sizeof(optvalue)); + (char *) &optvalue, sizeof(optvalue)); } - if (flags & TCL_TCPSERVER_REUSEPORT) { + if (GOT_BITS(flags, TCL_TCPSERVER_REUSEPORT)) { #ifndef SO_REUSEPORT /* - * If the platform doesn't support the SO_REUSEPORT flag we can't do - * much beside erroring out. + * If the platform doesn't support the SO_REUSEPORT flag we can't + * do much beside erroring out. */ + errorMsg = "SO_REUSEPORT isn't supported by this platform"; goto error; #else optvalue = 1; (void) setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, - (char *) &optvalue, sizeof(optvalue)); + (char *) &optvalue, sizeof(optvalue)); #endif } @@ -1549,7 +1638,10 @@ Tcl_OpenTcpServerEx( } #ifdef IPV6_V6ONLY - /* Missing on: Solaris 2.8 */ + /* + * Missing on: Solaris 2.8 + */ + if (addrPtr->ai_family == AF_INET6) { int v6only = 1; @@ -1701,7 +1793,7 @@ TcpAccept( sprintf(channelName, SOCK_TEMPLATE, (long) newSockState); newSockState->channel = Tcl_CreateChannel(&tcpChannelType, channelName, - newSockState, (TCL_READABLE | TCL_WRITABLE)); + newSockState, TCL_READABLE | TCL_WRITABLE); Tcl_SetChannelOption(NULL, newSockState->channel, "-translation", "auto crlf"); diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c index 805599d..f475aed 100644 --- a/unix/tclUnixThrd.c +++ b/unix/tclUnixThrd.c @@ -644,6 +644,7 @@ TclpFinalizeCondition( *---------------------------------------------------------------------- */ +#ifndef TCL_NO_DEPRECATED Tcl_DirEntry * TclpReaddir( DIR * dir) @@ -666,6 +667,7 @@ TclpInetNtoa( return inet_ntoa(addr); #endif } +#endif /* TCL_NO_DEPRECATED */ #ifdef TCL_THREADS /* diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c index 8ec6e8a..d95d39b 100644 --- a/unix/tclUnixTime.c +++ b/unix/tclUnixTime.c @@ -22,6 +22,7 @@ * variable is the key to this buffer. */ +#ifndef TCL_NO_DEPRECATED static Tcl_ThreadDataKey tmKey; typedef struct { struct tm gmtime_buf; @@ -45,6 +46,8 @@ static char *lastTZ = NULL; /* Holds the last setting of the TZ static void SetTZIfNecessary(void); static void CleanupMemory(ClientData clientData); +#endif /* TCL_NO_DEPRECATED */ + static void NativeScaleTime(Tcl_Time *timebuf, ClientData clientData); static void NativeGetTime(Tcl_Time *timebuf, @@ -334,6 +337,7 @@ Tcl_GetTime( *---------------------------------------------------------------------- */ +#ifndef TCL_NO_DEPRECATED struct tm * TclpGetDate( const time_t *time, @@ -423,6 +427,7 @@ TclpLocaltime( return &tsdPtr->localtime_buf; } +#endif /* TCL_NO_DEPRECATED */ /* *---------------------------------------------------------------------- @@ -557,6 +562,7 @@ NativeGetTime( *---------------------------------------------------------------------- */ +#ifndef TCL_NO_DEPRECATED static void SetTZIfNecessary(void) { @@ -602,6 +608,7 @@ CleanupMemory( { ckfree(lastTZ); } +#endif /* TCL_NO_DEPRECATED */ /* * Local Variables: |