1 #include "syshdrs.h" 2 3 #ifndef NO_SIGNALS 4 extern volatile Sjmp_buf gNetTimeoutJmp; 5 extern volatile Sjmp_buf gPipeJmp; 6 #endif 7 8 int 9 SAcceptA(int sfd, struct sockaddr_in *const addr, int tlen) 10 { 11 int result; 12 #ifndef NO_SIGNALS 13 vsio_sigproc_t sigalrm, sigpipe; 14 #endif 15 size_t size; 16 17 if (tlen < 0) { 18 errno = 0; 19 for (;;) { 20 size = sizeof(struct sockaddr_in); 21 result = accept(sfd, (struct sockaddr *) addr, (int *) &size); 22 if ((result >= 0) || (errno != EINTR)) 23 return (result); 24 } 25 } 26 #ifndef NO_SIGNALS 27 if (SSetjmp(gNetTimeoutJmp) != 0) { 28 alarm(0); 29 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm); 30 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe); 31 errno = ETIMEDOUT; 32 return (kTimeoutErr); 33 } 34 35 sigalrm = (vsio_sigproc_t) SSignal(SIGALRM, SIOHandler); 36 sigpipe = (vsio_sigproc_t) SSignal(SIGPIPE, SIG_IGN); 37 alarm((unsigned int) tlen); 38 39 errno = 0; 40 do { 41 size = sizeof(struct sockaddr_in); 42 result = accept(sfd, (struct sockaddr *) addr, (int *) &size); 43 } while ((result < 0) && (errno == EINTR)); 44 45 alarm(0); 46 (void) SSignal(SIGALRM, (sio_sigproc_t) sigalrm); 47 (void) SSignal(SIGPIPE, (sio_sigproc_t) sigpipe); 48 return (result); 49 #else 50 return (-1); 51 #endif 52 } /* SAcceptA */ 53