142c142,143
< * Loop that polls on the network file descriptor and stdin.
---
> * Loop that selects on the network file descriptor and stdin.
> * Changed from poll() by Ali Saidi to make work on Mac OS X >= 10.4
147c148
< struct pollfd pfd[2];
---
> fd_set read_fds;
149c150
< int wfd = fileno(stdin), n, ret;
---
> int wfd = fileno(stdin), n, ret, max_fd;
151a153
> struct timeval timeout;
153,155c155,156
< /* Setup Network FD */
< pfd[0].fd = nfd;
< pfd[0].events = POLLIN;
---
> if (nfd == -1)
> return;
157,159c158
< /* Setup STDIN FD */
< pfd[1].fd = wfd;
< pfd[1].events = POLLIN;
---
> FD_ZERO(&read_fds);
161,162c160,169
< while (pfd[0].fd != -1) {
< if ((n = poll(pfd, 2, -1)) < 0) {
---
> FD_SET(wfd, &read_fds);
> FD_SET(nfd, &read_fds);
> max_fd = nfd + 1;
>
> timeout.tv_sec = 1;
> timeout.tv_usec = 0;
>
> while (1) {
> n = select(max_fd, &read_fds, NULL, NULL, &timeout);
> if (n < 0) {
164c171
< err(1, "Polling Error");
---
> perror("Select Error:");
167c174,180
< if (n == 0)
---
> if (n == 0) {
> if (read(nfd, buf, 0) < 0)
> return;
> goto setup_select;
> }
>
> if (read(nfd, buf, 0) < 0)
170c183
< if (pfd[0].revents & POLLIN) {
---
> if (FD_ISSET(nfd, &read_fds)) {
175,176c188
< pfd[0].fd = -1;
< pfd[0].events = 0;
---
> return;
183c195
< if (pfd[1].revents & POLLIN) {
---
> if (FD_ISSET(wfd, &read_fds)) {
188,189d199
< pfd[1].fd = -1;
< pfd[1].events = 0;
211c221,227
< }
---
> setup_select:
> FD_ZERO(&read_fds);
> FD_SET(wfd, &read_fds);
> FD_SET(nfd, &read_fds);
> timeout.tv_sec = 1;
> timeout.tv_usec = 0;
> } // while