if (nfds < fds[i].fd)
if (nfds < fds[i].fd + 1)
int poll(struct pollfd *fds, unsigned n, int timeout){	fd_set rfds;	fd_set wfds;	unsigned i;	int nfds;	struct timeval tv;	int rv;	FD_ZERO(&rfds);	FD_ZERO(&wfds);	nfds = 0;	for (i = 0; i < n; i++) {		if (fds[i].fd != -1) {			if (fds[i].events & POLLIN)				FD_SET(fds[i].fd, &rfds);			if (fds[i].events & POLLOUT)				FD_SET(fds[i].fd, &wfds);			if (nfds < fds[i].fd)				nfds = fds[i].fd + 1;		}	}	if (timeout == INFTIM)		rv = select(nfds, &rfds, &wfds, 0, 0);	else {		tv.tv_sec = timeout / 1000;		tv.tv_usec = (timeout % 1000) * 1000;		rv = select(nfds, &rfds, &wfds, 0, &tv);	}	if (rv == -1)		return -1;	for (i = 0; i < n; i++) {		fds[i].revents = 0;		if (fds[i].fd != -1) {			if (FD_ISSET(fds[i].fd, &rfds))				fds[i].revents |= POLLIN;			if (FD_ISSET(fds[i].fd, &wfds))				fds[i].revents |= POLLOUT;		}	}	return rv;}