Пример #1
0
bool CLoggingManager::saveToTankFile(IEspUpdateLogRequestWrap& logRequest, CLogRequestInFile* reqInFile)
{
    if (!logFailSafe.get())
    {
        ERRLOG("CLoggingManager::saveToTankFile: logFailSafe not configured.");
        return false;
    }

    unsigned startTime = (getEspLogLevel()>=LogNormal) ? msTick() : 0;

    StringBuffer GUID;
    logFailSafe->GenerateGUID(GUID, NULL);
    reqInFile->setGUID(GUID);
    reqInFile->setOption(logRequest.getOption());

    StringBuffer reqBuf;
    Owned<IEspUpdateLogRequestWrap> logRequestFiltered = logContentFilter.filterLogContent(&logRequest);
    if (!serializeLogRequestContent(logRequestFiltered, GUID, reqBuf))
    {
        ERRLOG("CLoggingManager::saveToTankFile: failed in serializeLogRequestContent().");
        return false;
    }

    logFailSafe->AddACK(GUID);//Ack this logging request since the task will be done as soon as the next line is called.
    logFailSafe->Add(GUID, reqBuf, reqInFile);

    ESPLOG(LogNormal, "LThread:saveToTankFile: %dms\n", msTick() - startTime);
    return true;
}
Пример #2
0
 void testTimedElapsed(Semaphore & sem, unsigned time)
 {
     unsigned now = msTick();
     sem.wait(time);
     unsigned taken = msTick() - now;
     ASSERT(taken >= time && taken < 2*time);
 }
Пример #3
0
    void testTimedElapsed(Semaphore & sem, unsigned time, unsigned loopCount)
    {
        unsigned __int64 sumTaken = 0;
        unsigned maxTaken = 0;
        unsigned timeLimit = 2 * time;
        unsigned numberOfOut = 0;
        bool isSignaled = false;

        PROGLOG("Start loop");
        for (int i = 0 ; i <= loopCount; i++)
        {
            unsigned now = msTick();
            if (sem.wait(time))
            {
                isSignaled = true;
                break;
            }
            unsigned taken = msTick() - now;
            sumTaken += taken;
            maxTaken = (taken > maxTaken ? taken : maxTaken);
            numberOfOut += (taken > timeLimit ? 1 : 0);
        }

        VStringBuffer errMsg("values: time: %d, loop: %d, sum taken: %llu, average taken: %llu, max taken: %d, out of limit: %d times, signaled: %s",
                                time, loopCount, sumTaken, sumTaken/loopCount, maxTaken, numberOfOut, (isSignaled ? "yes" : "no"));
        CPPUNIT_ASSERT_MESSAGE(errMsg.str(), 0 == numberOfOut && !isSignaled );
        PROGLOG("%s", errMsg.str());
    }
Пример #4
0
 void testTimedAvailable(Semaphore & sem)
 {
     unsigned now = msTick();
     sem.wait(100);
     unsigned taken = msTick() - now;
     //Shouldn't cause a reschedule, definitely shouldn't wait for 100s
     ASSERT(taken < 5);
 }
