9 poll(struct pollfd
*fds
,
13 TIMEVAL timeout
, *toptr
;
14 FD_SET ifds
, ofds
, efds
, *ip
, *op
;
23 for (i
= 0; i
< nfds
; ++i
)
33 if (fds
[i
].events
& (POLLIN
|POLLPRI
))
36 FD_SET(fds
[i
].fd
, ip
);
39 if (fds
[i
].events
& POLLOUT
)
42 FD_SET(fds
[i
].fd
, op
);
45 FD_SET(fds
[i
].fd
, &efds
);
53 timeout
.tv_sec
= timo
/ 1000;
54 timeout
.tv_usec
= (timo
- timeout
.tv_sec
* 1000) * 1000;
57 rc
= select(++n
, ip
, op
, &efds
, toptr
);
62 for (i
= 0, n
= 0; i
< nfds
; ++i
)
64 if (fds
[i
].fd
< 0) continue;
66 if (fds
[i
].events
& (POLLIN
|POLLPRI
) && FD_ISSET(i
, &ifds
))
67 fds
[i
].revents
|= POLLIN
;
69 if (fds
[i
].events
& POLLOUT
&& FD_ISSET(i
, &ofds
))
70 fds
[i
].revents
|= POLLOUT
;
72 if (FD_ISSET(i
, &efds
))
73 fds
[i
].revents
|= POLLHUP
;
80 int socketpair(int af
,
85 struct sockaddr_in addr
;
88 int addrlen
= sizeof(addr
);
89 DWORD flags
= 0; //(make_overlapped ? WSA_FLAG_OVERLAPPED : 0);
93 WSASetLastError(WSAEINVAL
);
97 socks
[0] = socks
[1] = INVALID_SOCKET
;
98 if ((listener
= socket(af
, type
, 0)) == INVALID_SOCKET
)
101 memset(&addr
, 0, sizeof(addr
));
102 addr
.sin_family
= AF_INET
;
103 addr
.sin_addr
.s_addr
= htonl(0x7f000001);
106 e
= bind(listener
, (const struct sockaddr
*) &addr
, sizeof(addr
));
107 if (e
== SOCKET_ERROR
)
109 e
= WSAGetLastError();
110 closesocket(listener
);
114 e
= getsockname(listener
, (struct sockaddr
*) &addr
, &addrlen
);
115 if (e
== SOCKET_ERROR
)
117 e
= WSAGetLastError();
118 closesocket(listener
);
125 if (listen(listener
, 1) == SOCKET_ERROR
)
127 if ((socks
[0] = WSASocket(af
, type
, 0, NULL
, 0, flags
)) == INVALID_SOCKET
)
129 if (connect(socks
[0], (const struct sockaddr
*) &addr
, sizeof(addr
)) == SOCKET_ERROR
)
131 if ((socks
[1] = accept(listener
, NULL
, NULL
)) == INVALID_SOCKET
)
134 closesocket(listener
);
139 e
= WSAGetLastError();
140 closesocket(listener
);
141 closesocket(socks
[0]);
142 closesocket(socks
[1]);
159 memcpy(&in
.s_addr
, src
, sizeof(in
.s_addr
));
160 text_addr
= inet_ntoa(in
);
161 if (text_addr
&& dst
)
163 strncpy(dst
, text_addr
, cnt
);