void XCatch::ResetTime() { XU8 s=XFile::XBINARY|XFile::XREAD|XFile::XWRITE; if(!m_file.Open(m_strFile,s)) return; XCHeader hd; m_file.Read(&hd,sizeof(hd)); XTime time; time.SetCurrentTime(); hd.nTime=time.GetTime(); m_file.Seek(0,XFile::XSEEK_SET); m_file.Write(&hd,sizeof(hd)); m_file.Close(); }
XU8 XClient::Connect(CONNECTREQ &data,XU8 nCharset,XU8 bSync) { if(m_hConnect.IsEvent(0)) return 0;//XFALSE; XU8 nApp = GetAppProto(); m_nProtoType = nApp; if(m_pInfo->nProtocol != XPROTO_UDP && m_pConnect!=XNULL ) { m_pConnect->DisConnect(); } m_con.Reset(XFALSE); if(data.data.GetSize()) { XU8Array&out=m_con.outData; out.Append(data.data); if(data.strContentType.IsEmpty()) { XContentType type(XCNT::CAPPLICATION,XCNT::TX_WWW_FORM_URLENCODED); m_con.strContentType=type.GetTypeString();//strCntTypeURL; } else { m_con.strContentType=data.strContentType; } } m_con.URL=data.URL; m_con.strRefer=data.strRefer; m_con.nMethod=data.nMethod; m_con.strHeaders.Append(data.strHeaders); //m_res.Reset(nCharset); //{//for DEBUG // CONNECTINFO*pCon=GetConnectInfo(); // RESPONSEINFO*pInfo=GetResponseInfo(); // if(strcmp(m_con.URL.m_strURL,"C:/game.dat") == 0) // int a = 0;//pInfo->strFilterURL="D:\\WorkAS3\\debug.flt"; //} XTime time; XU32 l=0; XBOOL bFilter=XFALSE; if(!IsNeedCache()) bFilter=true; bool bStatic=false; XU8 nType = bFilter?XCatch::XC_NONE:m_catch.CatchDetect(m_con,time,l,data.bForward,bStatic); if(m_con.nMethod!=XEM::GET) bStatic=false; if(nType==XCatch::XC_OK) { if(bSync&&l<RECBUFFER&&m_catch.GetCatchData()) { return DATAOK; } else if(m_pConnect!=&m_catch) { XTime nowTime; nowTime.SetCurrentTime(); if(!bStatic||nowTime.GetDay()-time.GetDay()>4) { XString8 strTime; time.GetTime(strTime); XEH h; XSortString8::ESetValue(m_con.strHeaders,h[XEH::IF_MODIFIED_SINCE],strTime); } else { m_pConnectOld=m_pConnect; m_pConnect=&m_catch; nApp=GetAppProto(); } } } m_res.Reset(nCharset); XU8 nNew=GetAppProto(); m_nProtoType=nNew; if(nApp!=nNew||m_pConnect==XNULL)//||bNewPort) { if(m_pConnect!=XNULL&&m_pConnect!=&m_catch) delete m_pConnect; m_pConnect=XNULL; switch(nNew) { case XAPP_HTTP: //sjj #ifdef _USERSSL_ m_pConnect=new XConnectHttp(this, XFALSE); break; case XAPP_HTTPS: m_pConnect=new XConnectHttp(this, XTRUE); #else m_pConnect=new XConnectHttp(this); #endif break; case XAPP_FILE: m_pConnect=new XConnectFile(this); break; case XAPP_RES: m_pConnect=new XConnectRes(this); break; case XAPP_SOCKET: m_pConnect=new XConnectTCP(this); break; } } if(m_pConnect!=XNULL) m_pConnect->SetStatus(XPROC_BEGIN); m_hPosted.ResetEvent(); m_hCancel.ResetEvent(); m_hConnect.SetEvent(); return 1; }