View | Details | Raw Unified | Return to bug 7231
Collapse All | Expand All

(-)openbsd-compat/win32-socket.c (-40 / +77 lines)
Lines 663-720 Link Here
663
	return ret;
663
	return ret;
664
}
664
}
665
665
666
static int
667
_select_ttys(int nfds, fd_set *readfds, fd_set *writefds,
668
             fd_set *exceptfds, struct timeval *timeout)
669
{
670
  int i;
666
671
667
int
672
  /*
668
win32_select(int nfds, fd_set *readfds, fd_set *writefds,
673
   * We have no good way of checking if a console handle is writeable,
674
   * so we assume they always are and let the blocking handle it
675
   */
676
  if (writefds != NULL) {
677
    for (i = 0;i < writefds->fd_count;i++) {
678
      if (isatty(writefds->fd_array[i]))
679
	break;
680
    }
681
682
    if (i != writefds->fd_count) {
683
      fd_set newwr;
684
685
      FD_ZERO(&newwr);
686
687
      for (;i < writefds->fd_count;i++) {
688
	if (isatty(writefds->fd_array[i]))
689
	  FD_SET(writefds->fd_array[i], &newwr);
690
      }
691
692
      if (readfds != NULL)
693
	FD_ZERO(readfds);
694
      if (writefds != NULL)
695
	FD_ZERO(writefds);
696
      if (exceptfds != NULL)
697
	FD_ZERO(exceptfds);
698
699
      memcpy(writefds, &newwr, sizeof(fd_set));
700
701
      return writefds->fd_count;
702
    }
703
  }
704
705
  if (readfds != NULL) {
706
    for (i = 0;i < readfds->fd_count;i++) {
707
      if (isatty(readfds->fd_array[i]))
708
	return win32_wait(readfds, writefds, exceptfds, timeout);
709
    }
710
  }
711
712
  return 0;
713
}
714
715
716
static int
717
_select_fifos(int nfds, fd_set *readfds, fd_set *writefds,
669
             fd_set *exceptfds, struct timeval *timeout)
718
             fd_set *exceptfds, struct timeval *timeout)
670
{
719
{
671
	int ret;
720
  int i;
672
	u_int i;
673
721
674
	/*
722
  if (writefds != NULL) {
675
	 * We have no good way of checking if a console handle is writeable,
723
    for (i = 0;i < writefds->fd_count;i++) {
676
	 * so we assume they always are and let the blocking handle it
724
      if (isafifo(writefds->fd_array[i]))
677
	 */
725
	return win32_wait(readfds, writefds, exceptfds, timeout);
678
	if (writefds != NULL) {
726
    }
679
		for (i = 0;i < writefds->fd_count;i++) {
727
  }
680
			if (isatty(writefds->fd_array[i]))
681
				break;
682
		}
683
728
684
		if (i != writefds->fd_count) {
729
  if (readfds != NULL) {
685
			fd_set newwr;
730
    for (i = 0;i < readfds->fd_count;i++) {
731
      if (isafifo(readfds->fd_array[i]))
732
	return win32_wait(readfds, writefds, exceptfds, timeout);
733
    }
734
  }
686
735
687
			FD_ZERO(&newwr);
736
  return 0;
737
}
688
738
689
			for (;i < writefds->fd_count;i++) {
690
				if (isatty(writefds->fd_array[i]))
691
					FD_SET(writefds->fd_array[i], &newwr);
692
			}
693
739
694
			if (readfds != NULL)
740
int
695
				FD_ZERO(readfds);
741
win32_select(int nfds, fd_set *readfds, fd_set *writefds,
696
			if (writefds != NULL)
742
             fd_set *exceptfds, struct timeval *timeout)
697
				FD_ZERO(writefds);
743
{
698
			if (exceptfds != NULL)
744
	int ret;
699
				FD_ZERO(exceptfds);
700
745
701
			memcpy(writefds, &newwr, sizeof(fd_set));
746
	ret = _select_ttys(nfds, readfds, writefds, exceptfds, timeout);
747
	if (ret != 0)
748
	  return ret;
702
749
703
			return writefds->fd_count;
750
	ret = _select_fifos(nfds, readfds, writefds, exceptfds, timeout);
704
		}
751
	if (ret != 0)
705
	}
752
	  return ret;
706
753
707
	/* Need to use more Windows specific APIs when dealing with non-sockets */
708
	if (readfds != NULL) {
709
		for (i = 0;i < readfds->fd_count;i++) {
710
			if (isatty(readfds->fd_array[i]) ||
711
			    isafifo(readfds->fd_array[i]))
712
				return win32_wait(readfds, writefds, exceptfds, timeout);
713
		}
714
	}
715
716
	ret = select(nfds, readfds, writefds, exceptfds, timeout);
754
	ret = select(nfds, readfds, writefds, exceptfds, timeout);
717
718
	if (ret == SOCKET_ERROR)
755
	if (ret == SOCKET_ERROR)
719
		errno = get_win32_error();
756
		errno = get_win32_error();
720
757

Return to bug 7231