Beispiel #1
0
/*
int relayFile2Fifo(FILE *rfp,PCStr(regfile),PCStr(fifo)){
*/
int relayFile2Fifo(FILE *fs,FILE *rfp,PCStr(regfile),PCStr(fifo)){
	FILE *ffp;
	CStr(buf,8*1024);
	int siz,rem,rcc,rcc1;
	int start;
	int last = time(0);

	ffp = fopen(fifo,"w+");
if( lGATEWAY() )
sv1log("----FIFO relay OPEN %X %s\n",p2i(ffp),fifo);
	if( rfp == 0 || ffp == 0 )
		return -1;

	rcc = 0;
	start = time(0);
	for(;;){
		siz = File_size(regfile);
		if( siz < 0 ){
			break;
		}
		rem = siz - ftell(rfp);

		if( lVERB() )
		DEBUG("--SFTP-DATA rem[%d] = %d (%d - %d)\n",
			fileno(rfp),rem,iftell(rfp),File_size(regfile));

		if( 0 < rem ){
			rcc1 = fread(buf,1,sizeof(buf),rfp);
			if( rcc1 <= 0 )
				break;
			rcc += rcc1;
			fwrite(buf,1,rcc1,ffp);
			last = time(0);
		}else{
			if( !File_is(fifo) ){
				/* fifo is unlinked on recv. complete */
				break;
			}
			fflush(ffp);
			if( 10 < time(0)-start ){
				if( fPollIn(fs,1) == 0
				 //&& IsAlive(fileno(fifo))
				 && time(0)-last < SFTP_DATA_TIMEOUT ){
					/* no prompt for the next command yet */
				}else
				break;
			}
			msleep(100);
		}
	}
	fflush(ffp);
	fclose(ffp);
if( lGATEWAY() )
sv1log("####@@@@ FIFO relay DONE %d %s\n",rcc,fifo);
	return rcc;
}
Beispiel #2
0
bool VcfFileReader::processNewSection()
{
    myNewSection = false;
    
    // Check to see if the index file has been read.
    if(myVcfIndex == NULL)
    {
        myStatus.setStatus(StatGenStatus::FAIL_ORDER, 
                           "Cannot read section since there is no index file open");
        throw(std::runtime_error("SOFTWARE BUG: trying to read a VCF record by section prior to opening the VCF Index file."));
        return(false);
    }

    if(myFilePtr == NULL)
    {
        myStatus.setStatus(StatGenStatus::FAIL_ORDER, 
                           "Cannot read section without first opening the VCF file.");
        throw(std::runtime_error("SOFTWARE BUG: trying to read a VCF record by section prior to opening the VCF file."));
        return(false);
    }

    // Using random access, so can't buffer
    myFilePtr->disableBuffering();

    uint64_t startPos = 0;
    // Find where this section starts in the file.
    if(!myVcfIndex->getStartPos(mySectionChrom.c_str(),
                                mySection1BasedStartPos, 
                                startPos))
    {
        // Didn't find the position.
        myStatus = StatGenStatus::NO_MORE_RECS;
        return(false);
    }
    if(startPos != (uint64_t)iftell(myFilePtr))
    {
        // Seek to the start position.
        if(ifseek(myFilePtr, startPos, SEEK_SET) != true)
        {
            // seek failed, return failure.
            myStatus.setStatus(StatGenStatus::FAIL_IO, 
                               "Failed to seek to the specified section");
            return(false);
        }
    }
    return(true);
}
Beispiel #3
0
void put_cde_slots(IFILE *file, int ifaxq)					/*;put_cde_slots*/
{
	long	dpos;

	dpos = iftell(file); /* get current position */
	putnum(file, "n-code_slots", tup_size(CODE_SLOTS));
	putnum(file, "n-data-slots", tup_size(DATA_SLOTS));
	putnum(file, "n-exception-slots", tup_size(EXCEPTION_SLOTS));
	put_slot(file, CODE_SLOTS);
	put_slot(file, DATA_SLOTS);
	put_slot(file, EXCEPTION_SLOTS);
	/* now replace word at start of  file with long giving offset to 
	 *start of information just written.
	 */
	file->fh_slots = dpos;
	ifclose(file);
}
Beispiel #4
0
 bool SamFile::ensureIndexedReadPosition()
 {
     // If no sections are specified, return true.
     if(myRefID == BamIndex::REF_ID_ALL)
     {
         return(true);
     }

     // Check to see if we have more to read out of the current chunk.
     // By checking the current position in relation to the current
     // end chunk.  If the current position is >= the end of the
     // current chunk, then we must see to the next chunk.
     uint64_t currentPos = iftell(myFilePtr);
     if(currentPos >= myCurrentChunkEnd)
     {
         // If there are no more chunks to process, return failure.
         if(myChunksToRead.empty())
         {
             myStatus = SamStatus::NO_MORE_RECS;
             return(false);
         }
         
         // There are more chunks left, so get the next chunk.
         Chunk newChunk = myChunksToRead.pop();
         
         // Move to the location of the new chunk if it is not adjacent
         // to the current chunk.
         if(newChunk.chunk_beg != currentPos)
         {
             // New chunk is not adjacent, so move to it.
             if(ifseek(myFilePtr, newChunk.chunk_beg, SEEK_SET) != true)
             {
                 // seek failed, cannot retrieve next record, return failure.
                 myStatus.setStatus(SamStatus::FAIL_IO, 
                                    "Failed to seek to the next record");
                 return(false);
             }
         }
         // Seek succeeded, set the end of the new chunk.
         myCurrentChunkEnd = newChunk.chunk_end;
     }
     return(true);
 }