diff -r 1a4cf44b1ada -r f8f21ccd46d5 UnixOperatingSystem.st --- a/UnixOperatingSystem.st Wed May 09 14:19:22 2018 +0200 +++ b/UnixOperatingSystem.st Wed May 09 14:27:09 2018 +0200 @@ -10184,7 +10184,7 @@ #endif %}. seconds notNil ifTrue:[ - ^ { ((seconds * 1000) + millis) . micros } + ^ { ((seconds * 1000) + millis) . micros } ]. self primitiveFailed. @@ -10196,6 +10196,58 @@ " ! +getOSTimeWithNanos + "This returns the OS time as a 2-element vector with milliseconds (as before) + plus nanoseconds. + The base of the returned value is not consistent across + different OS's - some return the number of microseconds since jan, 1st 1970; + others since 1900. The Time classes are prepared for this, and + converts as appropriate (by using my fromOSTime: conversion methods). + + Don't use this method in application code since it is an internal (private) + interface. For compatibility with ST-80, use Time>>millisecondClockValue. + or use instances of Time, Date or Timestamp to work with." + + + |seconds millis nanos| + +%{ +# if (_POSIX_C_SOURCE >= 199309L) && defined(CLOCK_REALTIME) && !defined(NO_CLOCK_GETTIME) + struct timespec ts; + static int has_clock_gettime = 1; + unsigned long _secs, _millis, _nanos; + + if (has_clock_gettime) { + if (clock_gettime(CLOCK_REALTIME, &ts) != -1) { + _secs = ts.tv_sec; + _millis = ts.tv_nsec / 1000000; + _nanos = ts.tv_nsec % 1000000; + + seconds = __MKUINT(_secs); + millis = __MKUINT(_millis); + nanos = __MKUINT(_nanos); + } else { + /* + * clock_gettime is not implemented in the kernel + * fall through to alternative implementation + */ + has_clock_gettime = 0; + } + } +# endif +%}. + seconds notNil ifTrue:[ + ^ { ((seconds * 1000) + millis) . nanos } + ]. + ^ super getOSTimeInNanos + + " + OperatingSystem getOSTimeInNanos printCR. + Delay waitForSeconds:0.1. + OperatingSystem getOSTimeInNanos printCR. + " +! + getRealNanosecondTime "This returns the microsecond timers value - if available. On some machines, times with this precision may not be available, @@ -10943,7 +10995,7 @@ If blocking is true, we wait until a process changed state, otherwise we return immediately. - If implementations uses waitpid() and pidToWaitForOrNil is an integer, + If implementations uses waitpid() and pidToWaitForOrNil is an integer, only wait for childProcesses with pid pidToWaitForOrNil. If implementation uses the obsolete wait3() or the very obsolete wait() @@ -10962,10 +11014,10 @@ pid_t _pidToWaitFor = -1; if (__isSmallInteger(pidToWaitForOrNil)) { - _pidToWaitFor = __intVal(pidToWaitForOrNil); + _pidToWaitFor = __intVal(pidToWaitForOrNil); } else if (pidToWaitForOrNil != nil) { - error = @symbol(badArgument2); - goto done; + error = @symbol(badArgument2); + goto done; } # define __WAIT waitpid(_pidToWaitFor, &waitStatus, blocking == true ? WUNTRACED : WNOHANG|WUNTRACED) @@ -10980,11 +11032,11 @@ # define __BLOCKING_WAIT__ 1 if (blocking != true) { - /* - * We do not support nonBlocking waits, so signal an error - * Sorry about the goto, but with all these ifdefs ... - */ - goto done; + /* + * We do not support nonBlocking waits, so signal an error + * Sorry about the goto, but with all these ifdefs ... + */ + goto done; } #endif /* !HAS_WAIT3 */ @@ -11014,7 +11066,7 @@ #endif do { - _pid = __WAIT; + _pid = __WAIT; } while (_pid == -1 && errno == EINTR); #if __BLOCKING_WAIT__ @@ -11025,35 +11077,35 @@ #undef __WAIT if (_pid == 0) - RETURN(nil) + RETURN(nil) if (_pid == -1) { - if (errno == ECHILD) - RETURN(nil); + if (errno == ECHILD) + RETURN(nil); } else { - pid = __mkSmallInteger(_pid); - if (WIFEXITED(waitStatus)) { - status = @symbol(exit); - code = __mkSmallInteger(WEXITSTATUS(waitStatus)); - core = WCOREDUMP(waitStatus) ? true : false; - } else if (WIFSIGNALED(waitStatus)) { - status = @symbol(signal); - code = __mkSmallInteger(WTERMSIG(waitStatus)); - } else if (WIFSTOPPED(waitStatus)) { - status = @symbol(stop); - code = __mkSmallInteger(WSTOPSIG(waitStatus)); - } + pid = __mkSmallInteger(_pid); + if (WIFEXITED(waitStatus)) { + status = @symbol(exit); + code = __mkSmallInteger(WEXITSTATUS(waitStatus)); + core = WCOREDUMP(waitStatus) ? true : false; + } else if (WIFSIGNALED(waitStatus)) { + status = @symbol(signal); + code = __mkSmallInteger(WTERMSIG(waitStatus)); + } else if (WIFSTOPPED(waitStatus)) { + status = @symbol(stop); + code = __mkSmallInteger(WSTOPSIG(waitStatus)); + } #if defined(WIFCONTINUED) - else if (WIFCONTINUED(waitStatus)) { - status = @symbol(continue); - } + else if (WIFCONTINUED(waitStatus)) { + status = @symbol(continue); + } #endif } done: ; %}. (status isNil or:[pid isNil]) ifTrue:[ - ^ self primitiveFailed:error + ^ self primitiveFailed:error ]. "/ Transcript show:'pid: '; show:pid; show:' status: '; show:status; @@ -11160,9 +11212,9 @@ ! selectOnAnyReadable:readFdArray writable:writeFdArray exception:exceptFdArray - readableInto:readableResultFdArray writableInto:writableResultFdArray - exceptionInto:exceptionResultFdArray - withTimeOut:millis + readableInto:readableResultFdArray writableInto:writableResultFdArray + exceptionInto:exceptionResultFdArray + withTimeOut:millis "wait for any fd in readFdArray (an Array of integers) to become ready for reading, writeFdArray to become ready for writing, @@ -11192,32 +11244,32 @@ int numFds = 0; if (readableResultFdArray != nil) { - if (! __isArrayLike(readableResultFdArray)) { - goto fail; - } - resultSizeReadable = __arraySize(readableResultFdArray); + if (! __isArrayLike(readableResultFdArray)) { + goto fail; + } + resultSizeReadable = __arraySize(readableResultFdArray); } if (writableResultFdArray != nil) { - if (! __isArrayLike(writableResultFdArray)) { - goto fail; - } - resultSizeWritable = __arraySize(writableResultFdArray); - if (readableResultFdArray == writableResultFdArray) { - // allow common result set for read/write/except - pcntW = &cntR; - } + if (! __isArrayLike(writableResultFdArray)) { + goto fail; + } + resultSizeWritable = __arraySize(writableResultFdArray); + if (readableResultFdArray == writableResultFdArray) { + // allow common result set for read/write/except + pcntW = &cntR; + } } if (exceptionResultFdArray != nil) { - if (! __isArrayLike(exceptionResultFdArray)) { - goto fail; - } - resultSizeException = __arraySize(exceptionResultFdArray); - if (exceptionResultFdArray == readableResultFdArray) { - // allow common result set for read/write/except - pcntE = &cntR; - } else if (exceptionResultFdArray == writableResultFdArray) { - pcntE = &cntW; - } + if (! __isArrayLike(exceptionResultFdArray)) { + goto fail; + } + resultSizeException = __arraySize(exceptionResultFdArray); + if (exceptionResultFdArray == readableResultFdArray) { + // allow common result set for read/write/except + pcntE = &cntR; + } else if (exceptionResultFdArray == writableResultFdArray) { + pcntE = &cntW; + } } FD_ZERO(&rset); @@ -11226,109 +11278,109 @@ maxF = -1; if (readFdArray != nil) { - int i, count; - - if (! __isArrayLike(readFdArray)) { - goto fail; - } - count = __arraySize(readFdArray); - - for (i=0; i maxF) maxF = f; - numFds++; - } else { - if (@global(InfoPrinting) == true) { - fprintf(stderr, "OS [warning]: huge read-fd (0x%lx) given to select\n", (unsigned long)fd); - } - } - } - } - } + int i, count; + + if (! __isArrayLike(readFdArray)) { + goto fail; + } + count = __arraySize(readFdArray); + + for (i=0; i maxF) maxF = f; + numFds++; + } else { + if (@global(InfoPrinting) == true) { + fprintf(stderr, "OS [warning]: huge read-fd (0x%lx) given to select\n", (unsigned long)fd); + } + } + } + } + } } if (writeFdArray != nil) { - int i, count; - - if (! __isArrayLike(writeFdArray)) { - goto fail; - } - count = __arraySize(writeFdArray); - for (i=0; i maxF) maxF = f; - numFds++; - } else { - if (@global(InfoPrinting) == true) { - fprintf(stderr, "OS [warning]: huge write-fd (0x%lx) given to select\n", (unsigned long)fd); - } - } - } - } - } + int i, count; + + if (! __isArrayLike(writeFdArray)) { + goto fail; + } + count = __arraySize(writeFdArray); + for (i=0; i maxF) maxF = f; + numFds++; + } else { + if (@global(InfoPrinting) == true) { + fprintf(stderr, "OS [warning]: huge write-fd (0x%lx) given to select\n", (unsigned long)fd); + } + } + } + } + } } if (exceptFdArray != nil) { - int i, count; - - if (! __isArrayLike(exceptFdArray)) { - goto fail; - } - count = __arraySize(exceptFdArray); - for (i=0; i maxF) maxF = f; - numFds++; - } else { - if (@global(InfoPrinting) == true) { - fprintf(stderr, "OS [warning]: huge except-fd (0x%lx) given to select\n", (unsigned long)fd); - } - } - } - } - } + int i, count; + + if (! __isArrayLike(exceptFdArray)) { + goto fail; + } + count = __arraySize(exceptFdArray); + for (i=0; i maxF) maxF = f; + numFds++; + } else { + if (@global(InfoPrinting) == true) { + fprintf(stderr, "OS [warning]: huge except-fd (0x%lx) given to select\n", (unsigned long)fd); + } + } + } + } + } } if (millis == nil) { - wtp = NULL; // wait forever + wtp = NULL; // wait forever } else if (__isSmallInteger(millis)) { - __millis = __intVal(millis); - if (__millis > 0) { - wt.tv_sec = __millis / 1000; - wt.tv_usec = (__millis % 1000) * 1000; - } else { - wt.tv_sec = wt.tv_usec = 0; - } - wtp = &wt; + __millis = __intVal(millis); + if (__millis > 0) { + wt.tv_sec = __millis / 1000; + wt.tv_usec = (__millis % 1000) * 1000; + } else { + wt.tv_sec = wt.tv_usec = 0; + } + wtp = &wt; } else { - goto fail; + goto fail; } /* @@ -11336,84 +11388,84 @@ * However, we must then care for moved objects. */ if (wtp == NULL) { - /* - * wait forever - there is no timeout time, we can stay here interruptable. - */ - __BEGIN_INTERRUPTABLE__ - do { - ret = select(maxF+1, &rset, &wset, &eset, NULL); - } while ((ret < 0) && (errno == EINTR)); - __END_INTERRUPTABLE__ + /* + * wait forever - there is no timeout time, we can stay here interruptable. + */ + __BEGIN_INTERRUPTABLE__ + do { + ret = select(maxF+1, &rset, &wset, &eset, NULL); + } while ((ret < 0) && (errno == EINTR)); + __END_INTERRUPTABLE__ } else if (__millis == 0) { - /* - * just poll, no interrupt processing. - */ - do { - ret = select(maxF+1, &rset, &wset, &eset, wtp); - } while ((ret < 0) && (errno == EINTR)); + /* + * just poll, no interrupt processing. + */ + do { + ret = select(maxF+1, &rset, &wset, &eset, wtp); + } while ((ret < 0) && (errno == EINTR)); } else { - __BEGIN_INTERRUPTABLE__ - do { - ret = select(maxF+1, &rset, &wset, &eset, wtp); - /* - * for now: don't loop; if we did, we had to adjust the vt-timeval; - * could otherwise stay in this loop forever ... - * Premature ret (before the time expired) must be handled by the caller. - * A good solution is to update the wt-timeval and redo the select. - */ - } while (0 /* (ret < 0) && (errno == EINTR) */ ); - __END_INTERRUPTABLE__ + __BEGIN_INTERRUPTABLE__ + do { + ret = select(maxF+1, &rset, &wset, &eset, wtp); + /* + * for now: don't loop; if we did, we had to adjust the vt-timeval; + * could otherwise stay in this loop forever ... + * Premature ret (before the time expired) must be handled by the caller. + * A good solution is to update the wt-timeval and redo the select. + */ + } while (0 /* (ret < 0) && (errno == EINTR) */ ); + __END_INTERRUPTABLE__ } if (ret > 0) { - OBJ *__resultR = (resultSizeReadable > 0) ? (__arrayVal(readableResultFdArray)) : 0; - OBJ *__resultW = (resultSizeWritable > 0) ? (__arrayVal(writableResultFdArray)) : 0; - OBJ *__resultE = (resultSizeException > 0) ? (__arrayVal(exceptionResultFdArray)) : 0; - int i; - - for (i=0; i <= maxF; i++) { - if (FD_ISSET(i, &rset)) { - if (*pcntR < resultSizeReadable) { - __resultR[*pcntR] = __mkSmallInteger(i); - } - (*pcntR)++; cntAll++; - } - - if (FD_ISSET(i, &wset)) { - if (*pcntW < resultSizeWritable) { - __resultW[*pcntW] = __mkSmallInteger(i); - } - (*pcntW)++; cntAll++; - } - - if (FD_ISSET(i, &eset)) { - if (*pcntE < resultSizeException) { - __resultE[*pcntE] = __mkSmallInteger(i); - } - (*pcntE)++; cntAll++; - } - } - /* add a delimiter */ - if (*pcntR < resultSizeReadable) { - __resultR[*pcntR] = nil; - } - if (*pcntW < resultSizeWritable) { - __resultW[*pcntW] = nil; - } - if (*pcntE < resultSizeException) { - __resultE[*pcntE] = nil; - } - - RETURN (__mkSmallInteger(cntAll)); + OBJ *__resultR = (resultSizeReadable > 0) ? (__arrayVal(readableResultFdArray)) : 0; + OBJ *__resultW = (resultSizeWritable > 0) ? (__arrayVal(writableResultFdArray)) : 0; + OBJ *__resultE = (resultSizeException > 0) ? (__arrayVal(exceptionResultFdArray)) : 0; + int i; + + for (i=0; i <= maxF; i++) { + if (FD_ISSET(i, &rset)) { + if (*pcntR < resultSizeReadable) { + __resultR[*pcntR] = __mkSmallInteger(i); + } + (*pcntR)++; cntAll++; + } + + if (FD_ISSET(i, &wset)) { + if (*pcntW < resultSizeWritable) { + __resultW[*pcntW] = __mkSmallInteger(i); + } + (*pcntW)++; cntAll++; + } + + if (FD_ISSET(i, &eset)) { + if (*pcntE < resultSizeException) { + __resultE[*pcntE] = __mkSmallInteger(i); + } + (*pcntE)++; cntAll++; + } + } + /* add a delimiter */ + if (*pcntR < resultSizeReadable) { + __resultR[*pcntR] = nil; + } + if (*pcntW < resultSizeWritable) { + __resultW[*pcntW] = nil; + } + if (*pcntE < resultSizeException) { + __resultE[*pcntE] = nil; + } + + RETURN (__mkSmallInteger(cntAll)); } else if (ret < 0 && errno != EINTR) { - /* - * Error: Return -1 - */ - if (@global(InfoPrinting) == true) { - fprintf(stderr, "OS [info]: select errno = %d\n", errno); - } - @global(LastErrorNumber) = __mkSmallInteger(errno); - RETURN (__mkSmallInteger(-1)); + /* + * Error: Return -1 + */ + if (@global(InfoPrinting) == true) { + fprintf(stderr, "OS [info]: select errno = %d\n", errno); + } + @global(LastErrorNumber) = __mkSmallInteger(errno); + RETURN (__mkSmallInteger(-1)); } /* @@ -12219,10 +12271,10 @@ With 0 as timeout argument, this can be used to check for availability (poll) of read-data." - ^ (OperatingSystem - selectOnAnyReadable:(Array with:fd) writable:nil exception:nil - readableInto:nil writableInto:nil exceptionInto:nil - withTimeOut:millis) ~~ 0. + ^ (OperatingSystem + selectOnAnyReadable:(Array with:fd) writable:nil exception:nil + readableInto:nil writableInto:nil exceptionInto:nil + withTimeOut:millis) ~~ 0. "Created: / 01-10-1997 / 08:51:11 / stefan" "Modified (comment): / 03-05-2018 / 14:59:08 / stefan" @@ -12320,27 +12372,27 @@ %{ if (__isSmallInteger(__INST(fd))) { - int fd = __smallIntegerVal(__INST(fd)); - - /* - * if available, try FIONREAD first, which is usually done faster. - */ + int fd = __smallIntegerVal(__INST(fd)); + + /* + * if available, try FIONREAD first, which is usually done faster. + */ # ifdef FIONREAD - { - int result = 0; - - if (ioctl(fd, FIONREAD, &result) >= 0) { - RETURN(result > 0 ? true : false); - } - } + { + int result = 0; + + if (ioctl(fd, FIONREAD, &result) >= 0) { + RETURN(result > 0 ? true : false); + } + } # endif /* FIONREAD */ } %}. - ^ (OperatingSystem - selectOnAnyReadable:(Array with:fd) writable:nil exception:nil - readableInto:nil writableInto:nil exceptionInto:nil - withTimeOut:0) ~~ 0. + ^ (OperatingSystem + selectOnAnyReadable:(Array with:fd) writable:nil exception:nil + readableInto:nil writableInto:nil exceptionInto:nil + withTimeOut:0) ~~ 0. " |h n| @@ -12364,10 +12416,10 @@ canWriteWithoutBlocking "return true, if filedescriptor can be written without blocking" - ^ (OperatingSystem - selectOnAnyReadable:nil writable:(Array with:fd) exception:nil - readableInto:nil writableInto:nil exceptionInto:nil - withTimeOut:0) ~~ 0. + ^ (OperatingSystem + selectOnAnyReadable:nil writable:(Array with:fd) exception:nil + readableInto:nil writableInto:nil exceptionInto:nil + withTimeOut:0) ~~ 0. "Modified: / 03-05-2018 / 14:54:51 / stefan" ! @@ -12466,20 +12518,20 @@ fd isNil ifTrue:[^ self error:#errorNotOpen]. self canReadWithoutBlocking ifTrue:[ - ^ false. + ^ false. ]. wasBlocked := OperatingSystem blockInterrupts. inputSema := Semaphore name:'readWait'. [ - Processor signal:inputSema onInput:fd. - hasTimedout := (inputSema waitWithTimeoutMs:timeout state:#iowait) isNil. + Processor signal:inputSema onInput:fd. + hasTimedout := (inputSema waitWithTimeoutMs:timeout state:#iowait) isNil. ] ifCurtailed:[ - Processor disableSemaphore:inputSema. - wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. + Processor disableSemaphore:inputSema. + wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. ]. hasTimedout ifTrue:[ - Processor disableSemaphore:inputSema. + Processor disableSemaphore:inputSema. ]. wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. ^ hasTimedout @@ -12499,20 +12551,20 @@ fd isNil ifTrue:[^ self error:#errorNotOpen]. self canWriteWithoutBlocking ifTrue:[ - ^ false. + ^ false. ]. wasBlocked := OperatingSystem blockInterrupts. outputSema := Semaphore name:'writeWait'. [ - Processor signal:outputSema onOutput:fd. - hasTimedOut := (outputSema waitWithTimeoutMs:timeout state:#iowait) isNil. + Processor signal:outputSema onOutput:fd. + hasTimedOut := (outputSema waitWithTimeoutMs:timeout state:#iowait) isNil. ] ifCurtailed:[ - Processor disableSemaphore:outputSema. - wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. + Processor disableSemaphore:outputSema. + wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. ]. hasTimedOut ifTrue:[ - Processor disableSemaphore:outputSema. + Processor disableSemaphore:outputSema. ]. wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. ^ hasTimedOut @@ -13326,219 +13378,219 @@ int ret, __flags; int nInstBytes, sockAddrSize; union { - struct sockaddr addr; - char enoughBytesForBigAddresses[1024]; + struct sockaddr addr; + char enoughBytesForBigAddresses[1024]; } sav_sockaddr; struct sockaddr *sav_sockaddrp; if (wantHostName == true) { - hp = host; - hsz = sizeof(host); + hp = host; + hsz = sizeof(host); } if (wantServiceName == true) { - sp = service; - ssz = sizeof(service); + sp = service; + ssz = sizeof(service); } if (hp == 0 && sp == 0) { - error = @symbol(badArgument); - goto err; + error = @symbol(badArgument); + goto err; } if (!__isBytes(socketAddress)) { - error = @symbol(badArgument1); - goto err; + error = @symbol(badArgument1); + goto err; } nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(socketAddress))->c_ninstvars)); sockAddrSize = __byteArraySize(socketAddress) - nInstBytes; if (!__isSmallInteger(flags)) { - error = @symbol(badArgument5); - goto err; + error = @symbol(badArgument5); + goto err; } __flags = __intVal(flags); #if defined(NI_NUMERICHOST) if (useDatagram == true) { - __flags |= NI_DGRAM; + __flags |= NI_DGRAM; } if (sockAddrSize <= sizeof(sav_sockaddr)) { - sav_sockaddrp = &sav_sockaddr.addr; + sav_sockaddrp = &sav_sockaddr.addr; } else { - fprintf(stderr, "OS: sockAddr buffer size too small\n"); - sav_sockaddrp = (struct sockaddr *)malloc(sockAddrSize + 32); + fprintf(stderr, "OS: sockAddr buffer size too small\n"); + sav_sockaddrp = (struct sockaddr *)malloc(sockAddrSize + 32); } { - // when we run this interruptable (or even in a separate thread), - // we cannot pass ST/X objects to it - // (some other ST/X thread might trigger a GC) - memcpy(sav_sockaddrp, __byteArrayVal(socketAddress)+nInstBytes, sockAddrSize); - - __BEGIN_INTERRUPTABLE__ - ret = getnameinfo(sav_sockaddrp, sockAddrSize, hp, hsz, sp, ssz, __flags); - __END_INTERRUPTABLE__ + // when we run this interruptable (or even in a separate thread), + // we cannot pass ST/X objects to it + // (some other ST/X thread might trigger a GC) + memcpy(sav_sockaddrp, __byteArrayVal(socketAddress)+nInstBytes, sockAddrSize); + + __BEGIN_INTERRUPTABLE__ + ret = getnameinfo(sav_sockaddrp, sockAddrSize, hp, hsz, sp, ssz, __flags); + __END_INTERRUPTABLE__ } while (ret == EAI_SYSTEM && errno == EINTR); if (sav_sockaddrp != &sav_sockaddr.addr) { - free(sav_sockaddrp); + free(sav_sockaddrp); } if (ret != 0) { - switch (ret) { - case EAI_FAMILY: - error = @symbol(badProtocol); - break; - case EAI_SOCKTYPE: - error = @symbol(badSocketType); - break; - case EAI_BADFLAGS: - error = @symbol(badFlags); - break; - case EAI_NONAME: - error = @symbol(unknownHost); - break; - case EAI_SERVICE: - error = @symbol(unknownService); - break; + switch (ret) { + case EAI_FAMILY: + error = @symbol(badProtocol); + break; + case EAI_SOCKTYPE: + error = @symbol(badSocketType); + break; + case EAI_BADFLAGS: + error = @symbol(badFlags); + break; + case EAI_NONAME: + error = @symbol(unknownHost); + break; + case EAI_SERVICE: + error = @symbol(unknownService); + break; #ifdef EAI_ADDRFAMILY - case EAI_ADDRFAMILY : - error = @symbol(unknownHostForProtocol); - break; + case EAI_ADDRFAMILY : + error = @symbol(unknownHostForProtocol); + break; #endif #ifdef EAI_NODATA - case EAI_NODATA: - error = @symbol(noAddress); - break; -#endif - case EAI_MEMORY: - error = @symbol(allocationFailure); - break; - case EAI_FAIL: - error = @symbol(permanentFailure); - break; - case EAI_AGAIN: - error = @symbol(tryAgain); - break; - case EAI_SYSTEM: - error = @symbol(systemError); - break; - default: - error = @symbol(unknownError); - } - errorString = __MKSTRING(gai_strerror(ret)); - goto err; + case EAI_NODATA: + error = @symbol(noAddress); + break; +#endif + case EAI_MEMORY: + error = @symbol(allocationFailure); + break; + case EAI_FAIL: + error = @symbol(permanentFailure); + break; + case EAI_AGAIN: + error = @symbol(tryAgain); + break; + case EAI_SYSTEM: + error = @symbol(systemError); + break; + default: + error = @symbol(unknownError); + } + errorString = __MKSTRING(gai_strerror(ret)); + goto err; } # else /* ! NI_NUMERICHOST */ { - /* - * Do it using gethostbyaddr() - */ - struct sockaddr_in *sa; - - if (sockAddrSize < sizeof(*sa)) { - error = @symbol(badArgument1); - goto err; - } - - if (sp) { - char *__proto = (useDatagram == true ? "udp" : "tcp"); - struct servent *servp = getservbyport(sa->sin_port, __proto); - if (servp) { - sp = servp->s_name; - } - } - if (hp) { - struct hostent *hostp; + /* + * Do it using gethostbyaddr() + */ + struct sockaddr_in *sa; + + if (sockAddrSize < sizeof(*sa)) { + error = @symbol(badArgument1); + goto err; + } + + if (sp) { + char *__proto = (useDatagram == true ? "udp" : "tcp"); + struct servent *servp = getservbyport(sa->sin_port, __proto); + if (servp) { + sp = servp->s_name; + } + } + if (hp) { + struct hostent *hostp; # ifdef USE_H_ERRNO - do { - sa = (struct sockaddr_in *)(__byteArrayVal(socketAddress) + nInstBytes); - - /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname uses a static data area - and sa points to possible grabage collected memory - */ - hostp = gethostbyaddr((char *)&sa->sin_addr, sockAddrSize, sa->sin_family); - /* __END_INTERRUPTABLE__ */ - } while ((hostp == NULL) - && ((h_errno == TRY_AGAIN) - || errno == EINTR + do { + sa = (struct sockaddr_in *)(__byteArrayVal(socketAddress) + nInstBytes); + + /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname uses a static data area + and sa points to possible grabage collected memory + */ + hostp = gethostbyaddr((char *)&sa->sin_addr, sockAddrSize, sa->sin_family); + /* __END_INTERRUPTABLE__ */ + } while ((hostp == NULL) + && ((h_errno == TRY_AGAIN) + || errno == EINTR # ifdef IRIX5_3 - || (errno == ECONNREFUSED) + || (errno == ECONNREFUSED) # endif - ) - ); - if (hostp == 0) { - switch (h_errno) { - case HOST_NOT_FOUND: - errorString = @symbol(unknownHost); - break; - case NO_ADDRESS: - errorString = @symbol(noAddress); - break; - case NO_RECOVERY: - errorString = @symbol(permanentFailure); - break; - case TRY_AGAIN: - errorString = @symbol(tryAgain); - break; - default: - errorString = @symbol(unknownError); - break; - } - error = __mkSmallInteger(h_errno); - goto err; - } + ) + ); + if (hostp == 0) { + switch (h_errno) { + case HOST_NOT_FOUND: + errorString = @symbol(unknownHost); + break; + case NO_ADDRESS: + errorString = @symbol(noAddress); + break; + case NO_RECOVERY: + errorString = @symbol(permanentFailure); + break; + case TRY_AGAIN: + errorString = @symbol(tryAgain); + break; + default: + errorString = @symbol(unknownError); + break; + } + error = __mkSmallInteger(h_errno); + goto err; + } # else /* !USE_H_ERRNO */ - hostp = gethostbyaddr(sa->sin_addr, sockAddrSize, sa->sin_family); - if (hostp == 0) { - errorString = @symbol(unknownHost); - error = __mkSmallInteger(-1); - goto err; - } + hostp = gethostbyaddr(sa->sin_addr, sockAddrSize, sa->sin_family); + if (hostp == 0) { + errorString = @symbol(unknownHost); + error = __mkSmallInteger(-1); + goto err; + } # endif /* !USE_H_ERRNO*/ - hp = hostp->h_name; - } + hp = hostp->h_name; + } } # endif /* ! NI_NUMERICHOST */ if (hp) - hostName = __MKSTRING(hp); + hostName = __MKSTRING(hp); if (sp) - serviceName = __MKSTRING(sp); + serviceName = __MKSTRING(sp); err:; #else error = @symbol(notImplemented); #endif %}. error notNil ifTrue:[ - ^ (HostAddressLookupError new - parameter:error; - messageText:' - ', errorString; - request:thisContext message) raiseRequest. + ^ (HostAddressLookupError new + parameter:error; + messageText:' - ', errorString; + request:thisContext message) raiseRequest. ]. ^ Array with:hostName with:serviceName " self getNameInfo: - (self getAddressInfo:'localhost' serviceName:'echo' - domain:#inet type:#stream protocol:nil flags:nil) first socketAddress - wantHostName:true wantServiceName:true datagram:false flags:0 + (self getAddressInfo:'localhost' serviceName:'echo' + domain:#inet type:#stream protocol:nil flags:nil) first socketAddress + wantHostName:true wantServiceName:true datagram:false flags:0 self getNameInfo: - (self getAddressInfo:'exept.de' serviceName:'echo' - domain:#inet type:#stream protocol:nil flags:nil) first socketAddress - wantHostName:true wantServiceName:true datagram:false flags:0 + (self getAddressInfo:'exept.de' serviceName:'echo' + domain:#inet type:#stream protocol:nil flags:nil) first socketAddress + wantHostName:true wantServiceName:true datagram:false flags:0 self getNameInfo: - (self getAddressInfo:'217.172.183.25' serviceName:'22' - domain:#inet type:#stream protocol:nil flags:nil) first socketAddress - wantHostName:true wantServiceName:true datagram:false flags:0 + (self getAddressInfo:'217.172.183.25' serviceName:'22' + domain:#inet type:#stream protocol:nil flags:nil) first socketAddress + wantHostName:true wantServiceName:true datagram:false flags:0 self getNameInfo: - (self getAddressInfo:'1.2.3.4' serviceName:'22' - domain:#inet type:#stream protocol:nil flags:nil) first socketAddress - wantHostName:true wantServiceName:true datagram:false flags:0 + (self getAddressInfo:'1.2.3.4' serviceName:'22' + domain:#inet type:#stream protocol:nil flags:nil) first socketAddress + wantHostName:true wantServiceName:true datagram:false flags:0 " "Modified: / 21-03-2018 / 10:03:30 / stefan" @@ -13562,23 +13614,23 @@ int ret, cnt = 0; if (hostName == nil) { - __hostName = 0; + __hostName = 0; } else if (__isStringLike(hostName)) { - __hostName = __stringVal(hostName); + __hostName = __stringVal(hostName); } else { - error = @symbol(badArgument1); - goto out; + error = @symbol(badArgument1); + goto out; } if (serviceName == nil) { - __serviceName = 0; + __serviceName = 0; } else if (__isStringLike(serviceName)) { - __serviceName = __stringVal(serviceName); + __serviceName = __stringVal(serviceName); } else if (__isSmallInteger(serviceName)) { - __serviceName = intServiceName; - snprintf(intServiceName, sizeof(intServiceName), "%d", (int)(__intVal(serviceName))); + __serviceName = intServiceName; + snprintf(intServiceName, sizeof(intServiceName), "%d", (int)(__intVal(serviceName))); } else { - error = @symbol(badArgument2); - goto out; + error = @symbol(badArgument2); + goto out; } { @@ -13590,131 +13642,131 @@ struct addrinfo *info = NULL, *infop; hints.ai_flags = AI_ADDRCONFIG // only return IPv6 or IPv4 addresses if there is at least on interface where this address type is configured - | AI_V4MAPPED; + | AI_V4MAPPED; if (__isSmallInteger(serviceName)) - hints.ai_flags |= AI_NUMERICSERV; + hints.ai_flags |= AI_NUMERICSERV; if (__hostName && __stringSize(hostName) == 0) { - // empty string, this is a listening host - bound to INADDR_ANY - __hostName = 0; - hints.ai_flags |= AI_PASSIVE; + // empty string, this is a listening host - bound to INADDR_ANY + __hostName = 0; + hints.ai_flags |= AI_PASSIVE; } #if defined(AI_IDN) hints.ai_flags |= AI_IDN | AI_CANONIDN; // map non-ascii domain names to IDN format #endif if (__isSmallInteger(domain)) - hints.ai_family = __intVal(domain); + hints.ai_family = __intVal(domain); if (__isSmallInteger(type)) - hints.ai_socktype = __intVal(type); + hints.ai_socktype = __intVal(type); if (__isSmallInteger(proto)) - hints.ai_protocol = __intVal(proto); + hints.ai_protocol = __intVal(proto); if (__isSmallInteger(flags)) - hints.ai_flags |= __intVal(flags); + hints.ai_flags |= __intVal(flags); do { - /* reload */ - if (__hostName) { - __hostName = __stringVal(hostName); - } - if (__isStringLike(serviceName)) { - __serviceName = __stringVal(serviceName); - } + /* reload */ + if (__hostName) { + __hostName = __stringVal(hostName); + } + if (__isStringLike(serviceName)) { + __serviceName = __stringVal(serviceName); + } // disabled, because sender blocks interrupts // __BEGIN_INTERRUPTABLE__ - ret = getaddrinfo(__hostName, __serviceName, &hints, &info); + ret = getaddrinfo(__hostName, __serviceName, &hints, &info); // __END_INTERRUPTABLE__ } while (ret == EAI_SYSTEM && errno == EINTR); if (ret != 0) { - switch (ret) { - case EAI_FAMILY: - error = @symbol(badProtocol); - break; - case EAI_SOCKTYPE: - error = @symbol(badSocketType); - break; - case EAI_BADFLAGS: - error = @symbol(badFlags); - break; - case EAI_NONAME: - error = @symbol(unknownHost); - break; - case EAI_SERVICE: - error = @symbol(unknownService); - break; + switch (ret) { + case EAI_FAMILY: + error = @symbol(badProtocol); + break; + case EAI_SOCKTYPE: + error = @symbol(badSocketType); + break; + case EAI_BADFLAGS: + error = @symbol(badFlags); + break; + case EAI_NONAME: + error = @symbol(unknownHost); + break; + case EAI_SERVICE: + error = @symbol(unknownService); + break; #ifdef EAI_ADDRFAMILY - case EAI_ADDRFAMILY : - error = @symbol(unknownHostForProtocol); - break; + case EAI_ADDRFAMILY : + error = @symbol(unknownHostForProtocol); + break; #endif #ifdef EAI_NODATA - case EAI_NODATA: - error = @symbol(noAddress); - break; -#endif - case EAI_MEMORY: - error = @symbol(allocationFailure); - break; - case EAI_FAIL: - error = @symbol(permanentFailure); - break; - case EAI_AGAIN: - error = @symbol(tryAgain); - break; - case EAI_SYSTEM: - error = @symbol(systemError); - break; - default: - error = @symbol(unknownError); - } - errorString = __MKSTRING(gai_strerror(ret)); - goto ai_out; + case EAI_NODATA: + error = @symbol(noAddress); + break; +#endif + case EAI_MEMORY: + error = @symbol(allocationFailure); + break; + case EAI_FAIL: + error = @symbol(permanentFailure); + break; + case EAI_AGAIN: + error = @symbol(tryAgain); + break; + case EAI_SYSTEM: + error = @symbol(systemError); + break; + default: + error = @symbol(unknownError); + } + errorString = __MKSTRING(gai_strerror(ret)); + goto ai_out; } for (cnt=0, infop=info; infop; infop=infop->ai_next) - cnt++; + cnt++; result = __ARRAY_NEW_INT(cnt); if (result == nil) { - error = @symbol(allocationFailure); - goto ai_out; + error = @symbol(allocationFailure); + goto ai_out; } for (infop=info, cnt=0; infop; infop=infop->ai_next, cnt++) { - OBJ o, resp; - - resp = __ARRAY_NEW_INT(6); - if (resp == nil) { - error = @symbol(allocationFailure); - goto ai_out; - } - - __ArrayInstPtr(result)->a_element[cnt] = resp; __STORE(result, resp); - - __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(infop->ai_flags); - __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(infop->ai_family); - __ArrayInstPtr(resp)->a_element[2] = __mkSmallInteger(infop->ai_socktype); - __ArrayInstPtr(resp)->a_element[3] = __mkSmallInteger(infop->ai_protocol); - - __PROTECT__(resp); - o = __BYTEARRAY_NEW_INT(infop->ai_addrlen); - __UNPROTECT__(resp); - if (o == nil) { - error = @symbol(allocationFailure); - goto ai_out; - } - memcpy(__byteArrayVal(o), infop->ai_addr, infop->ai_addrlen); + OBJ o, resp; + + resp = __ARRAY_NEW_INT(6); + if (resp == nil) { + error = @symbol(allocationFailure); + goto ai_out; + } + + __ArrayInstPtr(result)->a_element[cnt] = resp; __STORE(result, resp); + + __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(infop->ai_flags); + __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(infop->ai_family); + __ArrayInstPtr(resp)->a_element[2] = __mkSmallInteger(infop->ai_socktype); + __ArrayInstPtr(resp)->a_element[3] = __mkSmallInteger(infop->ai_protocol); + + __PROTECT__(resp); + o = __BYTEARRAY_NEW_INT(infop->ai_addrlen); + __UNPROTECT__(resp); + if (o == nil) { + error = @symbol(allocationFailure); + goto ai_out; + } + memcpy(__byteArrayVal(o), infop->ai_addr, infop->ai_addrlen); __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); - if (infop->ai_canonname) { - __PROTECT__(resp); - o = __MKSTRING(infop->ai_canonname); - __UNPROTECT__(resp); - if (o == nil) { - error = @symbol(allocationFailure); - goto ai_out; - } - __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); - } + if (infop->ai_canonname) { + __PROTECT__(resp); + o = __MKSTRING(infop->ai_canonname); + __UNPROTECT__(resp); + if (o == nil) { + error = @symbol(allocationFailure); + goto ai_out; + } + __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); + } } ai_out: @@ -13731,136 +13783,136 @@ int i; if (__serviceName) { - struct servent *sp; - char *__proto = 0; - - if (__isStringLike(protoArg)) - __proto = __stringVal(protoArg); - - sp = getservbyname(__serviceName, __proto); - if (sp == NULL) { - errorString = @symbol(unknownService); - error = __mkSmallInteger(-3); - goto out; - } - port = sp->s_port; + struct servent *sp; + char *__proto = 0; + + if (__isStringLike(protoArg)) + __proto = __stringVal(protoArg); + + sp = getservbyname(__serviceName, __proto); + if (sp == NULL) { + errorString = @symbol(unknownService); + error = __mkSmallInteger(-3); + goto out; + } + port = sp->s_port; } if (__hostName) { # ifdef USE_H_ERRNO - do { - if (hostName == nil) { - __hostName = 0; - } else if (__isStringLike(hostName)) { - __hostName = __stringVal(hostName); - } - /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname - * uses a static data area - */ - __BEGIN_INTERRUPTABLE__ - hp = gethostbyname(__hostName); - __END_INTERRUPTABLE__ - } while ((hp == NULL) - && ( - (h_errno == TRY_AGAIN) - || errno == EINTR + do { + if (hostName == nil) { + __hostName = 0; + } else if (__isStringLike(hostName)) { + __hostName = __stringVal(hostName); + } + /* __BEGIN_INTERRUPTABLE__ is dangerous, because gethostbyname + * uses a static data area + */ + __BEGIN_INTERRUPTABLE__ + hp = gethostbyname(__hostName); + __END_INTERRUPTABLE__ + } while ((hp == NULL) + && ( + (h_errno == TRY_AGAIN) + || errno == EINTR # ifdef IRIX5_3 - || (errno == ECONNREFUSED) + || (errno == ECONNREFUSED) # endif - ) - ); - if (hp == 0) { - switch (h_errno) { - case HOST_NOT_FOUND: - errorString = @symbol(unknownHost); - break; - case NO_ADDRESS: - errorString = @symbol(noAddress); - break; - case NO_RECOVERY: - errorString = @symbol(permanentFailure); - break; - case TRY_AGAIN: - errorString = @symbol(tryAgain); - break; - default: - errorString = @symbol(unknownError); - break; - } - error = __mkSmallInteger(h_errno); - goto out; - } + ) + ); + if (hp == 0) { + switch (h_errno) { + case HOST_NOT_FOUND: + errorString = @symbol(unknownHost); + break; + case NO_ADDRESS: + errorString = @symbol(noAddress); + break; + case NO_RECOVERY: + errorString = @symbol(permanentFailure); + break; + case TRY_AGAIN: + errorString = @symbol(tryAgain); + break; + default: + errorString = @symbol(unknownError); + break; + } + error = __mkSmallInteger(h_errno); + goto out; + } # else /* !USE_H_ERRNO */ - hp = gethostbyname(__hostName); - if (hp == 0) { - errorString = @symbol(unknownHost); - error = __mkSmallInteger(-1); - goto out; - } + hp = gethostbyname(__hostName); + if (hp == 0) { + errorString = @symbol(unknownHost); + error = __mkSmallInteger(-1); + goto out; + } # endif /* !USE_H_ERRNO*/ - if (__isSmallInteger(domain) && hp->h_addrtype != __smallIntegerVal(domain)) { - errorString = @symbol(unknownHost); - error = __mkSmallInteger(-2); - goto out; - } - - for (cnt = 0, addrpp = hp->h_addr_list; *addrpp; addrpp++) - cnt++; - addrpp = hp->h_addr_list; + if (__isSmallInteger(domain) && hp->h_addrtype != __smallIntegerVal(domain)) { + errorString = @symbol(unknownHost); + error = __mkSmallInteger(-2); + goto out; + } + + for (cnt = 0, addrpp = hp->h_addr_list; *addrpp; addrpp++) + cnt++; + addrpp = hp->h_addr_list; } else { - cnt = 1; + cnt = 1; } result = __ARRAY_NEW_INT(cnt); if (result == nil) { - error = @symbol(allocationFailure); - goto out; + error = @symbol(allocationFailure); + goto out; } for (i = 0; i < cnt; i++) { - OBJ o, resp; - struct sockaddr_in *sa; - - resp = __ARRAY_NEW_INT(6); - if (resp == nil) { - error = @symbol(allocationFailure); - goto out; - } - - __ArrayInstPtr(result)->a_element[i] = resp; __STORE(result, resp); - __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(0); - __ArrayInstPtr(resp)->a_element[2] = type; __STORE(result, type); - __ArrayInstPtr(resp)->a_element[3] = proto; __STORE(result, proto); - __PROTECT__(resp); - o = __BYTEARRAY_NEW_INT(sizeof(*sa)); - __UNPROTECT__(resp); - if (o == nil) { - error = @symbol(allocationFailure); - goto out; - } - __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); - sa = (struct sockaddr_in *)__byteArrayVal(o); - sa->sin_port = port; - - if (__hostName) { - sa->sin_family = hp->h_addrtype; - memcpy(&sa->sin_addr, *addrpp, hp->h_length); - __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(hp->h_addrtype); - if (hp->h_name) { - __PROTECT__(resp); - o = __MKSTRING(hp->h_name); - __UNPROTECT__(resp); - if (o == nil) { - error = @symbol(allocationFailure); - goto out; - } - __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); - } - addrpp++; - } else{ - __ArrayInstPtr(resp)->a_element[1] = domain; __STORE(resp, domain); - } + OBJ o, resp; + struct sockaddr_in *sa; + + resp = __ARRAY_NEW_INT(6); + if (resp == nil) { + error = @symbol(allocationFailure); + goto out; + } + + __ArrayInstPtr(result)->a_element[i] = resp; __STORE(result, resp); + __ArrayInstPtr(resp)->a_element[0] = __mkSmallInteger(0); + __ArrayInstPtr(resp)->a_element[2] = type; __STORE(result, type); + __ArrayInstPtr(resp)->a_element[3] = proto; __STORE(result, proto); + __PROTECT__(resp); + o = __BYTEARRAY_NEW_INT(sizeof(*sa)); + __UNPROTECT__(resp); + if (o == nil) { + error = @symbol(allocationFailure); + goto out; + } + __ArrayInstPtr(resp)->a_element[4] = o; __STORE(resp, o); + sa = (struct sockaddr_in *)__byteArrayVal(o); + sa->sin_port = port; + + if (__hostName) { + sa->sin_family = hp->h_addrtype; + memcpy(&sa->sin_addr, *addrpp, hp->h_length); + __ArrayInstPtr(resp)->a_element[1] = __mkSmallInteger(hp->h_addrtype); + if (hp->h_name) { + __PROTECT__(resp); + o = __MKSTRING(hp->h_name); + __UNPROTECT__(resp); + if (o == nil) { + error = @symbol(allocationFailure); + goto out; + } + __ArrayInstPtr(resp)->a_element[5] = o; __STORE(resp, o); + } + addrpp++; + } else{ + __ArrayInstPtr(resp)->a_element[1] = domain; __STORE(resp, domain); + } } # endif /* ! AI_NUMERICHOST */ } @@ -13870,10 +13922,10 @@ out:; %}. error notNil ifTrue:[ - errorString notNil ifTrue:[ - ^ errorString. - ]. - ^ error. + errorString notNil ifTrue:[ + ^ errorString. + ]. + ^ error. ]. ^ result.