示例#1
0
lword NonblockingSink::TimedFlush(unsigned long maxTime, size_t targetSize)
{
	m_blockedBySpeedLimit = false;

	size_t curBufSize = GetCurrentBufferSize();
	if (curBufSize <= targetSize && (targetSize || !EofPending()))
		return 0;

	if (!GetMaxBytesPerSecond())
		return DoFlush(maxTime, targetSize);

	bool forever = (maxTime == INFINITE_TIME);
	unsigned long timeToGo = maxTime;
	Timer timer(Timer::MILLISECONDS, forever);
	lword totalFlushed = 0;

	timer.StartTimer();

	while (true)
	{	
		size_t flushSize = UnsignedMin(curBufSize - targetSize, ComputeCurrentTransceiveLimit());
		if (flushSize || EofPending())
		{
			if (!forever) timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime());
			size_t ret = (size_t)DoFlush(timeToGo, curBufSize - flushSize);
			if (ret)
			{
				NoteTransceive(ret);
				curBufSize -= ret;
				totalFlushed += ret;
			}
		}

		if (curBufSize <= targetSize && (targetSize || !EofPending()))
			break;

		if (!forever)
		{
			timeToGo = SaturatingSubtract(maxTime, timer.ElapsedTime());
			if (!timeToGo)
				break;
		}

		double waitTime = TimeToNextTransceive();
		if (!forever && waitTime > timeToGo)
		{
			m_blockedBySpeedLimit = true;
			break;
		}

		WaitObjectContainer container;
		LimitedBandwidth::GetWaitObjects(container, CallStack("NonblockingSink::TimedFlush() - speed limit", 0));
		container.Wait((unsigned long)waitTime);
	}

	return totalFlushed;
}
示例#2
0
static PGPError
SizeAdvise (PGPPipeline *myself, unsigned long bytes)
{
	DefModContext *context;
	PGPError	error;

	pgpAssert (myself);
	pgpAssert (myself->magic == DEFMODMAGIC);

	context = (DefModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	if (bytes || context->scope_depth)
		return( kPGPError_NoErr );

	if (!context->finished) {
		/* It is a Bad Thing to call zip_finish multiple times. */
		zip_finish (context->zdcontext, context->ztcontext,
					context->zbcontext);
		context->finished = 1;
	}
	error = DoFlush (context);
	if (error)
		return error;

	return context->tail->sizeAdvise (context->tail, 0);
}
示例#3
0
static PGPError
Annotate (PGPPipeline *myself, PGPPipeline *origin, int type,
	  PGPByte const *string, size_t size)
{
	DefModContext *context;
	PGPError	error;

	pgpAssert (myself);
	pgpAssert (myself->magic == DEFMODMAGIC);

	context = (DefModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	error = DoFlush (context);
	if (error)
		return error;

	error = context->tail->annotate (context->tail, origin, type,
					string, size);
	if (!error)
		PGP_SCOPE_DEPTH_UPDATE(context->scope_depth, type);
	pgpAssert(context->scope_depth != -1);
	return error;
}
示例#4
0
文件: BitWriter.cpp 项目: ifzz/FDK
void CBitWriter::Flush()
{
	if (m_position > 0)
	{
		m_position = cDataSize;
		DoFlush();
	}
}
示例#5
0
LogStream::~LogStream()
{
	if (this->pSstream != NULL)
	{
		DoFlush();
		delete this->pSstream;
	}
}
示例#6
0
bool wxZlibOutputStream::Close()
 {
  DoFlush(true);
   deflateEnd(m_deflate);
   wxDELETE(m_deflate);
   wxDELETEA(m_z_buffer);

  return wxFilterOutputStream::Close() && IsOk();
 }
示例#7
0
bool wxZlibOutputStream::Close()
 {
  DoFlush(true);
   deflateEnd(m_deflate);
   delete m_deflate;

  m_deflate = NULL;
   delete[] m_z_buffer;
  m_z_buffer = NULL;

  return wxFilterOutputStream::Close() && IsOk();
 }
示例#8
0
EC_VOID AudioRender::HandleControlMsg(EC_VOIDP pMsg)
{
    MediaEngMsg *pMessage = (MediaEngMsg*)pMsg;
    switch (pMessage->nCmd)
    {
        case MediaEngCommand_Flush:
        {
            DoFlush();
            break;
        }
        default: break;
    }
}
示例#9
0
static PGPError
SizeAdvise (PGPPipeline *myself, unsigned long bytes)
{
	CiphrModContext *context;
	PGPError	error;
	PGPSize		hashSize;
	PGPByte		hashBuf[100];

	pgpAssert (myself);
	pgpAssert (myself->magic == CIPHERMODMAGIC);

	context = (CiphrModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	error = DoFlush (context);
	if (error)
		return error;

	if (context->scope_depth)
		return( kPGPError_NoErr );	/* Can't pass it through */

	if (bytes == 0) {
		/* Closing down */
		if (context->encrypt && context->hash) {
			PGPGetHashSize( context->hash, &hashSize );
			pgpAssert (hashSize <= sizeof(hashBuf));
			PGPFinalizeHash( context->hash, hashBuf );
			PGPFreeHashContext( context->hash );
			context->hash = NULL;
			Write( myself, hashBuf, hashSize, &error );
			if( IsPGPError( error ) )
				return error;
		}
	} else {
		if (context->encrypt && context->hash) {
			PGPGetHashSize( context->hash, &hashSize );
			bytes += hashSize;
		}
	}

	return context->tail->sizeAdvise (context->tail, bytes);
}
示例#10
0
static size_t
Write (PGPPipeline *myself, PGPByte const *buf, size_t size, PGPError *error)
{
	DefModContext *context;

	pgpAssert (myself);
	pgpAssert (myself->magic == DEFMODMAGIC);
	pgpAssert (error);

	context = (DefModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	zip_input (context->zdcontext, context->ztcontext, context->zbcontext,
			   (char const *)buf, size);
	*error = DoFlush (context);

	return size;
}
示例#11
0
static int
SizeAdvise (PGPPipeline *myself, unsigned long bytes)
{
	Context *context;
	PGPError	error;

	pgpAssert (myself);
	pgpAssert (myself->magic == MAGIC);

	context = myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	error = DoFlush (context);
	if (error)
		return error;

	return context->tail->sizeAdvise (context->tail, bytes)
}
示例#12
0
static int
Flush (PGPPipeline *myself)
{
	Context *context;
	PGPError	error;

	pgpAssert (myself);
	pgpAssert (myself->magic == MAGIC);

	context = myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	error = DoFlush (context);
	if (error)
		return error;

	return context->tail->flush (context->tail);
}
示例#13
0
static PGPError
Flush (PGPPipeline *myself)
{
	DefModContext *context;
	PGPError	error;

	pgpAssert (myself);
	pgpAssert (myself->magic == DEFMODMAGIC);

	context = (DefModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	error = DoFlush (context);
	if (error)
		return error;

	return context->tail->flush (context->tail);
}
示例#14
0
static PGPError
Flush(PGPPipeline *myself)
{
	AddHdrContext *context;
	PGPError	error;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);

	if (context->buffer) {
		error = FlushHeader(context);
		if (error)
			return error;

		/* Using the new packets -- force a flush of the buffer */
		if (context->dowrite) {
			error = FlushBuffer(context);
			if (error)
				return error;
		} else {
			error = ForceFlush(context);
			if (error)
				return error;
		}

	} else {
		/* Using the fifo */

		if (!context->dowrite)
			return kPGPError_BadParams;

		error = DoFlush(context);
		if (error)
			return error;
	}

	return context->tail->flush(context->tail);
}
示例#15
0
int main()
{
    int it;
    
    initIndex = 0;
    INIT_FUNS()
    
    for (it = 0; it < 100; it++)
    {
        int k;
        for (k = 0; k < 10; k++)
        {
            callIndex = it + k; 
            CALL_FUNS()
        }
        DoFlush();
   }
    
    return 0;
}
示例#16
0
void Sequence::Add(UIdType n)
{
   m_count++;

   // can we continue the current range?
   if ( HasCurrentRange() && n == m_last + 1 )
   {
      // continue it
      m_last++;
   }
   else // start a new one
   {
      if ( DoFlush() )
      {
         m_seq << ',';
      }

      m_seq << n;

      m_first =
      m_last = n;
   }
}
示例#17
0
static size_t
Write(PGPPipeline *myself, PGPByte const *buf, size_t size, PGPError *error)
{
	AddHdrContext *context;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);
	pgpAssert(error);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);
	pgpAssert(context->fifo);

	if (!context->dowrite) {
		/* Buffer into the fifo until we get a sizeadvise */

		return pgpFifoWrite (context->fifod, context->fifo, buf, size);
	}

	/*
	 * Ok, we've been given our size.  Flush the fifo and then be
	 * a write-through
	 */
	*error = DoFlush(context);
	if (*error)
		return 0;
	if (context->sizeknown && size > context->bytes) {
		pgpAssert(0);
		*error = kPGPError_SizeAdviseFailure;
		return 0;
	}

	size = context->tail->write(context->tail, buf, size, error);
	context->bytes -= size;
	return size;
}
示例#18
0
static size_t
Write (PGPPipeline *myself, PGPByte const *buf, size_t size, PGPError *error)
{
	Context *context;
	size_t written = 0;

	pgpAssert (myself);
	pgpAssert (myself->magic == MAGIC);
	pgpAssert (error);

	context = myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	do {
		*error = DoFlush (context);
		if (*error)
			return written;

		/*
		 * Now that we don't have anything buffered, bring in more
		 * data from the passed-in buffer, process it, and buffer
		 * that to write out.
		 */
		context->bufptr = context->buffer;
		/* XXX Set context->buflen to length of read-in material */
		/* XXX Read/processed data into context->buffer */
		buf += context->buflen;
		size -= context->buflen;
		written += context->buflen;

	} while (context->buflen > 0);
	/* Continue until we have nothing buffered */

	return written;	
}
示例#19
0
	/// Zapisuje pojedynczy znak
	void WriteChar(wchar_t Ch) { if (m_BufIndex == BUFFER_SIZE) DoFlush(); m_Buf[m_BufIndex++] = Ch; }
示例#20
0
bool Stream::Flush(Signal &sig)
{
	return DoFlush(sig);
}
示例#21
0
static size_t
Write (PGPPipeline *myself, PGPByte const *buf, size_t size, PGPError *error)
{
	CiphrModContext *context;
	PGPSize written = 0;
	PGPSize newdatasize = 0;

	pgpAssert (myself);
	pgpAssert (myself->magic == CIPHERMODMAGIC);
	pgpAssert (error);

	context = (CiphrModContext *)myself->priv;
	pgpAssert (context);
	pgpAssert (context->tail);

	do {
		PGPSize bufspace;
		PGPByte *bufend;

		*error = DoFlush (context);
		if (*error)
			return written;

		/*
		 * Now that we dont have anything buffered, bring in more
		 * data from the passed-in buffer, process it, and buffer
		 * that to write out.
		 */
		if (context->buftake > context->bufput)
			bufend = context->buftake;
		else
			bufend = context->buffer + sizeof(context->buffer);
		bufspace = bufend - context->bufput;
		
		newdatasize = pgpMin (size, bufspace);
		if (newdatasize > sizeof(context->buffer)
						  - (context->buflen + context->buftaillen) )
			newdatasize = sizeof(context->buffer)
						  - (context->buflen + context->buftaillen);
		context->buflen += newdatasize;

		/* Tell user how many bytes we're doing, allow him to interrupt */
		if (context->progress && newdatasize)
		{
			if (context->progress(newdatasize) < 0)
			{
				/* User requested interruption */
				*error = kPGPError_UserAbort;
				return written;
			}
		}

		if (newdatasize > 0) {
			if (context->encrypt) {
				if (context->hash) {
					PGPContinueHash( context->hash, buf, newdatasize );
				}
				pgpCFBEncryptInternal (context->cfb, (PGPByte *)buf,
						   newdatasize, context->bufput );
			} else {
				/* Hashing is handled in DoFlush */
				pgpCFBDecryptInternal (context->cfb, (PGPByte *)buf,
						   newdatasize, context->bufput );
			}
			buf += newdatasize;
			size -= newdatasize;
			written += newdatasize;
			context->bufput += newdatasize;
			if (context->bufput == context->buffer+sizeof(context->buffer))
				context->bufput = context->buffer;
		}

	} while (newdatasize > 0);
	/* Continue until we have nothing buffered */

	return written;	
}
示例#22
0
文件: calendar.c 项目: hoijui/Remind
static void GenerateCalEntries(int col)
{
    int r;
    Token tok;
    char const *s;
    Parser p;

/* Do some initialization first... */
    ClearGlobalOmits();
    DestroyOmitContexts();
    DestroyVars(0);
    NumTriggered = 0;

    r=IncludeFile(InitialFile);
    if (r) {
	fprintf(ErrFp, "%s %s: %s\n", ErrMsg[E_ERR_READING], InitialFile, ErrMsg[r]);
	exit(1);
    }

    while(1) {
	r = ReadLine();
	if (r == E_EOF) return;
	if (r) {
	    Eprint("%s: %s", ErrMsg[E_ERR_READING], ErrMsg[r]);
	    exit(1);
	}
	s = FindInitialToken(&tok, CurLine);

	/* Should we ignore it? */
	if (NumIfs &&
	    tok.type != T_If &&
	    tok.type != T_Else &&
	    tok.type != T_EndIf &&
	    tok.type != T_IfTrig &&
	    ShouldIgnoreLine())
	{
	    /* DO NOTHING */
	}
	else {
	    /* Create a parser to parse the line */
	    CreateParser(s, &p);

	    switch(tok.type) {

	    case T_Empty:
	    case T_Comment:
		break;

	    case T_ErrMsg:  r=DoErrMsg(&p);  break;
	    case T_Rem:     r=DoCalRem(&p, col); break;
	    case T_If:      r=DoIf(&p);      break;
	    case T_IfTrig:  r=DoIfTrig(&p);  break;
	    case T_Else:    r=DoElse(&p);    break;
	    case T_EndIf:   r=DoEndif(&p);   break;
	    case T_Include: r=DoInclude(&p); break;
	    case T_Exit:    DoExit(&p);	     break;
	    case T_Set:     r=DoSet(&p);     break;
	    case T_Fset:    r=DoFset(&p);    break;
	    case T_UnSet:   r=DoUnset(&p);   break;
	    case T_Clr:     r=DoClear(&p);   break;
	    case T_Flush:   r=DoFlush(&p);   break;
	    case T_Debug:   break;  /* IGNORE DEBUG CMD */
	    case T_Dumpvars: break; /* IGNORE DUMPVARS CMD */
	    case T_Banner:  break;  /* IGNORE BANNER CMD */
	    case T_Omit:    r=DoOmit(&p);
		if (r == E_PARSE_AS_REM) {
		    DestroyParser(&p);
		    CreateParser(s, &p);
		    r=DoCalRem(&p, col);
		}
		break;
	    case T_Pop:     r=PopOmitContext(&p);     break;
	    case T_Push:    r=PushOmitContext(&p);    break;
	    case T_Preserve: r=DoPreserve(&p);        break;
	    case T_RemType: if (tok.val == RUN_TYPE) {
		r=DoRun(&p);
		break;
	    } else {
		CreateParser(CurLine, &p);
		r=DoCalRem(&p, col);
		break;
	    }

	    /* If we don't recognize the command, do a REM by default */
	    /* Note:  Since the parser hasn't been used yet, we don't */
	    /* need to destroy it here. */

	    default:        CreateParser(CurLine, &p);
		r=DoCalRem(&p, col);
		break;
	    }
	    if (r && (!Hush || r != E_RUN_DISABLED)) Eprint("%s", ErrMsg[r]);

	    /* Destroy the parser - free up resources it may be tying up */
	    DestroyParser(&p);
	}
    }
}
示例#23
0
	/// Wymusza opró¿nienie bufora i wys³anie pozosta³ych w nim danych do strumienia
	void Flush() { if (m_BufIndex > 0) DoFlush(); }
示例#24
0
STDMETHODIMP CRFSOutputPin::WaitForNext (DWORD dwTimeout, IMediaSample **ppSample, DWORD_PTR *pdwUser)
{
    HRESULT ret = S_OK;
    DWORD r;
    ReadRequest *rr;

    if (!(ppSample && pdwUser))
        return E_POINTER;

    if (m_flush)
        return DoFlush (ppSample, pdwUser);

    m_lock.Lock ();
    rr = m_requests.UnlinkLast ();
    m_lock.Unlock ();

    Anchor<ReadRequest> arr (&rr);

    while (!rr)
    {
        r = WaitForSingleObject (m_event, dwTimeout);

        if (m_flush)
            return DoFlush (ppSample, pdwUser);

        if (r == WAIT_TIMEOUT)
            return VFW_E_TIMEOUT;

        if (r == WAIT_FAILED)
        {
            ErrorMsg (GetLastError (), L"CRFSOutputPin::WaitForNext - WaitForSingleObject");
            return E_FAIL;
        }

        m_lock.Lock ();
        rr = m_requests.UnlinkLast ();
        m_lock.Unlock ();

        if (!rr)
            DbgLog((LOG_TRACE, 2, L"Got nothing?!?!"));
    }

    DWORD count, read, acc = 0;
    SubRequest *sr = rr->subreqs.First ();

    count = rr->count;

    HANDLE *hArray = new HANDLE [count];

    for (DWORD i = 0; i < count; i ++)
    {
        hArray [i] = sr->o.hEvent;
        sr = rr->subreqs.Next (sr);
    }

    // FIXME: Any time spent waiting in WaitForSingleObject above should be subtracted from dwTimeout
    r = WaitForMultipleObjects (count, hArray, TRUE, dwTimeout);

    delete [] hArray;

    if (r == WAIT_TIMEOUT)
    {
        // Put it back into the list.
        m_lock.Lock ();
        arr.Release ();
        m_requests.InsertLast (rr);
        m_lock.Unlock ();
        return VFW_E_TIMEOUT;
    }

    *pdwUser = rr->dwUser;
    *ppSample = rr->pSample;

    if (r == WAIT_FAILED)
    {
        ErrorMsg (GetLastError (), L"CRFSOutputPin::WaitForNext - WaitForMultipleObjects");
        return E_FAIL;
    }

    while (sr = rr->subreqs.UnlinkFirst ())
    {
        read = 0;

        if (!GetOverlappedResult (sr->file, &sr->o, &read, TRUE))
        {
            ErrorMsg (GetLastError (), L"CRFSOutputPin::WaitForNext - GetOverlappedResult");
            acc += read;
            delete sr;
            ret = S_FALSE; // FIXME: Should probably return EOF if that's what happened.
            break;
        }

        acc += read;

        // TODO: Try to recover if read != sr->expected.
        if (read != sr->expected)
        {
            DbgLog((LOG_TRACE, 2, L"CRFSOutputPin::WaitForNext Got %lu expected %lu!", read, sr->expected));
            delete sr;
            ret = S_FALSE;
            break;
        }
        delete sr;
    }

    rr->pSample->SetActualDataLength (acc);

    return ret;
}
示例#25
0
	/// Writes single char/byte
	void WriteChar(char ch) { if (m_WriteBufIndex == m_WriteBufSize) DoFlush(); m_WriteBuf[m_WriteBufIndex++] = ch; }
void PVAuthorEngineNodeUtility::Run()
{
    LOG_STACK_TRACE((0, "PVAuthorEngineNodeUtility::Run: Enter"));

    if (iCmdQueue.empty())
        return;

    PVAENodeUtilCmd cmd = iCmdQueue[0];
    if (cmd.iNodes.empty())
    {
        LOG_ERR((0, "PVAuthorEngineNodeUtility::Run: Error - cmd.iNodes is empty"));
        CompleteUtilityCmd(cmd, PVMFFailure);
        return;
    }

    PVMFStatus status = PVMFFailure;
    LOG_STACK_TRACE((0, "PVAuthorEngineNodeUtility::Run: cmd.iType=%d", cmd.iType));
    switch (cmd.iType)
    {
        case PVAENU_CMD_CONNECT:
            status = DoConnect(cmd);
            break;
        case PVAENU_CMD_DISCONNECT:
            status = DoDisconnect(cmd);
            break;
        case PVAENU_CMD_QUERY_UUID:
            status = DoQueryUuid(cmd);
            break;
        case PVAENU_CMD_QUERY_INTERFACE:
            status = DoQueryInterface(cmd);
            break;
        case PVAENU_CMD_INIT:
            status = DoInit(cmd);
            break;
        case PVAENU_CMD_PREPARE:
            status = DoPrepare(cmd);
            break;
        case PVAENU_CMD_START:
            status = DoStart(cmd);
            break;
        case PVAENU_CMD_PAUSE:
            status = DoPause(cmd);
            break;
        case PVAENU_CMD_STOP:
            status = DoStop(cmd);
            break;
        case PVAENU_CMD_FLUSH:
            status = DoFlush(cmd);
            break;
        case PVAENU_CMD_RESET:
            status = DoReset(cmd);
            break;
        default:
            status = PVMFFailure;
            break;
    }

    if (status != PVMFPending)
        CompleteUtilityCmd(cmd, status);

    LOG_STACK_TRACE((0, "PVAuthorEngineNodeUtility::Run: Exit"));
}