Пример #1
0
/* Loop the readStream list, and return the already stream */
int StreamManager::HttpParseHeader(){

    WebStream *webStream = NULL;
    list<WebStream *>::iterator ite;
    
    ESLog::ISLog("HTTP HEADER SETS PARSE START\n", __FILE__, __LINE__);

    ESLog::ISLog("readStreamSize:%d\n", __FILE__, __LINE__, this->readStream.size());
    /* loop */
    for( ite = this->readStream.begin(); ite != this->readStream.end(); ++ite ) {

        int result = -1;
        webStream = *ite;

        
        ESLog::ISLog("read webStream->http ptr:%u\n", __FILE__, __LINE__, webStream->GetHttpPtr());
        ESLog::ISLog("read webStream->fd:%d\n", __FILE__, __LINE__, webStream->GetTcpConnFd());
        ESLog::ISLog("read webStream->Status:%s\n", __FILE__, __LINE__, webStream->GetStatusDesc());

        /* if the readStream has writed */
        if( webStream->GetStatus() == WSTREAM_WRITE ) {
            continue;
        }

        /* is http protocol parser exist */
        if( !webStream->IsHttpParserExist() ) {
            ESLog::ISLog("An new Http Object Create \n", __FILE__, __LINE__ );
            Http *httpParser = new Http();
            httpParser->SetWebStreamPtr(webStream);
            webStream->SetHttpParser(httpParser);
            ESLog::ISLog("New Http read webStream->http ptr:%u\n", __FILE__, __LINE__, webStream->GetHttpPtr());
        }

        ESLog::ISLog("read WebStream->HttpStatus:%s\n", __FILE__, __LINE__, webStream->GetHttpPtr()->GetStatusDesc());

        /* if the header has parserd*/
        if( webStream->GetHttpPtr()->GetStatus() == HTTP_REQHEAD_PARSED  ) {
            continue;
        }

        /* if the latest http parsed over, again init http object */
        if( webStream->GetHttpPtr()->GetStatus() == HTTP_RESSEND_OVER  ) {
            
            webStream->GetHttpPtr()->ReInit();
        }

        /* parse the http header, if the http header parsed, then we give the webStream to the
           session/application, it will send to a idle thread to tackle the session
           if return 0, the header parser over; if return > 0 , it still to parser;
           if return < 0 , there is an error happend */
        result = webStream->ParseHttpHeader();  // <--i) set the status of the webStream , http Status
        if( result < 0 ) {
            
            ESLog::ISLog("ParseHttpHeader Erorr START\n", __FILE__, __LINE__ );
            webStream->SetStatus(WSTREAM_ERROR);
            //webStream->GetHttpPtr()->SetStatus(HTTP_RESSEND_OVER);
            //Server::Instance()->GetIOLoop().ModToReadEventFd(webStream->GetTcpConnFd(), (void *)webStream);
            //webStream->ReInit();
            //this->DeleteReadWebStream(webStream);

            Server::Instance()->GetIOLoop().DelReadEventFd(webStream->GetTcpConnFd());

            //webStream->FreeTcpConn();
            //webStream->FreeHttp();
            //webStream->ReInit();
            //webStream->SetStatus(WSTREAM_UNINITILIZED);
            //this->AddIdleStream(webStream);

            ESLog::ISLog("ParseHttpHeader Erorr END\n", __FILE__, __LINE__ );
            continue;
            //break;
            //return  result;  // an error happend
        }

        /* the header has passed  */
        if( webStream->GetHttpPtr()->GetStatus() == HTTP_REQHEAD_PARSED ) {
            //webStream->GetHttpPtr()->SetStatus(2);
            ESLog::ISLog("there is http head parsed\n", __FILE__, __LINE__);
            webStream->SetStatus(WSTREAM_UNDISPATHED);
            this->AddTaskWebStream(webStream);
        }
        
    }

    ESLog::ISLog("HTTP HEADER SETS PARSE END\n", __FILE__, __LINE__);
}