📄 network_8cpp-source.html
字号:
<a name="l00316"></a>00316 <span class="preprocessor"></span> <span class="keywordflow">while</span> (receiver.<a class="code" href="class_network_receiver.html#5e1c4db8bc07f0bf5b8d06496162cbe1" title="receive data from network source, returns whether result is immediately available...">Receive</a>(m_buf+m_dataEnd, m_buf.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-m_dataEnd))<a name="l00317"></a>00317 {<a name="l00318"></a>00318 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> recvResult = receiver.<a class="code" href="class_network_receiver.html#3d7974f03642b4da960e918ca1ce485a">GetReceiveResult</a>();<a name="l00319"></a>00319 <span class="preprocessor">#if CRYPTOPP_TRACE_NETWORK</span><a name="l00320"></a>00320 <span class="preprocessor"></span> OutputDebugString((IntToString((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<span class="keyword">this</span>) + <span class="stringliteral">": Received "</span> + IntToString(recvResult) + <span class="stringliteral">" bytes\n"</span>).c_str());<a name="l00321"></a>00321 <span class="preprocessor">#endif</span><a name="l00322"></a>00322 <span class="preprocessor"></span> m_dataEnd += recvResult;<a name="l00323"></a>00323 <span class="keywordflow">if</span> (receiver.<a class="code" href="class_network_receiver.html#eba679e0b607742c7c7298a3796d069d">EofReceived</a>() || m_dataEnd > m_buf.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>() /2)<a name="l00324"></a>00324 {<a name="l00325"></a>00325 m_waitingForResult = <span class="keyword">false</span>;<a name="l00326"></a>00326 <span class="keywordflow">break</span>;<a name="l00327"></a>00327 }<a name="l00328"></a>00328 }<a name="l00329"></a>00329 }<a name="l00330"></a>00330 }<a name="l00331"></a>00331 }<a name="l00332"></a>00332 <span class="keywordflow">else</span><a name="l00333"></a>00333 {<a name="l00334"></a>00334 m_putSize = UnsignedMin(m_dataEnd - m_dataBegin, maxSize - byteCount);<a name="l00335"></a>00335 <a name="l00336"></a>00336 <span class="keywordflow">if</span> (checkDelimiter)<a name="l00337"></a>00337 m_putSize = std::find(m_buf+m_dataBegin, m_buf+m_dataBegin+m_putSize, delimiter) - (m_buf+m_dataBegin);<a name="l00338"></a>00338 <a name="l00339"></a>00339 DoOutput:<a name="l00340"></a>00340 <span class="keywordtype">size_t</span> result = t-><a class="code" href="class_buffered_transformation.html#770bf11f26d4dec66423a7dc2d36843d" title="input multiple bytes that may be modified by callee for blocking or non-blocking...">PutModifiable2</a>(m_buf+m_dataBegin, m_putSize, 0, forever || blockingOutput);<a name="l00341"></a>00341 <span class="keywordflow">if</span> (result)<a name="l00342"></a>00342 {<a name="l00343"></a>00343 <span class="keywordflow">if</span> (t-><a class="code" href="class_waitable.html#ded81bbe562f61932306a64e6122a6ca" title="wait on this object">Wait</a>(SaturatingSubtract(maxTime, timer.<a class="code" href="class_timer_base.html#eab32d0bc5ca83836e0e9f9e108d66a4">ElapsedTime</a>()),<a name="l00344"></a>00344 <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSource::DoPump() - wait attachment"</span>, 0)))<a name="l00345"></a>00345 <span class="keywordflow">goto</span> DoOutput;<a name="l00346"></a>00346 <span class="keywordflow">else</span><a name="l00347"></a>00347 {<a name="l00348"></a>00348 m_outputBlocked = <span class="keyword">true</span>;<a name="l00349"></a>00349 <span class="keywordflow">return</span> result;<a name="l00350"></a>00350 }<a name="l00351"></a>00351 }<a name="l00352"></a>00352 m_outputBlocked = <span class="keyword">false</span>;<a name="l00353"></a>00353 <a name="l00354"></a>00354 byteCount += m_putSize;<a name="l00355"></a>00355 m_dataBegin += m_putSize;<a name="l00356"></a>00356 <span class="keywordflow">if</span> (checkDelimiter && m_dataBegin < m_dataEnd && m_buf[m_dataBegin] == delimiter)<a name="l00357"></a>00357 <span class="keywordflow">break</span>;<a name="l00358"></a>00358 <span class="keywordflow">if</span> (maxSize != ULONG_MAX && byteCount == maxSize)<a name="l00359"></a>00359 <span class="keywordflow">break</span>;<a name="l00360"></a>00360 <span class="comment">// once time limit is reached, return even if there is more data waiting</span><a name="l00361"></a>00361 <span class="comment">// but make 0 a special case so caller can request a large amount of data to be</span><a name="l00362"></a>00362 <span class="comment">// pumped as long as it is immediately available</span><a name="l00363"></a>00363 <span class="keywordflow">if</span> (maxTime > 0 && timer.<a class="code" href="class_timer_base.html#eab32d0bc5ca83836e0e9f9e108d66a4">ElapsedTime</a>() > maxTime)<a name="l00364"></a>00364 <span class="keywordflow">break</span>;<a name="l00365"></a>00365 }<a name="l00366"></a>00366 }<a name="l00367"></a>00367 <a name="l00368"></a>00368 <span class="keywordflow">return</span> 0;<a name="l00369"></a>00369 }<a name="l00370"></a>00370 <a name="l00371"></a>00371 <span class="comment">// *************************************************************</span><a name="l00372"></a>00372 <a name="l00373"></a><a class="code" href="class_network_sink.html#c778064029bf196a1342625e29aaa227">00373</a> <a class="code" href="class_network_sink.html#c778064029bf196a1342625e29aaa227">NetworkSink::NetworkSink</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> maxBufferSize, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> autoFlushBound)<a name="l00374"></a>00374 : m_maxBufferSize(maxBufferSize), m_autoFlushBound(autoFlushBound)<a name="l00375"></a>00375 , m_needSendResult(false), m_wasBlocked(false), m_eofState(EOF_NONE)<a name="l00376"></a>00376 , m_buffer(STDMIN(16U*1024U+256, maxBufferSize)), m_skipBytes(0) <a name="l00377"></a>00377 , m_speedTimer(<a class="code" href="class_timer.html" title="high resolution timer">Timer</a>::MILLISECONDS), m_byteCountSinceLastTimerReset(0)<a name="l00378"></a>00378 , m_currentSpeed(0), m_maxObservedSpeed(0)<a name="l00379"></a>00379 {<a name="l00380"></a>00380 }<a name="l00381"></a>00381 <a name="l00382"></a><a class="code" href="class_network_sink.html#a0da4518b7999c27c4a131f71ef06795">00382</a> <span class="keywordtype">float</span> <a class="code" href="class_network_sink.html#a0da4518b7999c27c4a131f71ef06795" title="compute the current speed of this sink in bytes per second">NetworkSink::ComputeCurrentSpeed</a>()<a name="l00383"></a>00383 {<a name="l00384"></a>00384 <span class="keywordflow">if</span> (m_speedTimer.<a class="code" href="class_timer_base.html#eab32d0bc5ca83836e0e9f9e108d66a4">ElapsedTime</a>() > 1000)<a name="l00385"></a>00385 {<a name="l00386"></a>00386 m_currentSpeed = m_byteCountSinceLastTimerReset * 1000 / m_speedTimer.<a class="code" href="class_timer_base.html#eab32d0bc5ca83836e0e9f9e108d66a4">ElapsedTime</a>();<a name="l00387"></a>00387 m_maxObservedSpeed = STDMAX(m_currentSpeed, m_maxObservedSpeed * 0.98f);<a name="l00388"></a>00388 m_byteCountSinceLastTimerReset = 0;<a name="l00389"></a>00389 m_speedTimer.<a class="code" href="class_timer_base.html#50804b61c4254f7289c6c67515d5d46d">StartTimer</a>();<a name="l00390"></a>00390 <span class="comment">// OutputDebugString(("max speed: " + IntToString((int)m_maxObservedSpeed) + " current speed: " + IntToString((int)m_currentSpeed) + "\n").c_str());</span><a name="l00391"></a>00391 }<a name="l00392"></a>00392 <span class="keywordflow">return</span> m_currentSpeed;<a name="l00393"></a>00393 }<a name="l00394"></a>00394 <a name="l00395"></a><a class="code" href="class_network_sink.html#72fd5feef36aae810f3832c8b6e8ee81">00395</a> <span class="keywordtype">float</span> <a class="code" href="class_network_sink.html#72fd5feef36aae810f3832c8b6e8ee81" title="get the maximum observed speed of this sink in bytes per second">NetworkSink::GetMaxObservedSpeed</a>()<span class="keyword"> const</span><a name="l00396"></a>00396 <span class="keyword"></span>{<a name="l00397"></a>00397 lword m = <a class="code" href="class_limited_bandwidth.html#6bd1d7ab2fd038e150e058a30700b989">GetMaxBytesPerSecond</a>();<a name="l00398"></a>00398 <span class="keywordflow">return</span> m ? STDMIN(m_maxObservedSpeed, <span class="keywordtype">float</span>(CRYPTOPP_VC6_INT64 m)) : m_maxObservedSpeed;<a name="l00399"></a>00399 }<a name="l00400"></a>00400 <a name="l00401"></a><a class="code" href="class_network_sink.html#87f8ea4beb77135a3dc0ee1c5fcb72d5">00401</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_network_sink.html#87f8ea4beb77135a3dc0ee1c5fcb72d5">NetworkSink::GetMaxWaitObjectCount</a>()<span class="keyword"> const</span><a name="l00402"></a>00402 <span class="keyword"></span>{<a name="l00403"></a>00403 <span class="keywordflow">return</span> <a class="code" href="class_limited_bandwidth.html#1f5898c4e376b0d205fd784eaf5dec56">LimitedBandwidth::GetMaxWaitObjectCount</a>() + <a class="code" href="class_network_sink.html#4c69470708806083c426045695a396ac">GetSender</a>().<a class="code" href="class_waitable.html#3cac959dd3d871d332b6ca87f3a044b3" title="maximum number of wait objects that this object can return">GetMaxWaitObjectCount</a>();<a name="l00404"></a>00404 }<a name="l00405"></a>00405 <a name="l00406"></a><a class="code" href="class_network_sink.html#398a8ac1689dffbabb0115787904688b">00406</a> <span class="keywordtype">void</span> <a class="code" href="class_network_sink.html#398a8ac1689dffbabb0115787904688b">NetworkSink::GetWaitObjects</a>(<a class="code" href="class_wait_object_container.html" title="container of wait objects">WaitObjectContainer</a> &container, <a class="code" href="class_call_stack.html">CallStack</a> <span class="keyword">const</span>& callStack)<a name="l00407"></a>00407 {<a name="l00408"></a>00408 <span class="keywordflow">if</span> (<a class="code" href="class_nonblocking_sink.html#5558b33305f12a74c7fc3ac88d5af8cd">BlockedBySpeedLimit</a>())<a name="l00409"></a>00409 <a class="code" href="class_limited_bandwidth.html#be3aabb618510d9629c1a65382fbfdb3">LimitedBandwidth::GetWaitObjects</a>(container, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::GetWaitObjects() - speed limit"</span>, &callStack));<a name="l00410"></a>00410 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m_wasBlocked)<a name="l00411"></a>00411 AccessSender().<a class="code" href="class_waitable.html#97155f28db33d3dacc69dc453a01609a" title="put wait objects into container">GetWaitObjects</a>(container, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::GetWaitObjects() - was blocked"</span>, &callStack));<a name="l00412"></a>00412 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!m_buffer.<a class="code" href="class_byte_queue.html#c218d4b07fe058306a00475222869aaa">IsEmpty</a>())<a name="l00413"></a>00413 AccessSender().<a class="code" href="class_waitable.html#97155f28db33d3dacc69dc453a01609a" title="put wait objects into container">GetWaitObjects</a>(container, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::GetWaitObjects() - buffer not empty"</span>, &callStack));<a name="l00414"></a>00414 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="class_network_sink.html#2682fef333bb6bc3bb318750df7011a6">EofPending</a>())<a name="l00415"></a>00415 AccessSender().<a class="code" href="class_waitable.html#97155f28db33d3dacc69dc453a01609a" title="put wait objects into container">GetWaitObjects</a>(container, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::GetWaitObjects() - EOF pending"</span>, &callStack));<a name="l00416"></a>00416 }<a name="l00417"></a>00417 <a name="l00418"></a><a class="code" href="class_network_sink.html#5827a2d026f19314c777b068ce2b69fb">00418</a> <span class="keywordtype">size_t</span> <a class="code" href="class_network_sink.html#5827a2d026f19314c777b068ce2b69fb" title="input multiple bytes for blocking or non-blocking processing">NetworkSink::Put2</a>(<span class="keyword">const</span> byte *inString, <span class="keywordtype">size_t</span> length, <span class="keywordtype">int</span> messageEnd, <span class="keywordtype">bool</span> blocking)<a name="l00419"></a>00419 {<a name="l00420"></a>00420 <span class="keywordflow">if</span> (m_eofState == EOF_DONE)<a name="l00421"></a>00421 {<a name="l00422"></a>00422 <span class="keywordflow">if</span> (length || messageEnd)<a name="l00423"></a>00423 <span class="keywordflow">throw</span> <a class="code" href="class_exception.html" title="base class for all exceptions thrown by Crypto++">Exception</a>(<a class="code" href="class_exception.html#8e53909d979479380e0274807c074c0a27d9ee7704100a88e4ae4adcc4072015" title="some error not belong to any of the above categories">Exception::OTHER_ERROR</a>, <span class="stringliteral">"NetworkSink::Put2() being called after EOF had been sent"</span>);<a name="l00424"></a>00424 <a name="l00425"></a>00425 <span class="keywordflow">return</span> 0;<a name="l00426"></a>00426 }<a name="l00427"></a>00427
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -