void copyFdSet(fd_set *src, fd_set *dest)
{
    // fd_set struct has one member: __fds_bits. which is an array of longs.
    // length of that array is FD_SETSIZE/NFDBITS
    // see /usr/include/sys/select.h
    if (src == NULL)
        dest = NULL;
    if (dest == NULL)
        return;
    int length_fd_bits = FD_SETSIZE/NFDBITS;
    int i = 0;
    for (i = 0; i < length_fd_bits; i++) {
        __FDS_BITS(dest)[i] = __FDS_BITS(src)[i];
    }
}
Exemple #2
0
/* external function definitions */
void 
fdsinit(void)
{
  static char fnc[] = "fdsinit";
  int i;

  if ((i = getdtablesize()) < 0) {
    Warn("%t %s(): warning: getdtablesize(): %m\n", fnc);
  } else {
    fds_size = i;
  }

  fds_howmany = howmany(fds_size, NFDBITS);
  fds_sizeof = fds_howmany * sizeof(fd_mask);

  fds_all = fdsalloc();
  for (i = 0; i < fds_howmany; i++) {
    __FDS_BITS(fds_all)[i] = (fd_mask) (~0);
  }
  fds_none = fdsalloc();
  fds_r = fdsalloc();
  fds_ra = fdsalloc();
  fds_w = fdsalloc();
  fds_wa = fdsalloc();
  fds_x = fdsalloc();
  fds_xa = fdsalloc();

  return;
}
Exemple #3
0
void
_FD::FDSet::setAll()
{
    unsigned int i;
    fd_set *arr = (this);
    for (i = 0; i < sizeof (fd_set) / sizeof (fd_mask); ++i) {
      __FDS_BITS (arr)[i] = ~((fd_mask)0);
    }
}
Exemple #4
0
/*
 * called just post exec, state transfered is readyForLazy bit vector
 */
/*static*/ void
_FD::ClassInit(FDSet *fromParent)
{
    // One instance
    FileTable = new _FD;
    /*
     * no need to initialize the fd_list except for cleaner
     * errors.
     */
    FDSet::Sanity();
    FileTable->lock.init();
    FileTable->pollsLock.init();
    FileTable->blockedPolls.init();

    if (fromParent == NULL) {
	FileTable->active.zero();
	FileTable->readyForLazy.zero();
    } else {
	uval fd;
	uval word;
	uval mask;

	fromParent->copyTo(&FileTable->active);
	fromParent->copyTo(&FileTable->readyForLazy);
	// NULL all list elements marked as active to allow check
	// on NULL in getFD

	// FIXME: this can be done faster/better
	for (word=0;word<FDSet::Words;word++) {
	    if ((mask=__FDS_BITS(&(FileTable->active))[word])) {
		fd = word*FDSet::BitsPerWord;
		while (mask) {
		    if (mask&1) {
			FileTable->fdrec[fd].ref = NULL;
			FileTable->fdrec[fd].poll= NULL;
		    }
		    fd++;
		    mask>>=1;
		}
	    }
	}
    }