MCPcopy Create free account
hub / github.com/LUX-Core/lux / DoFlush

Method DoFlush

src/cryptopp/network.cpp:478–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478lword NetworkSink::DoFlush(unsigned long maxTime, size_t targetSize)
479{
480 NetworkSender &sender = AccessSender();
481
482 bool forever = maxTime == INFINITE_TIME;
483 Timer timer(Timer::MILLISECONDS, forever);
484 unsigned int totalFlushSize = 0;
485
486 while (true)
487 {
488 if (m_buffer.CurrentSize() <= targetSize)
489 break;
490
491 if (m_needSendResult)
492 {
493 if (sender.MustWaitForResult() &&
494 !sender.Wait(SaturatingSubtract(maxTime, timer.ElapsedTime()),
495 CallStack("NetworkSink::DoFlush() - wait send result", 0)))
496 break;
497
498 unsigned int sendResult = sender.GetSendResult();
499#if CRYPTOPP_TRACE_NETWORK
500 OutputDebugString((IntToString((unsigned int)this) + ": Sent " + IntToString(sendResult) + " bytes\n").c_str());
501#endif
502 m_buffer.Skip(sendResult);
503 totalFlushSize += sendResult;
504 m_needSendResult = false;
505
506 if (!m_buffer.AnyRetrievable())
507 break;
508 }
509
510 unsigned long timeOut = maxTime ? SaturatingSubtract(maxTime, timer.ElapsedTime()) : 0;
511 if (sender.MustWaitToSend() && !sender.Wait(timeOut, CallStack("NetworkSink::DoFlush() - wait send", 0)))
512 break;
513
514 size_t contiguousSize = 0;
515 const byte *block = m_buffer.Spy(contiguousSize);
516
517#if CRYPTOPP_TRACE_NETWORK
518 OutputDebugString((IntToString((unsigned int)this) + ": Sending " + IntToString(contiguousSize) + " bytes\n").c_str());
519#endif
520 sender.Send(block, contiguousSize);
521 m_needSendResult = true;
522
523 if (maxTime > 0 && timeOut == 0)
524 break; // once time limit is reached, return even if there is more data waiting
525 }
526
527 m_byteCountSinceLastTimerReset += totalFlushSize;
528 ComputeCurrentSpeed();
529
530 if (m_buffer.IsEmpty() && !m_needSendResult)
531 {
532 if (m_eofState == EOF_PENDING_SEND)
533 {
534 sender.SendEof();
535 m_eofState = sender.MustWaitForEof() ? EOF_PENDING_DELIVERY : EOF_DONE;

Callers

nothing calls this directly

Calls 15

SaturatingSubtractFunction · 0.85
IntToStringFunction · 0.85
ElapsedTimeMethod · 0.80
AnyRetrievableMethod · 0.80
MustWaitToSendMethod · 0.80
EofSentMethod · 0.80
CallStackClass · 0.70
CurrentSizeMethod · 0.45
MustWaitForResultMethod · 0.45
WaitMethod · 0.45
GetSendResultMethod · 0.45
SkipMethod · 0.45

Tested by

no test coverage detected