UnixOperatingSystem.st
changeset 8307 8e90da896548
parent 8279 e16a20ee2c6d
child 8337 1168b3ff3cdc
equal deleted inserted replaced
8306:5b610781e787 8307:8e90da896548
  5407     extern void __signalIoInterrupt();
  5407     extern void __signalIoInterrupt();
  5408 #endif
  5408 #endif
  5409     static int firstCall = 1;
  5409     static int firstCall = 1;
  5410 
  5410 
  5411 #if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4)
  5411 #if (defined(F_GETFL) && defined(F_SETFL) && defined(FASYNC)) || defined(SYSV4)
  5412 /*
  5412     /*
  5413  * SIGIO/SIGPOLL - data available for I/O
  5413      * SIGIO/SIGPOLL - data available for I/O
  5414  * (used to wake up waiting processes)
  5414      * (used to wake up waiting processes)
  5415  */
  5415      */
  5416 #ifdef SIGIO
  5416 # ifdef SIGIO
  5417 # define THESIGNAL SIGIO
  5417 #  define THESIGNAL SIGIO
  5418 #else
       
  5419 # ifdef SIGPOLL
       
  5420 #  define THESIGNAL SIGPOLL
       
  5421 # else
  5418 # else
  5422 #  ifdef SIGURG
  5419 #  ifdef SIGPOLL
  5423 #   define THESIGNAL SIGURG
  5420 #   define THESIGNAL SIGPOLL
       
  5421 #  else
       
  5422 #   ifdef SIGURG
       
  5423 #    define THESIGNAL SIGURG
       
  5424 #   endif
  5424 #  endif
  5425 #  endif
  5425 # endif
  5426 # endif
  5426 #endif
       
  5427 
  5427 
  5428     if (__isSmallInteger(fd)) {
  5428     if (__isSmallInteger(fd)) {
  5429 	if (firstCall) {
  5429 	if (firstCall) {
  5430 #ifdef HAS_SIGACTION
  5430 # ifdef HAS_SIGACTION
  5431 	    struct sigaction act = {0};
  5431 	    struct sigaction act;
  5432 
  5432 
  5433 	    /*
  5433 	    /*
  5434 	     * Do not add SA_RESTART here. A signal can cause a
  5434 	     * Do not add SA_RESTART here. A signal can cause a
  5435 	     * thread switch, another thread can do a garbage collect
  5435 	     * thread switch, another thread can do a garbage collect
  5436 	     * and restarted system calls may write into old
  5436 	     * and restarted system calls may write into old
  5439 
  5439 
  5440 	    act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */
  5440 	    act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */
  5441 	    sigemptyset(&act.sa_mask);
  5441 	    sigemptyset(&act.sa_mask);
  5442 	    act.sa_handler = __signalIoInterrupt;
  5442 	    act.sa_handler = __signalIoInterrupt;
  5443 	    sigaction(THESIGNAL, &act, 0);
  5443 	    sigaction(THESIGNAL, &act, 0);
  5444 #else
  5444 # else
  5445 # ifdef HAS_SIGVEC
  5445 #  ifdef HAS_SIGVEC
  5446 	    struct sigvec vec;
  5446 	    struct sigvec vec;
  5447 
  5447 
  5448 	    vec.sv_flags = SV_INTERRUPT;
  5448 	    vec.sv_flags = SV_INTERRUPT;
  5449 	    sigemptyset(&vec.sv_mask);
  5449 	    sigemptyset(&vec.sv_mask);
  5450 	    vec.sv_handler = __signalIoInterrupt;
  5450 	    vec.sv_handler = __signalIoInterrupt;
  5451 	    sigvec(THESIGNAL, &vec, NULL);
  5451 	    sigvec(THESIGNAL, &vec, NULL);
  5452 # else
  5452 #  else
  5453 	    signal(THESIGNAL, __signalIoInterrupt);
  5453 	    signal(THESIGNAL, __signalIoInterrupt);
  5454 # endif
  5454 #  endif /* SIGVEC */
  5455 #endif
  5455 # endif /* SIGACTION */
  5456 	    firstCall = 0;
  5456 	    firstCall = 0;
  5457 	}
  5457 	}
  5458 #undef THESIGNAL
  5458 #undef THESIGNAL
  5459 
  5459 
  5460 	f = __intVal(fd);
  5460 	f = __intVal(fd);
  5471 	    ret = fcntl(f, F_SETFL, flags | FASYNC);
  5471 	    ret = fcntl(f, F_SETFL, flags | FASYNC);
  5472 	    if (ret >= 0) ret = flags;
  5472 	    if (ret >= 0) ret = flags;
  5473 	}
  5473 	}
  5474 # endif /*!SYSV4*/
  5474 # endif /*!SYSV4*/
  5475 
  5475 
  5476 #if defined(F_SETOWN) || defined(FIOSETOWN)
  5476 # if defined(F_SETOWN) || defined(FIOSETOWN)
  5477 	{
  5477 	{
  5478 	    int pid;
  5478 	    int pid;
  5479 	    int ok;
  5479 	    int ok;
  5480 
  5480 
  5481 	    pid = getpid();
  5481 	    pid = getpid();
  5482 
  5482 
  5483 # if defined(F_SETOWN)
  5483 #  if defined(F_SETOWN)
  5484 	    ok = fcntl(f, F_SETOWN, pid);
  5484 	    ok = fcntl(f, F_SETOWN, pid);
  5485 	    /* printf("F_SETOWN returns %d (%d)\n", ret, errno); */
  5485 	    /* printf("F_SETOWN returns %d (%d)\n", ret, errno); */
  5486 # else
  5486 #  else
  5487 	    ok = ioctl(f, FIOSETOWN, &pid);
  5487 	    ok = ioctl(f, FIOSETOWN, &pid);
  5488 	    /* printf("FIOSETOWN returns %d (%d)\n", ret, errno); */
  5488 	    /* printf("FIOSETOWN returns %d (%d)\n", ret, errno); */
  5489 # endif
  5489 #  endif
  5490 	    if (ok < 0) {
  5490 	    if (ok < 0) {
  5491 		ret = ok;
  5491 		ret = ok;
  5492 	    }
  5492 	    }
  5493 	}
  5493 	}
  5494 #endif
  5494 # endif
  5495 	RETURN ( __MKUINT(ret) );
  5495 	RETURN ( __MKUINT(ret) );
  5496     }
  5496     }
  5497 #endif
  5497 #endif
  5498 %}.
  5498 %}.
  5499     "
  5499     "
  5676 		break;
  5676 		break;
  5677 	}
  5677 	}
  5678 
  5678 
  5679 	{
  5679 	{
  5680 #ifdef HAS_SIGACTION
  5680 #ifdef HAS_SIGACTION
  5681 	    struct sigaction act = {0};
  5681 	    struct sigaction act;
  5682 
  5682 
  5683 	    /*
  5683 	    /*
  5684 	     * Do not add SA_RESTART here. A signal can cause a
  5684 	     * Do not add SA_RESTART here. A signal can cause a
  5685 	     * thread switch, another thread can do a garbage collect
  5685 	     * thread switch, another thread can do a garbage collect
  5686 	     * and restarted system calls may write into old
  5686 	     * and restarted system calls may write into old
  5735 	extern void __signalTimerInterrupt(SIGHANDLER_ARG);
  5735 	extern void __signalTimerInterrupt(SIGHANDLER_ARG);
  5736 # endif
  5736 # endif
  5737 
  5737 
  5738 	if (firstCall) {
  5738 	if (firstCall) {
  5739 # ifdef HAS_SIGACTION
  5739 # ifdef HAS_SIGACTION
  5740 	    struct sigaction act = {0};
  5740 	    struct sigaction act;
  5741 
  5741 
  5742 	    act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */
  5742 	    act.sa_flags = SA_SIGINFO; /* <- if you add more, remember dummys at the top */
  5743 	    sigemptyset(&act.sa_mask);
  5743 	    sigemptyset(&act.sa_mask);
  5744 	    act.sa_handler = __signalTimerInterrupt;
  5744 	    act.sa_handler = __signalTimerInterrupt;
  5745 	    sigaction(SIGALRM, &act, 0);
  5745 	    sigaction(SIGALRM, &act, 0);
 11623 
 11623 
 11624 %{
 11624 %{
 11625 #ifndef NO_SOCKET
 11625 #ifndef NO_SOCKET
 11626     int sock;
 11626     int sock;
 11627     int ret;
 11627     int ret;
 11628     struct sockaddr sockaddr = { AF_UNSPEC };
 11628     struct sockaddr sockaddr;
 11629 
 11629 
 11630     if (!__isSmallInteger(__INST(fd))) {
 11630     if (!__isSmallInteger(__INST(fd))) {
 11631 	error = @symbol(badFd);
 11631 	error = @symbol(badFd);
 11632 	goto err;
 11632 	goto err;
 11633     }
 11633     }
 11635 
 11635 
 11636     /*
 11636     /*
 11637      * (dis-) connect by connecting to AF_UNSPEC socket
 11637      * (dis-) connect by connecting to AF_UNSPEC socket
 11638      */
 11638      */
 11639 again:
 11639 again:
       
 11640     sockaddr.sa_family = AF_UNSPEC;
 11640     ret = connect(sock, &sockaddr, sizeof(sockaddr));
 11641     ret = connect(sock, &sockaddr, sizeof(sockaddr));
 11641     if (ret < 0) {
 11642     if (ret < 0) {
 11642        switch(errno) {
 11643        switch(errno) {
 11643 	   case EINTR:
 11644 	   case EINTR:
 11644 # ifdef EAGAIN
 11645 # ifdef EAGAIN
 12325 ! !
 12326 ! !
 12326 
 12327 
 12327 !UnixOperatingSystem class methodsFor:'documentation'!
 12328 !UnixOperatingSystem class methodsFor:'documentation'!
 12328 
 12329 
 12329 version
 12330 version
 12330     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.207 2004-03-31 09:56:38 cg Exp $'
 12331     ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.208 2004-04-08 12:47:30 cg Exp $'
 12331 ! !
 12332 ! !
 12332 
 12333 
 12333 UnixOperatingSystem initialize!
 12334 UnixOperatingSystem initialize!
 12334 UnixOperatingSystem::FileDescriptorHandle initialize!
 12335 UnixOperatingSystem::FileDescriptorHandle initialize!