Пример #5
0
    int getPermissions(const char *key,const char *obj,IUserDescriptor *udesc,unsigned auditflags)
    {
        if (!ldapsecurity||((getLDAPflags()&DLF_ENABLED)==0)) 
            return 255;
        bool filescope = stricmp(key,"Scope")==0;
        bool wuscope = stricmp(key,"workunit")==0;
        if (filescope||wuscope) {
            StringBuffer username;
            StringBuffer password;
            int perm = 0;
            if (udesc) {
                udesc->getUserName(username);
                udesc->getPassword(password);
            }
            if (username.length()==0)  {
#ifndef _NO_DALIUSER_STACKTRACE
                DBGLOG("UNEXPECTED USER (NULL) in daldap.cpp getPermissions() line %d", __LINE__);
                //following debug code to be removed
                PrintStackReport();
#endif
                username.append(filesdefaultuser);
                decrypt(password, filesdefaultpassword);
            }
            unsigned start = msTick();
            Owned<ISecUser> user = ldapsecurity->createUser(username);
            if (user) {
                user->credentials().setPassword(password);
                if (filescope)
                    perm=ldapsecurity->authorizeFileScope(*user, obj);
                else if (wuscope)
                    perm=ldapsecurity->authorizeWorkunitScope(*user, obj);
                if (perm==-1)
                    perm = 0;
            }
            unsigned taken = msTick()-start;
#ifndef _DEBUG
            if (taken>100) 
#endif
            {
                PROGLOG("LDAP: getPermissions(%s) scope=%s user=%s returns %d in %d ms",key?key:"NULL",obj?obj:"NULL",username.str(),perm,taken);
            }
            if (auditflags&DALI_LDAP_AUDIT_REPORT) {
                StringBuffer auditstr;
                if ((auditflags&DALI_LDAP_READ_WANTED)&&!HASREADPERMISSION(perm)) 
                    auditstr.append("Lookup Access Denied");
                else if ((auditflags&DALI_LDAP_WRITE_WANTED)&&!HASWRITEPERMISSION(perm)) 
                    auditstr.append("Create Access Denied");
                if (auditstr.length()) {
                    auditstr.append(":\n\tProcess:\tdaserver");
                    auditstr.appendf("\n\tUser:\t%s",username.str());
                    auditstr.appendf("\n\tScope:\t%s\n",obj?obj:"");
                    SYSLOG(AUDIT_TYPE_ACCESS_FAILURE,auditstr.str());
                }
            }
            return perm;
        }
        return 255;
    }
Пример #6
0
 void testTimedElapsed(Semaphore & sem, unsigned time)
 {
     unsigned now = msTick();
     sem.wait(time);
     unsigned taken = msTick() - now;
     VStringBuffer errMsg("values: time: %u, taken: %u", time, taken);
     CPPUNIT_ASSERT_MESSAGE(errMsg.str(), taken >= time && taken < 2*time);
     PROGLOG("%s", errMsg.str());
 }
Пример #7
0
void TransferServer::appendTransformed(unsigned chunkIndex, ITransformer * input)
{
    OutputProgress & curProgress = progress.item(chunkIndex);
    PartitionPoint & curPartition = partition.item(chunkIndex);
    input->beginTransform(out);

    const offset_t startInputOffset = curPartition.inputOffset;
    const offset_t startOutputOffset = curPartition.outputOffset;

    loop
    {
        unsigned gotLength = input->getBlock(out);
        totalLengthRead  += gotLength;

        if (gpfFrequency || !gotLength || ((unsigned)(msTick() - lastTick)) > updateFrequency)
        {
            out->flush();

            lastTick = msTick();

            offset_t outputOffset = out->tell();
            offset_t inputOffset = input->tell();
            if (totalLengthToRead)
                LOG(MCdebugProgress, unknownJob, "Progress: %d%% done. [%" I64F "u]", (unsigned)(totalLengthRead*100/totalLengthToRead), (unsigned __int64)totalLengthRead);

            curProgress.status = (gotLength == 0) ? OutputProgress::StatusCopied : OutputProgress::StatusActive;
            curProgress.inputLength = input->tell()-startInputOffset;
            curProgress.outputLength = out->tell()-startOutputOffset;
            if (crcOut)
                curProgress.outputCRC = crcOut->getCRC();
            if (calcInputCRC)
                curProgress.hasInputCRC = input->getInputCRC(curProgress.inputCRC);
            sendProgress(curProgress);
        }

        if (!gotLength)
            break;

        if (blockDelay)
            MilliSleep(blockDelay);
        else if (throttleNicSpeed)
        {
            unsigned delay = (unsigned)(((unsigned __int64)gotLength*10*1000*(numParallelSlaves-1))/(throttleNicSpeed * I64C(0x100000)));
            if (delay)
                MilliSleep(delay*(getRandom()%100)/50);
        }
#ifdef _WIN32
        if (gpfFrequency && ((rand() % gpfFrequency) == 0))
        {
            LOG(MCdebugInfo, unknownJob, "About to crash....");
            *(char *)0 = 0;
        }
#endif
    }

    input->endTransform(out);
}
Пример #8
0
 ~Scope()
 {
     if (mTimer)
     {
         mTimer->decNesting(msTick() - mStart);
     }
 }
