1 #include "syshdrs.h"
2
3 int
SAcceptS(int sfd,struct sockaddr_in * const addr,int tlen)4 SAcceptS(int sfd, struct sockaddr_in *const addr, int tlen)
5 {
6 int result;
7 fd_set ss;
8 struct timeval tv;
9 size_t size;
10
11 if (tlen <= 0) {
12 errno = 0;
13 for (;;) {
14 size = sizeof(struct sockaddr_in);
15 result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
16 if ((result >= 0) || (errno != EINTR))
17 return (result);
18 }
19 }
20
21 forever {
22 errno = 0;
23 FD_ZERO(&ss);
24 FD_SET(sfd, &ss);
25 tv.tv_sec = tlen;
26 tv.tv_usec = 0;
27 result = select(sfd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, SELECT_TYPE_ARG5 &tv);
28 if (result == 1) {
29 /* ready */
30 break;
31 } else if (result == 0) {
32 /* timeout */
33 errno = ETIMEDOUT;
34 SETWSATIMEOUTERR
35 return (kTimeoutErr);
36 } else if (errno != EINTR) {
37 return (-1);
38 }
39 }
40
41 do {
42 size = sizeof(struct sockaddr_in);
43 result = accept(sfd, (struct sockaddr *) addr, (int *) &size);
44 } while ((result < 0) && (errno == EINTR));
45
46 return (result);
47 } /* SAcceptS */
48