Exemplo n.º 1
0
NetIoBuffer::~NetIoBuffer()
{
	MemoryBlock* buffer;

	while (buffer = PopData())
	{
		g_memoryPool.FreeBuffer(buffer);
	}
}
Exemplo n.º 2
0
// result is the last node (if any... which is a peekstack)
PLAYER_PATH_NODE LAYER::UnlayPath( int nLayers )
{
	// unwind to, and including this current spot.
	// this is to handle when the line intersects itself.
	// other conditions of unlaying via pathways may require
	// other functionality.
	int n;
	PLAYER_PATH_NODE node;// = (PLAYER_PATH_NODE)PopData( &pds_path );
	lprintf( WIDE("overlapped self at path segment %d"), nLayers );
	for( n = nLayers; (n && (node = (PLAYER_PATH_NODE)PopData( &pds_path ))), n; n-- )
	{
		lprintf( WIDE("Popped node %d(%p)"), n, node );
		// grab the NEXT node...
		// if it has bForced set... then this node must exist.
		PLAYER_PATH_NODE next = (PLAYER_PATH_NODE)PeekData( &pds_path );
		if( next && next->flags.bForced )
		{
			DebugBreak();
			node->flags.ForeDir = NOWHERE;
			return node;
		}
		if( node && node->flags.bForced )
		{
			DebugBreak();
         // this is SO bad.
		}
		//if( node->x == dest_x && node->y == dest_y )
		{
			//lprintf( WIDE("And then we find the node we overlaped...") );
		}
	}
	lprintf( WIDE("Okay done popping... %d, %p"), n, node );
	if( node )
	{
		PLAYER_PATH_NODE next = (PLAYER_PATH_NODE)PeekData( &pds_path );
		// set this as nowhere, so that we can easily just step forward here..
		if( !next )
		{
			if( !node->flags.bForced )
			{
				node->flags.ForeDir = NOWHERE;
			}
			PushData( &pds_path, node );
			return node;
		}
		if( !nLayers
			&& next->flags.bForced
			&& next->flags.BackDir != NOWHERE )
		{
			// if it was forced, then this MUST be here.  There is a reason.
			// there is also a way to end this reason, and unlay 0 path.  This
			// releases the foredir to anything.  This may be used for error correction path
			// assumptions?
			DebugBreak();
			if( next->flags.bTry )
			{
				node = (PLAYER_PATH_NODE)PopData(&pds_path );
				// this is the second attempt
				if( !node->flags.bFlopped )
				{
					node->flags.bFlopped = 1;
					node->flags.ForeDir = LeftOrRight( Opposite( node->flags.BackDir ), 1 );
               return node;
				}
			}
			next->flags.bForced = 0;
		}
		else
		{
			next->flags.ForeDir = NOWHERE;
         lprintf( WIDE("this node itself is okay...") );
		}
      return next;
	}
   return NULL;
}
Exemplo n.º 3
0
bool CWRequest::ReceiveFromBridge(string sSessionID, string* pRequestID, bool* pSetResponseCookie, bool* pSecure, bool* pKeepAlive, bool bLongPolling, int iTimeoutMS, CWCallbackFunction pCallback, const void* pCallbackArg, int iCallbackIntervalMS, string* pErrorMessage)
{
    if(sSessionID == "")
    {
        if(pErrorMessage != NULL) *pErrorMessage = "session_id is empty.";
        return false;
    }

    Clear();

    // ---
    // read request id from queue
    // ---
    string queue_filename = "";
    if(bLongPolling)
    {
        queue_filename = TempDir() + sSessionID + ".queue_lp";

        // if no long polling request is waiting, return false
        int queue_size = 0;
        if(!FileExists(queue_filename, &queue_size))
            return false;

        if(queue_size <= 0)
            return false;
    }
    else
        queue_filename = TempDir() + sSessionID + ".queue";

    char* buffer = NULL;
    int buffer_size = 0;
    if(!PopData(queue_filename, (void**)&buffer, &buffer_size, iTimeoutMS, pCallback, pCallbackArg, iCallbackIntervalMS, pErrorMessage))
        return false;

    string request_id(buffer, buffer_size);
    free(buffer);

    // ---
    // read request from file
    // ---
    string request_filename = TempDir() + request_id + ".request";

    int fd = -1;
    int file_size = 0;
    if(!FileOpenExistingAndLock(request_filename, REQUEST_RECEIVE_TIMEOUT, &fd, &file_size, pErrorMessage))
        return false;

    // query
    if(!FileReadStringList(fd, Query, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // post
    if(!FileReadStringList(fd, Post, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // cookie
    if(!FileReadStringList(fd, Cookie, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // env
    if(!FileReadStringList(fd, Env, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // unlock file
    FileUnlockAndClose(fd, NULL);

    // delete file
    FileDelete(request_filename, NULL);

    if(Cookie->GetValue("session_id") != sSessionID)
    {
        Cookie->SetValue("session_id", sSessionID);
        *pSetResponseCookie = true;
    }
    else
        *pSetResponseCookie = false;

    if(Env->GetValue("HTTPS") == "on")
        *pSecure = true;
    else
        *pSecure = false;

    if(pKeepAlive != NULL) *pKeepAlive = GetValue("keep_alive") == "1" || GetValue("keep_alive") == "true";

    *pRequestID = request_id;

    return true;
}
Exemplo n.º 4
0
Arquivo: calc.c Projeto: uning/system
int main(int argc, char **argv)
{
	int FState,LState,GramState,CalcuState;
	double result,TempData;
	char TempOprt;
	STK.data_curp=STK.data_stack;
	STK.oprt_curp=STK.oprt_stack;
	
	if (argc < 2)
	{
		Usage(argv[0]);
		return 1;
	}
	
	for (int i = 1; i < argc; i++)
	{
		strncat (liyx, argv[i], strlen(argv[i]));
	}
	
	strncat(liyx, "\n", strlen("\n"));
	
		
		clear(&STK);
		EXP_INIT=YES;
		BRACKET_COUNT=0;
		LState=100;
		GramState=1;
		CalcuState=1;
		
		do{
			FState=LState;
			if((LState=getexp(&STK.data_in,&STK.oprt_in))<0){
				error(LState);
				break;
			}
			if((GramState=checkgram(FState,LState))<0){
				error(GramState);
				break;
			}
			if(LState==1||LState==2||LState==3||LState==4)
				PushData(&STK);
			if(LState==2||(LState==6&&(FState==3||FState==7))){
				TempOprt=STK.oprt_in;
				STK.oprt_in='*';
			}
			while(priority(*(STK.oprt_curp),STK.oprt_in)>0&& *STK.oprt_curp!='(' && STK.oprt_curp!=STK.oprt_stack)
			{
				PopData(&STK);
				TempData=STK.data_out;
				PopData(&STK);
				PopOprt(&STK);
				CalcuState=calculat(STK.data_out,STK.oprt_out,TempData,&result);
				if(CalcuState<0) break;
				STK.data_in=result;
				PushData(&STK);
			}
			if(*STK.oprt_curp=='(' && (LState==3||LState==7)) PopOprt(&STK);
			if(!(LState==3||LState==4||LState==7||LState==8)) PushOprt(&STK);
			if(LState==2||(LState==6&&(FState==3||FState==7))){
				STK.oprt_in=TempOprt;
				PushOprt(&STK);
			}
			if(CalcuState<0){
				error(CalcuState);
				break;
			}

		}while (LState!=4&&LState!=8);

		if((LState==4||LState==8)&&BRACKET_COUNT!=0) error(-8);


		if((LState==4||LState==8) && BRACKET_COUNT==0 && GramState>0 && CalcuState>0 && FState+LState!=108)
			printf("%f\n",STK.data_in);

	return 0;
}