Пример #9
0
 CEspContext() : m_servPort(0), m_bindingValue(0), m_serviceValue(0), m_toBeAuthenticated(false), options(0), m_clientVer(-1)
 {
     m_hasException =  false;
     m_creationTime = msTick();
     m_active=ActiveRequests::getCount();
     respSerializationFormat=ESPSerializationANY;
 }
    void reportStatus(IWorkUnit *wu, CGraphBase &graph, unsigned startTime, bool finished, bool success=true)
    {
        const char *graphname = graph.queryJob().queryGraphName();
        StringBuffer timer, graphScope;
        formatGraphTimerLabel(timer, graphname, 0, graph.queryGraphId());
        formatGraphTimerScope(graphScope, graphname, 0, graph.queryGraphId());
        unsigned duration = msTick()-startTime;
        updateWorkunitTimeStat(wu, SSTsubgraph, graphScope, StTimeElapsed, timer, milliToNano(duration));

        if (finished)
        {
            if (memcmp(graphname,"graph",5)==0)
                graphname+=5;
            LOG(daliAuditLogCat,",Timing,ThorGraph,%s,%s,%s,%u,1,%d,%s,%s,%s",
                queryServerStatus().queryProperties()->queryProp("@thorname"),
                wu->queryWuid(),
                graphname,
                (unsigned)graph.queryGraphId(),
                duration,
                success?"SUCCESS":"FAILED",
                queryServerStatus().queryProperties()->queryProp("@nodeGroup"),
                queryServerStatus().queryProperties()->queryProp("@queue"));
            queryServerStatus().queryProperties()->removeProp("@graph");
            queryServerStatus().queryProperties()->removeProp("@subgraph");
            queryServerStatus().queryProperties()->removeProp("@sg_duration");
        }
        else
        {
            queryServerStatus().queryProperties()->setProp("@graph", graph.queryJob().queryGraphName());
            queryServerStatus().queryProperties()->setPropInt("@subgraph", (int)graph.queryGraphId());
            queryServerStatus().queryProperties()->setPropInt("@sg_duration", (duration+59999)/60000); // round it up
        }
    }
Пример #11
0
 Scope(CumulativeTimer* t)
     : mTimer(t), mStart(0)
 {
     if (mTimer)
         mTimer->incNesting();
     mStart = msTick();
 }
Пример #12
0
    virtual int run()
    {
        unsigned start=0;
        try {
            MemoryBuffer mb;
            bool first = true;
            loop
            {
                size32_t sz = sock->receive_block_size();
                if (sz==0)
                    break;
                {
                    //CriticalBlock block(recvsect);        // TEST
                    unsigned start=msTick();
                    if (!sock->receive_block(mb.clear().reserve(sz),sz)) {
                        StringBuffer err("Timeout receiving from ");
                        err.append(src);
                        ninfo->sendError(err.str());
                        break;
                    }
                }
#ifdef TRACE
                DBGLOG("received %d from %d",sz,src+1);
#endif
                unsigned seq;
                mb.read(seq);
                if (seq!=ninfo->recvseq[src]++) {
                    StringBuffer msg;
                    msg.append("Block out of sequence from ").append(src+1).append(", got ").append(seq).append(" expected ").append(ninfo->recvseq[src]-1);
                    ninfo->sendError(msg.str());
                    break; // errors fatal otherwise overload q
                }
                ninfo->recvtime[src] += (msTick()-start);
                ninfo->recvbytes[src] += sz;
            }
        }
        catch (IException *e) {
            StringBuffer err;
            e->errorMessage(err);
            ninfo->sendError("Receive exception",err.str());
        }
#ifdef TRACE
        DBGLOG("receive exit from %d",src+1);
#endif
        return 1;
    };
