void TimerWarnings::log() { if (!taskStats.empty() && nextReport < now()) { for (TaskStatsMap::iterator i = taskStats.begin(); i != taskStats.end(); ++i) { std::string task = i->first; TaskStats& stats = i->second; if (stats.lateDelay.count) QPID_LOG(info, task << " task late " << stats.lateDelay.count << " times by " << stats.lateDelay.average()/TIME_MSEC << "ms on average."); if (stats.overranOverrun.count) QPID_LOG(info, task << " task overran " << stats.overranOverrun.count << " times by " << stats.overranOverrun.average()/TIME_MSEC << "ms (taking " << stats.overranTime.average() << "ns) on average."); if (stats.lateAndOverranOverrun.count) QPID_LOG(info, task << " task late and overran " << stats.lateAndOverranOverrun.count << " times: late " << stats.lateAndOverranDelay.average()/TIME_MSEC << "ms, overran " << stats.lateAndOverranOverrun.average()/TIME_MSEC << "ms (taking " << stats.lateAndOverranTime.average() << "ns) on average."); } nextReport = AbsTime(now(), interval); taskStats.clear(); } }
/////////////////// // Setup the channel void CChannel::Create(const NetworkAddr& _adr, const SmartPointer<NetworkSocket>& _sock) { Clear(); RemoteAddr = _adr; fLastPckRecvd = tLX->currentTime; Socket = _sock; fLastSent = AbsTime(); fLastPingSent = fLastSent; iPing = 0; }
void Message::SharedStateImpl::computeExpiration() { //TODO: this is still quite 0-10 specific... uint64_t ttl; if (getTtl(ttl)) { // Use higher resolution time for the internal expiry calculation. // Prevent overflow as a signed int64_t Duration duration(std::min(ttl * TIME_MSEC, (uint64_t) std::numeric_limits<int64_t>::max())); expiration = AbsTime(sys::AbsTime::now(), duration); } }
void Message::computeExpiration(const boost::intrusive_ptr<ExpiryPolicy>& e) { //TODO: this is still quite 0-10 specific... uint64_t ttl; if (getEncoding().getTtl(ttl)) { if (e) { // Use higher resolution time for the internal expiry calculation. // Prevent overflow as a signed int64_t Duration duration(std::min(ttl * TIME_MSEC, (uint64_t) std::numeric_limits<int64_t>::max())); expiration = AbsTime(e->getCurrentTime(), duration); setExpiryPolicy(e); } } }
void CChannel_056b::Clear() { CChannel::Clear(); iOutgoingSequence = 0; iReliableSequence = 0; iLast_ReliableSequence = 0; iIncoming_ReliableSequence = 0; iIncomingSequence = 0; iIncomingAcknowledged = 0; iOutgoingBytes = 0; iIncomingBytes = 0; fLastSent = AbsTime(); bNewReliablePacket = false; iPongSequence = -1; Reliable.Clear(); }
void CChannel::Clear() { Socket = NULL; iPacketsDropped = 0; iPacketsGood = 0; cIncomingRate.clear(); cOutgoingRate.clear(); iOutgoingBytes = 0; iIncomingBytes = 0; iPing = 0; fLastSent = fLastPckRecvd = fLastPingSent = AbsTime(); iCurrentIncomingBytes = 0; iCurrentOutgoingBytes = 0; Messages.clear(); ReliableStreamBandwidthCounter = 0.0f; ReliableStreamLastSentTime = tLX->currentTime; ReliableStreamBandwidthCounterLastUpdate = tLX->currentTime; LimitReliableStreamBandwidth( -1.0f, 5.0f, 1024.0f ); }
void TestCChannelRobustness() { notes << "Testing CBytestream" << endl; CBytestream bsTest; bsTest.Test(); notes << "\n\n\n\nTesting CChannel robustness" << endl; int lagMin = 50; int lagMax = 400; int packetLoss = 15; // In percents float packetsPerSecond1 = 10.0f; // One channel sends faster than another float packetsPerSecond2 = 0.2f; int packetExtraData = 8192; // Extra data in bytes to add to packet to check buffer overflows CChannel3 c1, c2; //CChannel_056b c1, c2; SmartPointer<NetworkSocket> s1 = new NetworkSocket(); s1->OpenUnreliable(0); SmartPointer<NetworkSocket> s2 = new NetworkSocket(); s2->OpenUnreliable(0); SmartPointer<NetworkSocket> s1lag = new NetworkSocket(); s1lag->OpenUnreliable(0); SmartPointer<NetworkSocket> s2lag = new NetworkSocket(); s2lag->OpenUnreliable(0); NetworkAddr a1, a2, a1lag, a2lag; a1 = s1->localAddress(); a2 = s2->localAddress(); a1lag = s1lag->localAddress(); a2lag = s2lag->localAddress(); c1.Create( a1lag, s1 ); c2.Create( a2lag, s2 ); s1lag->setRemoteAddress( a2 ); s2lag->setRemoteAddress( a1 ); std::multimap< int, CBytestream > s1buf, s2buf; int i1=0, i2=0, i1r=0, i2r=0; float packetDelay1 = 10000000; if( packetsPerSecond1 > 0 ) packetDelay1 = 1000.0f / packetsPerSecond1; float packetDelay2 = 10000000; if( packetsPerSecond2 > 0 ) packetDelay2 = 1000.0f / packetsPerSecond2; float nextPacket1 = 0; float nextPacket2 = 0; for( int testtime=0; testtime < 100000; testtime+= 10, nextPacket1 += 10, nextPacket2 += 10 ) { tLX->currentTime = AbsTime(testtime); // Transmit number sequence and some unreliable info CBytestream b1, b2, b1u, b2u; if( nextPacket1 >= packetDelay1 ) { nextPacket1 = 0; i1++; b1.writeInt(i1, 4); for( int f=0; f<packetExtraData; f++ ) b1.writeByte(0xff); c1.AddReliablePacketToSend(b1); } if( nextPacket2 >= packetDelay2 ) { nextPacket2 = 0; i2++; b2.writeInt(i2, 4); for( int f=0; f<packetExtraData; f++ ) b2.writeByte(0xff); c2.AddReliablePacketToSend(b2); } c1.Transmit( &b1u ); c2.Transmit( &b2u ); b1.Clear(); b2.Clear(); b1.Read(s1lag.get()); b2.Read(s2lag.get()); b1.ResetPosToBegin(); b2.ResetPosToBegin(); // Add the lag if( b1.GetLength() != 0 ) { if( GetRandomInt(100) + 1 < packetLoss ) notes << testtime << ": c1 sent packet - lost (" << c1.Messages.size() << " in buf): " << printBinary(b1.readData()) << endl; else { int lag = ((testtime + lagMin + GetRandomInt(lagMax-lagMin)) / 10)*10; // Round to 10 s1buf.insert( std::make_pair( lag, b1 ) ); notes<< testtime << ": c1 sent packet - lag " << lag << " size " << b1.GetLength() << " (" << c1.Messages.size() << " in buf): " << printBinary(b1.readData()) << endl; } } for( std::multimap< int, CBytestream > :: iterator it = s1buf.lower_bound(testtime); it != s1buf.upper_bound(testtime); it++ ) { it->second.ResetPosToBegin(); it->second.ResetPosToBegin(); it->second.Send(s1lag.get()); } if( b2.GetLength() != 0 ) { if( GetRandomInt(100) + 1 < packetLoss ) notes << testtime << ": c2 sent packet - lost (" << c2.Messages.size() << " in buf): " << printBinary(b2.readData()) << endl; else { int lag = ((testtime + lagMin + GetRandomInt(lagMax-lagMin)) / 10)*10; // Round to 10 s2buf.insert( std::make_pair( lag, b2 ) ); notes << testtime << ": c2 sent packet - lag " << lag << " size " << b2.GetLength() << " (" << c2.Messages.size() << " in buf): " << printBinary(b2.readData()) << endl; } } for( std::multimap< int, CBytestream > :: iterator it = s2buf.lower_bound(testtime); it != s2buf.upper_bound(testtime); it++ ) { it->second.ResetPosToBegin(); it->second.ResetPosToBegin(); it->second.Send(s2lag.get()); } // Receive and check number sequence and unreliable info b1.Clear(); b2.Clear(); b1.Read(s1.get()); b2.Read(s2.get()); b1.ResetPosToBegin(); b2.ResetPosToBegin(); if( b1.GetLength() != 0 ) { notes << testtime << ": c1 recv packet (ping " << c1.getPing() << "): " << printBinary(b1.readData()) << endl; b1.ResetPosToBegin(); while( c1.Process( &b1 ) ) { while( b1.GetRestLen() != 0 ) { int i1rr = b1.readInt(4); notes << testtime << ": c1 reliable packet, data " << hex(i1rr) << " expected " << i1r+1 << " - " << (i1rr == i1r+1 ? "good" : "ERROR!") << endl; i1r = i1rr; for( int f=0; f<packetExtraData; f++ ) b1.readByte(); } b1.Clear(); } } if( b2.GetLength() != 0 ) { notes << testtime << ": c2 recv packet (ping " << c2.getPing() << "): " << printBinary(b2.readData()) << endl; b2.ResetPosToBegin(); while( c2.Process( &b2 ) ) { while( b2.GetRestLen() != 0 ) { int i2rr = b2.readInt(4); notes << testtime << ": c2 reliable packet, data " << hex(i2rr) << " expected " << i2r+1 << " - " << (i2rr == i2r+1 ? "good" : "ERROR!") << endl; i2r = i2rr; for( int f=0; f<packetExtraData; f++ ) b2.readByte(); } b2.Clear(); } } } }
/////////////////// // Show a server's details void Menu_Net_NETShowServer(const std::string& szAddress) { CGuiLayout cDetails; // Create the buffer DrawImage(tMenu->bmpBuffer.get(),tMenu->bmpMainBack_common,0,0); Menu_DrawBox(tMenu->bmpBuffer.get(), 15,130, 625, 465); Menu_DrawSubTitle(tMenu->bmpBuffer.get(),SUB_NETWORK); cInternet.Draw(tMenu->bmpBuffer.get()); //for(ushort i=1;i<4;i++) // cNetButtons[i].Draw(tMenu->bmpBuffer.get()); Menu_RedrawMouse(true); int center = VideoPostProcessor::videoSurface()->w/2; int y = VideoPostProcessor::videoSurface()->h/2 - INFO_H/2; cDetails.Initialize(); cDetails.Add( new CButton(BUT_REFRESH, tMenu->bmpButtons), nd_Refresh, center - 105, y+INFO_H-20, 85,15); cDetails.Add( new CButton(BUT_JOIN, tMenu->bmpButtons), nd_Join, center, y+INFO_H-20, 40,45); cDetails.Add( new CButton(BUT_OK, tMenu->bmpButtons), nd_Ok, center + 60, y+INFO_H-20, 40,15); ((CButton *)cDetails.getWidget(nd_Refresh))->setRedrawMenu(false); ((CButton *)cDetails.getWidget(nd_Ok))->setRedrawMenu(false); ((CButton *)cDetails.getWidget(nd_Join))->setRedrawMenu(false); bGotDetails = false; bOldLxBug = false; nTries = 0; fStart = AbsTime(); while(!WasKeyboardEventHappening(SDLK_ESCAPE,false) && tMenu->bMenuRunning) { tLX->currentTime = GetTime(); Menu_RedrawMouse(true); ProcessEvents(); //DrawImageAdv(VideoPostProcessor::videoSurface(),tMenu->bmpBuffer, 200,220, 200,220, 240, 240); Menu_SvrList_DrawInfo(szAddress, INFO_W, INFO_H); cDetails.Draw(VideoPostProcessor::videoSurface()); gui_event_t *ev = NULL; ev = cDetails.Process(); if(ev) { // Ok if(ev->iControlID == nd_Ok && ev->iEventMsg == BTN_CLICKED) { break; // Refresh } else if (ev->iControlID == nd_Refresh && ev->iEventMsg == BTN_CLICKED) { fStart = AbsTime(); bGotDetails = false; bOldLxBug = false; nTries = 0; } else if (ev->iControlID == nd_Join && ev->iEventMsg == BTN_CLICKED) { // Save the list SvrList_Save(); lv_subitem_t *sub = ((CListview *)cInternet.getWidget(mi_ServerList))->getCurSubitem(1); // Join if (sub) Menu_Net_NETJoinServer(szAddress, sub->sText); break; } } DrawCursor(VideoPostProcessor::videoSurface()); doVideoFrameInMainThread(); CapFPS(); } cDetails.Shutdown(); // Redraw the background DrawImage(tMenu->bmpBuffer.get(),tMenu->bmpMainBack_common,0,0); if (tMenu->tFrontendInfo.bPageBoxes) Menu_DrawBox(tMenu->bmpBuffer.get(), 15,130, 625, 465); Menu_DrawSubTitle(tMenu->bmpBuffer.get(),SUB_NETWORK); Menu_RedrawMouse(true); }
/////////////////// // Mouse up event int CListview::DoMouseUp(int x, int y, int dx, int dy, MouseButton button, const ModifiersState& modstate) { if(cScrollbar->isMouseDown() && cScrollbar->getVisible()) { cScrollbar->DoMouseUp(x - cScrollbar->getX(), y - cScrollbar->getY(), dx, dy, button, modstate); CContainerWidget::DoMouseUp(x, y, dx, dy, button, modstate); return WID_PROCESSED; } else { fLastMouseUp = AbsTime(); } // Column headers if (bShowColumnHeaders) { if( y >= cBorder.getTopW() && y < tItemArea.y && tLX->currentTime-fLastMouseUp >= 0.15f && iGrabbed <= 0) { fLastMouseUp = tLX->currentTime; iGrabbed = -1; int cur_x = cBorder.getLeftW(); std::vector<CListviewColumn *>::iterator col = tColumns.begin(); for (int i = 0; col != tColumns.end(); col++, i++) { (*col)->setMouseDown(false); // Mouse up over the column if (x >= cur_x && x < cur_x + (*col)->getWidth()) { bool asc = ((*col)->getSortDirection() != sort_Ascending); (*col)->setSortDirection(asc ? sort_Ascending : sort_Descending); SortBy(i, asc); } else (*col)->setSortDirection(sort_None); cur_x += (*col)->getWidth(); } CWidget::DoMouseUp(x, y, dx, dy, button, modstate); return WID_PROCESSED; } iGrabbed = 0; } setSelectedSub(NULL, -1); // // Process the items // // Send the event to the focused widget if (tFocusedSubWidget) { tFocusedSubWidget->DoMouseUp(x, y, dx, dy, button, modstate); } int count = 0; int cur_y = tItemArea.y; std::list<CListviewItem *>::iterator item = tItems.begin(); for(; item != tItems.end(); item++) { if (!(*item)->isVisible()) continue; if(count++ < cScrollbar->getValue()) continue; // Find the max height int h = (*item)->getHeight(); if(y > cur_y && y < cur_y + h) { bool doubleclick = false; if(tSelected && button == /*MBT_LEFT*/0) { if(tSelected == (*item)) { if(tLX->currentTime - fLastMouseUp < 0.5f) { doubleclick = true; fLastMouseUp = AbsTime(); CALL_EVENT(OnDoubleClick, (this, tSelected, count - 1)); } } } // Go through the sub items, check which one was clicked on std::list<CListviewSubitem *>::iterator sub = (*item)->getSubitems().begin(); std::vector<CListviewColumn *>::iterator col = tColumns.begin(); int cur_x = tItemArea.x; int i=0; for(; sub != (*item)->getSubitems().end() && col != tColumns.end(); col++, sub++,i++) { if((*sub)->isVisible()) if(x >= cur_x && x < cur_x + (*col)->getWidth()) setSelectedSub(*sub, i); // HINT: mouseup can receive only focused widget => no need to test events here cur_x += (*col)->getWidth(); } setSelected(item, count - 1); if(!doubleclick) fLastMouseUp = tLX->currentTime; return WID_PROCESSED; } // Check that we don't overflow cur_y += (*item)->getHeight(); if(cur_y >= tItemArea.y + tItemArea.h) break; } CContainerWidget::DoMouseUp(x, y, dx, dy, button, modstate); return WID_PROCESSED; }