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