Пример #13
0
 UserInfo(ISecUser& userInfo, unsigned TimeoutPeriod=60000)
 {
     _UserInfo = &userInfo;
     if(_UserInfo)
         _UserInfo->Link();
     _timeCreated = msTick();
     _timeOut = TimeoutPeriod; 
 }
Пример #14
0
 virtual void addTraceSummaryTimeStamp(const char *name)
 {
     if (name && *name)
     {
         unsigned timeval=msTick()-m_creationTime;
         StringBuffer value;
         value.append(name).append('=').appendulong(timeval).append("ms");
         m_traceValues.append(value.str());
     }
 }
Пример #15
0
TransferServer::TransferServer(ISocket * _masterSocket)
{
    masterSocket = _masterSocket;
    lastTick = msTick();
    updateFrequency = (unsigned int) -1;
    throttleNicSpeed = 0;
    compressedInput = false;
    compressOutput = false;
    transferBufferSize = DEFAULT_STD_BUFFER_SIZE;
}
Пример #16
0
bool NamedMutex::lockWait(unsigned timeout)
{
    unsigned t = msTick();
    // first lock locally
    if (!threadmutex.lockWait(timeout))
        return false;
    // then lock globally
    loop {
        if (lock_file(mutexfname))
            return true;
        unsigned elapsed = msTick()-t;
        if (elapsed>=timeout) {
            threadmutex.unlock();
            break;
        }
        Sleep((timeout-elapsed)>POLLTIME?POLLTIME:(timeout-elapsed));
    }
    return false;

}
Пример #17
0
static void printStats(offset_t filesize,unsigned start,unsigned startu)
{
    StringBuffer tmp;
    unsigned elapsed = msTick()-start;
    unsigned elapsedu = usTick()-startu;
    if (!elapsedu)
        elapsedu = 1;
    if (elapsed<1000)
        printf("%"I64F"d bytes copied, at %.2f MB/s in %s\n",filesize,((((double)filesize)/(1024*1024))/elapsedu)*1000000,formatTimeU(elapsedu,tmp));
    else
        printf("%"I64F"d bytes copied, at %.2f MB/s in %s\n",filesize,((((double)filesize)/(1024*1024))/elapsed)*1000,formatTime(elapsed*1000,tmp));
}
Пример #18
0
 void testSet(bool initial)
 {
     unsigned now = msTick();
     bool setValue = !initial;
     bool clearValue = initial;
     const unsigned numBits = 400;
     const unsigned passes = 10000;
     for (unsigned pass=0; pass < passes; pass++)
     {
         Owned<IBitSet> bs = createThreadSafeBitSet();
         testSet1(initial, bs, 0, numBits, setValue, clearValue);
     }
     unsigned elapsed = msTick()-now;
     fprintf(stdout, "Bit test (%u) time taken = %dms\n", initial, elapsed);
     now = msTick();
     for (unsigned pass=0; pass < passes; pass++)
     {
         Owned<IBitSet> bs = createBitSet();
         testSet1(initial, bs, 0, numBits, setValue, clearValue);
     }
     elapsed = msTick()-now;
     fprintf(stdout, "Bit test [thread-unsafe version] (%u) time taken = %dms\n", initial, elapsed);
     now = msTick();
     size32_t bitSetMemSz = getBitSetMemoryRequirement(numBits+5);
     MemoryBuffer mb;
     void *mem = mb.reserveTruncate(bitSetMemSz);
     for (unsigned pass=0; pass < passes; pass++)
     {
         Owned<IBitSet> bs = createBitSet(bitSetMemSz, mem);
         testSet1(initial, bs, 0, numBits, setValue, clearValue);
     }
     elapsed = msTick()-now;
     fprintf(stdout, "Bit test [thread-unsafe version, fixed memory] (%u) time taken = %dms\n", initial, elapsed);
 }
