⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network_8cpp-source.html

📁 著名的密码库Crypto++的文档 C++语言的杰作。程序员必备。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00428"></a>00428         <span class="keywordflow">if</span> (m_eofState &gt; EOF_NONE)<a name="l00429"></a>00429                 <span class="keywordflow">goto</span> EofSite;<a name="l00430"></a>00430 <a name="l00431"></a>00431         {<a name="l00432"></a>00432                 <span class="keywordflow">if</span> (m_skipBytes)<a name="l00433"></a>00433                 {<a name="l00434"></a>00434                         assert(length &gt;= m_skipBytes);<a name="l00435"></a>00435                         inString += m_skipBytes;<a name="l00436"></a>00436                         length -= m_skipBytes;<a name="l00437"></a>00437                 }<a name="l00438"></a>00438 <a name="l00439"></a>00439                 m_buffer.<a class="code" href="class_buffered_transformation.html#e70658b0d271f8e114ac6c3cc9774ede" title="input a byte for processing">Put</a>(inString, length);<a name="l00440"></a>00440 <a name="l00441"></a>00441                 <span class="keywordflow">if</span> (!blocking || m_buffer.<a class="code" href="class_byte_queue.html#003ce4b0f9525589327800d0a14b455f">CurrentSize</a>() &gt; m_autoFlushBound)<a name="l00442"></a>00442                         <a class="code" href="class_nonblocking_sink.html#f5da8dc12d42cf6152588ab02de4d336" title="flush to device for no more than maxTime milliseconds">TimedFlush</a>(0, 0);<a name="l00443"></a>00443 <a name="l00444"></a>00444                 <span class="keywordtype">size_t</span> targetSize = messageEnd ? 0 : m_maxBufferSize;<a name="l00445"></a>00445                 <span class="keywordflow">if</span> (blocking)<a name="l00446"></a>00446                         <a class="code" href="class_nonblocking_sink.html#f5da8dc12d42cf6152588ab02de4d336" title="flush to device for no more than maxTime milliseconds">TimedFlush</a>(<a class="code" href="cryptlib_8h.html#5dc7a255dd813433eeee3152544c2f1d" title="used to represent infinite time">INFINITE_TIME</a>, targetSize);<a name="l00447"></a>00447 <a name="l00448"></a>00448                 <span class="keywordflow">if</span> (m_buffer.<a class="code" href="class_byte_queue.html#003ce4b0f9525589327800d0a14b455f">CurrentSize</a>() &gt; targetSize)<a name="l00449"></a>00449                 {<a name="l00450"></a>00450                         assert(!blocking);<a name="l00451"></a>00451                         m_wasBlocked = <span class="keyword">true</span>;<a name="l00452"></a>00452                         m_skipBytes += length;<a name="l00453"></a>00453                         <span class="keywordtype">size_t</span> blockedBytes = UnsignedMin(length, m_buffer.<a class="code" href="class_byte_queue.html#003ce4b0f9525589327800d0a14b455f">CurrentSize</a>() - targetSize);<a name="l00454"></a>00454                         <span class="keywordflow">return</span> STDMAX&lt;size_t&gt;(blockedBytes, 1);<a name="l00455"></a>00455                 }<a name="l00456"></a>00456 <a name="l00457"></a>00457                 m_wasBlocked = <span class="keyword">false</span>;<a name="l00458"></a>00458                 m_skipBytes = 0;<a name="l00459"></a>00459         }<a name="l00460"></a>00460 <a name="l00461"></a>00461         <span class="keywordflow">if</span> (messageEnd)<a name="l00462"></a>00462         {<a name="l00463"></a>00463                 m_eofState = EOF_PENDING_SEND;<a name="l00464"></a>00464 <a name="l00465"></a>00465         EofSite:<a name="l00466"></a>00466                 <a class="code" href="class_nonblocking_sink.html#f5da8dc12d42cf6152588ab02de4d336" title="flush to device for no more than maxTime milliseconds">TimedFlush</a>(blocking ? <a class="code" href="cryptlib_8h.html#5dc7a255dd813433eeee3152544c2f1d" title="used to represent infinite time">INFINITE_TIME</a> : 0, 0);<a name="l00467"></a>00467                 <span class="keywordflow">if</span> (m_eofState != EOF_DONE)<a name="l00468"></a>00468                         <span class="keywordflow">return</span> 1;<a name="l00469"></a>00469         }<a name="l00470"></a>00470 <a name="l00471"></a>00471         <span class="keywordflow">return</span> 0;<a name="l00472"></a>00472 }<a name="l00473"></a>00473 <a name="l00474"></a><a class="code" href="class_network_sink.html#3300dceb745c222f3918662e857d6d33">00474</a> lword <a class="code" href="class_network_sink.html#3300dceb745c222f3918662e857d6d33">NetworkSink::DoFlush</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> maxTime, <span class="keywordtype">size_t</span> targetSize)<a name="l00475"></a>00475 {<a name="l00476"></a>00476         <a class="code" href="class_network_sender.html" title="Network Sender.">NetworkSender</a> &amp;sender = AccessSender();<a name="l00477"></a>00477 <a name="l00478"></a>00478         <span class="keywordtype">bool</span> forever = maxTime == <a class="code" href="cryptlib_8h.html#5dc7a255dd813433eeee3152544c2f1d" title="used to represent infinite time">INFINITE_TIME</a>;<a name="l00479"></a>00479         <a class="code" href="class_timer.html" title="high resolution timer">Timer</a> timer(<a class="code" href="class_timer_base.html#ce15d479a8bb76027f1f572010f62fb99a21aebaffc991a16f40f070792f89bf">Timer::MILLISECONDS</a>, forever);<a name="l00480"></a>00480         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> totalFlushSize = 0;<a name="l00481"></a>00481 <a name="l00482"></a>00482         <span class="keywordflow">while</span> (<span class="keyword">true</span>)<a name="l00483"></a>00483         {<a name="l00484"></a>00484                 <span class="keywordflow">if</span> (m_buffer.<a class="code" href="class_byte_queue.html#003ce4b0f9525589327800d0a14b455f">CurrentSize</a>() &lt;= targetSize)<a name="l00485"></a>00485                         <span class="keywordflow">break</span>;<a name="l00486"></a>00486                 <a name="l00487"></a>00487                 <span class="keywordflow">if</span> (m_needSendResult)<a name="l00488"></a>00488                 {<a name="l00489"></a>00489                         <span class="keywordflow">if</span> (sender.<a class="code" href="class_network_sender.html#89a0a3abf4c83dcbcb0ddd52addd44fb">MustWaitForResult</a>() &amp;&amp;<a name="l00490"></a>00490                                 !sender.<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="l00491"></a>00491                                         <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::DoFlush() - wait send result"</span>, 0)))<a name="l00492"></a>00492                                 <span class="keywordflow">break</span>;<a name="l00493"></a>00493 <a name="l00494"></a>00494                         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sendResult = sender.<a class="code" href="class_network_sender.html#1efa48c4cc8d6ca14a31b8eca210663a">GetSendResult</a>();<a name="l00495"></a>00495 <span class="preprocessor">#if CRYPTOPP_TRACE_NETWORK</span><a name="l00496"></a>00496 <span class="preprocessor"></span>                        OutputDebugString((IntToString((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<span class="keyword">this</span>) + <span class="stringliteral">": Sent "</span> + IntToString(sendResult) + <span class="stringliteral">" bytes\n"</span>).c_str());<a name="l00497"></a>00497 <span class="preprocessor">#endif</span><a name="l00498"></a>00498 <span class="preprocessor"></span>                        m_buffer.<a class="code" href="class_buffered_transformation.html#0c25529ded99db20ad35ccef3f7234e6" title="discard skipMax bytes from the output buffer">Skip</a>(sendResult);<a name="l00499"></a>00499                         totalFlushSize += sendResult;<a name="l00500"></a>00500                         m_needSendResult = <span class="keyword">false</span>;<a name="l00501"></a>00501 <a name="l00502"></a>00502                         <span class="keywordflow">if</span> (!m_buffer.<a class="code" href="class_byte_queue.html#e0d701bf528a1131917b77c0bb3fb369" title="returns whether any bytes are currently ready for retrieval">AnyRetrievable</a>())<a name="l00503"></a>00503                                 <span class="keywordflow">break</span>;<a name="l00504"></a>00504                 }<a name="l00505"></a>00505 <a name="l00506"></a>00506                 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> timeOut = maxTime ? SaturatingSubtract(maxTime, timer.<a class="code" href="class_timer_base.html#eab32d0bc5ca83836e0e9f9e108d66a4">ElapsedTime</a>()) : 0;<a name="l00507"></a>00507                 <span class="keywordflow">if</span> (sender.<a class="code" href="class_network_sender.html#fb86f4dc8d5ba76ad18f3be4a20d768e">MustWaitToSend</a>() &amp;&amp; !sender.<a class="code" href="class_waitable.html#ded81bbe562f61932306a64e6122a6ca" title="wait on this object">Wait</a>(timeOut, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::DoFlush() - wait send"</span>, 0)))<a name="l00508"></a>00508                         <span class="keywordflow">break</span>;<a name="l00509"></a>00509 <a name="l00510"></a>00510                 <span class="keywordtype">size_t</span> contiguousSize = 0;<a name="l00511"></a>00511                 <span class="keyword">const</span> byte *block = m_buffer.<a class="code" href="class_byte_queue.html#18f79d62aa125a795cf61444d1076cde">Spy</a>(contiguousSize);<a name="l00512"></a>00512 <a name="l00513"></a>00513 <span class="preprocessor">#if CRYPTOPP_TRACE_NETWORK</span><a name="l00514"></a>00514 <span class="preprocessor"></span>                OutputDebugString((IntToString((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<span class="keyword">this</span>) + <span class="stringliteral">": Sending "</span> + IntToString(contiguousSize) + <span class="stringliteral">" bytes\n"</span>).c_str());<a name="l00515"></a>00515 <span class="preprocessor">#endif</span><a name="l00516"></a>00516 <span class="preprocessor"></span>                sender.<a class="code" href="class_network_sender.html#a7655dd390817ca54628a5af93c23892">Send</a>(block, contiguousSize);<a name="l00517"></a>00517                 m_needSendResult = <span class="keyword">true</span>;<a name="l00518"></a>00518 <a name="l00519"></a>00519                 <span class="keywordflow">if</span> (maxTime &gt; 0 &amp;&amp; timeOut == 0)<a name="l00520"></a>00520                         <span class="keywordflow">break</span>;  <span class="comment">// once time limit is reached, return even if there is more data waiting</span><a name="l00521"></a>00521         }<a name="l00522"></a>00522 <a name="l00523"></a>00523         m_byteCountSinceLastTimerReset += totalFlushSize;<a name="l00524"></a>00524         <a class="code" href="class_network_sink.html#a0da4518b7999c27c4a131f71ef06795" title="compute the current speed of this sink in bytes per second">ComputeCurrentSpeed</a>();<a name="l00525"></a>00525         <a name="l00526"></a>00526         <span class="keywordflow">if</span> (m_buffer.<a class="code" href="class_byte_queue.html#c218d4b07fe058306a00475222869aaa">IsEmpty</a>() &amp;&amp; !m_needSendResult)<a name="l00527"></a>00527         {<a name="l00528"></a>00528                 <span class="keywordflow">if</span> (m_eofState == EOF_PENDING_SEND)<a name="l00529"></a>00529                 {<a name="l00530"></a>00530                         sender.<a class="code" href="class_network_sender.html#8291fe8d3ac83b1df0bfdb92d58dd06c">SendEof</a>();<a name="l00531"></a>00531                         m_eofState = sender.<a class="code" href="class_network_sender.html#d3efdc8b10e91dfa5a901416735be820">MustWaitForEof</a>() ? EOF_PENDING_DELIVERY : EOF_DONE;<a name="l00532"></a>00532                 }<a name="l00533"></a>00533 <a name="l00534"></a>00534                 <span class="keywordflow">while</span> (m_eofState == EOF_PENDING_DELIVERY)<a name="l00535"></a>00535                 {<a name="l00536"></a>00536                         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> timeOut = maxTime ? SaturatingSubtract(maxTime, timer.<a class="code" href="class_timer_base.html#eab32d0bc5ca83836e0e9f9e108d66a4">ElapsedTime</a>()) : 0;<a name="l00537"></a>00537                         <span class="keywordflow">if</span> (!sender.<a class="code" href="class_waitable.html#ded81bbe562f61932306a64e6122a6ca" title="wait on this object">Wait</a>(timeOut, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSink::DoFlush() - w

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -