int ProcessFhSet(nfhs_t pv_Nfhs, fh_set *pp_Fhs, fd_set *pp_Fds) { int lv_Fd = 0; struct fh_set lv_Fhs; if(pp_Fhs != NULL) { lv_Fhs.FhArray = pp_Fhs->FhArray; STFS_FH_ZERO(pp_Fhs); for (int i = 0; i < pv_Nfhs; i++) { if(i < (int)lv_Fhs.FhArray.size()) { STFS_ExternalFileHandle *lp_Efh = STFS_ExternalFileHandle::GetExternalFileHandle(lv_Fhs.FhArray[i]); if (! lp_Efh) { TRACE_PRINTF2(1, "Error in obtaining External File Handle for %ld\n", lv_Fhs.FhArray[i]); return -1; } if(((lp_Efh->OpenFlagsGet())&O_NONBLOCK) == O_NONBLOCK) { lv_Fd = lp_Efh->GetFD(); if(lv_Fd >= 0) { if(FD_ISSET(lv_Fd, pp_Fds)) { //Insert into fh_set pp_Fhs->FhArray.push_back(pp_Fhs->FhArray[i]); } } } } } } return 0; }
RESULT SQScratchFile::doSelect(Int32 index, DWORD timeout, EPendingIOType type, Int32& err) { if(scratchSpace_->getScratchOverflowMode() == SCRATCH_MMAP) { return SCRATCH_SUCCESS; } fd_set fds; struct timeval tv; Int32 retval; Int64 tLeft = LONG_MAX; if (timeout >= 0) tLeft = timeout * 10000; STFS_FH_ZERO(&fds); STFS_FH_SET(fileHandle_[index].fileNum, &fds); /* Wait up to five seconds. */ Int64 tBegin = 0; if (timeout == -1) {// infinit wait switch(type) { case PEND_READ: retval = STFS_select(fileHandle_[index].fileNum+1, &fds, NULL, NULL, NULL); break; default: case PEND_WRITE: retval = STFS_select(fileHandle_[index].fileNum+1, NULL, &fds, NULL, NULL); break; } } else { tv.tv_sec = tLeft / 1000000; tv.tv_usec = tLeft % 1000000; tBegin = juliantimestamp_(); switch(type) { case PEND_READ: retval = STFS_select(fileHandle_[index].fileNum+1, &fds, NULL, NULL, &tv); break; default: case PEND_WRITE: retval = STFS_select(fileHandle_[index].fileNum+1, NULL, &fds, NULL, &tv); break; } } if (retval == 0) { // timeout, nothing available return IO_NOT_COMPLETE; } if (retval < 0) // error { err = errno; return SCRATCH_FAILURE; } return SCRATCH_SUCCESS; }