Пример #19
0
    Linked<T> get(long timeout=0)
    {   
        const long interval=1000;

        for(;;)
        {
            {
                CriticalBlock b(crit); 
                typename std::vector<Linked<T> >::iterator it;
                for(it=resources.begin();it!=resources.end();it++)
                {
                    if(it->get() == NULL)
                    {
                        Owned<T> e = factory->createResource();
                        if(e)
                        {
                            it->set(e.get());
                            return e;
                        }
                    }
                    else if(!it->get()->IsShared())
                    {
                        return *it;
                    }
                }
            }

            long slp=timeout!=INFINITE && timeout<interval ? timeout : interval;
            if(slp<=0)
                break;

            long start=msTick();
            long elapsed=sem.wait(slp) ? (msTick()-start) : slp;

            if(timeout!=INFINITE)
                timeout-=elapsed;
        }

        throw MakeStringException(1, "Run out of resources");
    }
bool CLoggingManager::updateLog(IEspContext* espContext, const char* option, IPropertyTree* userContext, IPropertyTree* userRequest,
    const char* backEndReq, const char* backEndResp, const char* userResp, const char* logDatasets, StringBuffer& status)
{
    if (!initialized)
        throw MakeStringException(-1,"LoggingManager not initialized");

    bool bRet = false;
    try
    {
        Owned<IPropertyTree> espContextTree;
        if (espContext)
        {
            espContextTree.setown(createPTree("ESPContext"));

            short port;
            StringBuffer sourceIP, peerStr;
            const char* esdlBindingID = espContext->queryESDLBindingID();
            espContext->getServAddress(sourceIP, port);
            espContextTree->addProp("SourceIP", sourceIP.str());
            espContext->getPeer(peerStr);
            espContextTree->addProp("Peer", peerStr.str());
            if (!isEmptyString(esdlBindingID))
                espContextTree->addProp("ESDLBindingID", esdlBindingID);
            //More information in espContext may be added to the espContextTree later.

            const char* userId = espContext->queryUserId();
            if (userId && *userId)
                espContextTree->addProp("UserName", userId);

            espContextTree->addProp("ResponseTime", VStringBuffer("%.4f", (msTick()-espContext->queryCreationTime())/1000.0));
        }
        Owned<IEspUpdateLogRequestWrap> req =  new CUpdateLogRequestWrap(nullptr, option, espContextTree.getClear(), LINK(userContext), LINK(userRequest),
            backEndReq, backEndResp, userResp, logDatasets);
        Owned<IEspUpdateLogResponse> resp =  createUpdateLogResponse();
        bRet = updateLog(espContext, *req, *resp, status);
    }
    catch (IException* e)
    {
        status.set("Failed to update log: ");
        e->errorMessage(status);
        ERRLOG("%s", status.str());
        e->Release();
    }
    return bRet;
}
Пример #21
0
 CEspContext(IEspSecureContext* secureContext)
 : m_servPort(0)
 , m_bindingValue(0)
 , m_serviceValue(0)
 , m_toBeAuthenticated(false)
 , m_clientVer(-1)
 , options(0)
 , m_active(ActiveRequests::getCount())
 , m_creationTime(msTick())
 , m_processingTime(0)
 , m_exceptionTime(0)
 , m_hasException(false)
 , m_exceptionCode(0)
 , respSerializationFormat(ESPSerializationANY)
 {
     m_txSummary.setown(new CTxSummary(m_creationTime));
     updateTraceSummaryHeader();
     m_secureContext.setown(secureContext);
     m_SecurityHandler.setSecureContext(secureContext);
 }
Пример #22
0
//______________________________________________________________________________
//
// this delegates handling the internal clock to msTick() from timing.c
//______________________________________________________________________________
//
void app_timer_event()
{
    msTick();
    /*
    // example - send MIDI clock at 125bpm
    #define TICK_MS 20

    static u8 ms = TICK_MS;
    static u8 mt = 0;
    if (++ms >= TICK_MS)
    {

      //hal_plot_led(TYPESETUP, 0, mt/2, 0, 0);
      ms = 0;
      mt++;
      if(mt >= 96)
        mt = 0;
    	// send a clock pulse up the USB
    	hal_send_midi(USBSTANDALONE, MIDITIMINGCLOCK, 0, 0);
    }
    */
}
Пример #23
0
 virtual void setProcessingTime()
 {
     m_processingTime = msTick() - m_creationTime;
 }
Пример #24
0
 virtual bool IsValid()
 {
     return (msTick() > (_timeOut + _timeCreated)) ? false : true;
 }
Пример #25
0
    void print(const char *str)
    {
        if (nl) {
            char timeStamp[32];
            time_t tNow;
            time(&tNow);
#ifdef _WIN32
            unsigned tpid = GetCurrentThreadId();
#else
            unsigned tpid = getpid();
#endif
#ifdef _WIN32
            struct tm ltNow = *localtime(&tNow);
#else
            struct tm ltNow;
            localtime_r(&tNow, &ltNow);
#endif
#ifdef MINIMALTRACE
            if (((detail & _LOG_TID) && tpid!=lasttpid)||((detail & _LOG_TIME) && memcmp(&tNow,&lastt,sizeof(tNow))!=0))
            {
                lasttpid = tpid;
                lastt = tNow;
                FPRINTF("[");
                if (detail & _LOG_TIME)
                {
                    strftime(timeStamp, 32, "%H:%M:%S ", &ltNow);
                    FPRINTF(timeStamp);
                }
                if (detail & _LOG_TID)
                {
                    fprintf(stdlog, "TID=%d ", tpid);
                    if (logFile)
                        fprintf(logFile, "TID=%d ", tpid);
                }
                FPRINTF("]\n");
            }
#else
            if (detail & _LOG_TIME)
            {
                strftime(timeStamp, 32, "%m/%d/%y %H:%M:%S ", &ltNow);
                FPRINTF(timeStamp);
            }
            if (detail & _LOG_CLOCK)
            {
                unsigned t=msTick();
                fprintf(stdlog, "%u ", t);
                if (logFile)
                    fprintf(logFile, "%u ", t);
            }
            if (detail & _LOG_HIRESCLOCK)
            {
                unsigned clock = usTick();
                fprintf(stdlog, " TICK=%u ", clock);
                if (logFile)
                    fprintf(logFile, " TICK=%u ", clock);
            }
#if defined(_WIN32) 
            if (detail & _LOG_TID)
            {
                fprintf(stdlog, "TID=%d ", GetCurrentThreadId());
                if (logFile)
                    fprintf(logFile, "TID=%d ", GetCurrentThreadId());
            }
            if (detail & _LOG_PID)
            {
                fprintf(stdlog, "PID=%d ", GetCurrentProcessId());
                if (logFile)
                    fprintf(logFile, "PID=%d ", GetCurrentProcessId());
            }
#else
            if (detail & _LOG_PID)
            {
                fprintf(stdlog, "PID=%d ", getpid());
                if (logFile)
                    fprintf(logFile, "PID=%d ", getpid());
            }
#endif
            if (detail & (_LOG_PID|_LOG_TID|_LOG_TIME))
            {
                fprintf(stdlog, "- ");
                if (logFile)
                    fprintf(logFile, "- ");
            }
#endif
        }
        if (str && *str)
        {
            nl = str[strlen(str)-1]=='\n';
            FPRINTF(str);
        }
        else
            nl = false;
        fflush(stdlog);
        if (logFile)
        {
            fflush(logFile);
        }
    }
Пример #26
0
 inline bool checkTimeout(unsigned timeout) const { return msTick()-timeCached >= timeout; }
Пример #27
0
 CThorNodeGroup(const char* _groupName, unsigned _nodeCount, bool _replicateOutputs)
     : groupName(_groupName), nodeCount(_nodeCount), replicateOutputs(_replicateOutputs)
 {
     keyhash = hashnc((const byte *)groupName.get(),groupName.length(),0);
     timeCached = msTick();
 }
Пример #28
0
int HttpClient::sendRequest(int times, HttpStat& stat, StringBuffer& req)
{
    StringBuffer request;
    if(req.length() <= 2)
    {
        throw MakeStringException(-1, "request too short");
    }

    bool endofheaders = false;
    char c0 = req.charAt(0);
    char c1 = req.charAt(1);
    if(c0 == '\n')
        request.append("\r\n");
    else
        request.append(c0);

    if(c1 == '\n')
    {
        if(c0 == '\r')
            request.append(c1);
        else
        {
            request.append("\r\n");
            if(c0 == '\n')
                endofheaders = true;
        }
    }
    else
        request.append(c1);

    unsigned seq = 2;
    while(seq < req.length() && !endofheaders)
    {
        char c = req.charAt(seq);
        if(c == '\n')
        {
            char c1 = req.charAt(seq - 1);
            char c2 = req.charAt(seq - 2);
            if(c1 == '\n' || (c1 == '\r' && c2 == '\n'))
                endofheaders = true;

            if(c1 != '\r')
                request.append("\r\n");
            else
                request.append(c);
        }
        else
            request.append(c);
        seq++;
    }

    if(seq < req.length())
        request.append(req.length() - seq, req.str() + seq);

    if(httptest_tracelevel > 5)
        fprintf(m_ofile, ">>sending out request to %s:%d for %d times\n", m_host.str(), m_port, times);

    unsigned start = msTick();
    int slowest = 0;
    int fastest = 2147483647;
    for(int i = 0; i < times; i++)
    {
        SocketEndpoint ep;
        ep.set(m_host.str(), m_port);
        Owned<ISocket> socket;
        try
        {
            socket.setown(ISocket::connect(ep));
            if(m_use_ssl && m_ssctx.get() != NULL)
            {
                Owned<ISecureSocket> securesocket = m_ssctx->createSecureSocket(socket.getLink());
                int res = securesocket->secure_connect();
                if(res >= 0)
                {
                    socket.set(securesocket.get());
                }
            }
        }
        catch(IException *excpt)
        {
            StringBuffer errMsg;
            DBGLOG("Error connecting to %s:%d - %d:%s", m_host.str(), m_port, excpt->errorCode(), excpt->errorMessage(errMsg).str());
            continue;
        }
        catch(...)
        {
            DBGLOG("can't connect to %s:%d", m_host.str(), m_port);
            continue;
        }

        if(socket.get() == NULL)
        {
            StringBuffer urlstr;
            DBGLOG(">>Can't connect to %s", ep.getUrlStr(urlstr).str());
            continue;
        }

        if(m_delay > 0)
            sleep(m_delay);

        if(httptest_tracelevel > 5)
            fprintf(m_ofile, ">>sending out request:\n");
        if(httptest_tracelevel > 10)
            fprintf(m_ofile, "%s%s%s\n", sepstr, request.str(), sepstr);

        unsigned start1 = msTick();

        socket->write(request.str(), request.length());

        if(httptest_tracelevel > 5)
            fprintf(m_ofile, ">>receiving response:\n");

        StringBuffer buf;
        Owned<IByteOutputStream> ostream = createOutputStream(buf);
        stat.totalresplen += receiveData(socket.get(), ostream.get(), true);
        if(httptest_tracelevel > 10)
            fprintf(m_ofile, "%s%s%s\n", sepstr, buf.str(), sepstr);

        char tmpbuf[256];
        unsigned int sizeread;
        do
        {
            socket->read(tmpbuf, 0, 256, sizeread);
        }
        while(sizeread > 0);

        socket->shutdown();
        socket->close();
        fflush(m_ofile);
        unsigned end1 = msTick();
        int duration = end1 - start1;
        if(duration <= fastest)
            fastest = duration;
        if(duration > slowest)
            slowest = duration;

        if(i % 100 == 0)
            fprintf(stderr, "sent out %d\n", i);
    }

    unsigned end = msTick();
    stat.msecs = end - start;
    stat.numrequests = times;
    stat.totalreqlen = times * request.length();
    stat.slowest = slowest;
    stat.fastest = fastest;

    return 0;
}
Пример #29
0
void TransferServer::deserializeAction(MemoryBuffer & msg, unsigned action)
{
    SocketEndpoint ep;
    ep.deserialize(msg);
    if (!ep.isLocal())
    {
        StringBuffer host, expected;
        queryHostIP().getIpText(host);
        ep.getIpText(expected);
        throwError2(DFTERR_WrongComputer, expected.str(), host.str());
    }

    srcFormat.deserialize(msg);
    tgtFormat.deserialize(msg);
    msg.read(calcInputCRC);
    msg.read(calcOutputCRC);
    deserialize(partition, msg);
    msg.read(numParallelSlaves);
    msg.read(updateFrequency);
    msg.read(replicate);
    msg.read(mirror);
    msg.read(isSafeMode);

    srand((unsigned)get_cycles_now());
    int adjust = (rand() * rand() * rand()) % updateFrequency - (updateFrequency/2);
    lastTick = msTick() + adjust;

    StringBuffer localFilename;
    if (action == FTactionpull)
    {
        partition.item(0).outputName.getPath(localFilename);
        LOG(MCdebugProgress, unknownJob, "Process Pull Command: %s", localFilename.str());
    }
    else
    {
        partition.item(0).inputName.getPath(localFilename);
        LOG(MCdebugProgress, unknownJob, "Process Push Command: %s", localFilename.str());
    }
    LOG(MCdebugProgress, unknownJob, "Num Parallel Slaves=%d Adjust=%d/%d", numParallelSlaves, adjust, updateFrequency);
    LOG(MCdebugProgress, unknownJob, "replicate(%d) mirror(%d) safe(%d) incrc(%d) outcrc(%d)", replicate, mirror, isSafeMode, calcInputCRC, calcOutputCRC);

    displayPartition(partition);

    unsigned numProgress;
    msg.read(numProgress);
    for (unsigned i = 0; i < numProgress; i++)
    {
        OutputProgress & next = *new OutputProgress;
        next.deserializeCore(msg);
        progress.append(next);
    }
    if (msg.remaining())
        msg.read(throttleNicSpeed);
    if (msg.remaining())
        msg.read(compressedInput).read(compressOutput);
    if (msg.remaining())
        msg.read(copyCompressed);
    if (msg.remaining())
        msg.read(transferBufferSize);
    if (msg.remaining()) 
        msg.read(encryptKey).read(decryptKey);
    if (msg.remaining())
    {
        srcFormat.deserializeExtra(msg, 1);
        tgtFormat.deserializeExtra(msg, 1);
    }

    ForEachItemIn(i1, progress)
        progress.item(i1).deserializeExtra(msg, 1);

    LOG(MCdebugProgress, unknownJob, "throttle(%d), transferBufferSize(%d)", throttleNicSpeed, transferBufferSize);
    PROGLOG("compressedInput(%d), compressedOutput(%d), copyCompressed(%d)", compressedInput?1:0, compressOutput?1:0, copyCompressed?1:0);
    PROGLOG("encrypt(%d), decrypt(%d)", encryptKey.isEmpty()?0:1, decryptKey.isEmpty()?0:1);

    //---Finished deserializing ---
    displayProgress(progress);

    totalLengthRead = 0;
    totalLengthToRead = 0;
    ForEachItemIn(idx, partition)
        totalLengthToRead += partition.item(idx).inputLength;
}
Пример #30
0
 virtual void setException(int exceptionCode)
 {
     m_hasException = true;
     m_exceptionCode = exceptionCode;
     m_exceptionTime = msTick() - m_creationTime;
 }