📄 network_8cpp-source.html
字号:
<a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="keywordtype">double</span> waitTime = <a class="code" href="class_limited_bandwidth.html#ef86232b3bce4c5385f2a1137d63788f">TimeToNextTransceive</a>();<a name="l00206"></a>00206 <span class="keywordflow">if</span> (!forever && waitTime > timeToGo)<a name="l00207"></a>00207 {<a name="l00208"></a>00208 m_blockedBySpeedLimit = <span class="keyword">true</span>;<a name="l00209"></a>00209 <span class="keywordflow">break</span>;<a name="l00210"></a>00210 }<a name="l00211"></a>00211 <a name="l00212"></a>00212 <a class="code" href="class_wait_object_container.html" title="container of wait objects">WaitObjectContainer</a> container;<a name="l00213"></a>00213 <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">"NonblockingSink::TimedFlush() - speed limit"</span>, 0));<a name="l00214"></a>00214 container.<a class="code" href="class_wait_object_container.html#15356e5e6f3329d8056ed7ba53290be6">Wait</a>((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)waitTime);<a name="l00215"></a>00215 }<a name="l00216"></a>00216 <a name="l00217"></a>00217 <span class="keywordflow">return</span> totalFlushed;<a name="l00218"></a>00218 }<a name="l00219"></a>00219 <a name="l00220"></a><a class="code" href="class_nonblocking_sink.html#f09858e4c31e657d61ca458d00888e2d">00220</a> <span class="keywordtype">bool</span> <a class="code" href="class_nonblocking_sink.html#f09858e4c31e657d61ca458d00888e2d">NonblockingSink::IsolatedFlush</a>(<span class="keywordtype">bool</span> hardFlush, <span class="keywordtype">bool</span> blocking)<a name="l00221"></a>00221 {<a name="l00222"></a>00222 <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);<a name="l00223"></a>00223 <span class="keywordflow">return</span> hardFlush && (!!GetCurrentBufferSize() || EofPending());<a name="l00224"></a>00224 }<a name="l00225"></a>00225 <a name="l00226"></a>00226 <span class="comment">// *************************************************************</span><a name="l00227"></a>00227 <a name="l00228"></a><a class="code" href="class_network_source.html#6bc7cee112849db2581d9feaca00f0d7">00228</a> <a class="code" href="class_network_source.html#6bc7cee112849db2581d9feaca00f0d7">NetworkSource::NetworkSource</a>(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *attachment)<a name="l00229"></a>00229 : <a class="code" href="class_nonblocking_source.html" title="a Source class that can pump from a device for a specified amount of time.">NonblockingSource</a>(attachment), m_buf(1024*16)<a name="l00230"></a>00230 , m_waitingForResult(false), m_outputBlocked(false)<a name="l00231"></a>00231 , m_dataBegin(0), m_dataEnd(0)<a name="l00232"></a>00232 {<a name="l00233"></a>00233 }<a name="l00234"></a>00234 <a name="l00235"></a><a class="code" href="class_network_source.html#b467024c93ec09ec9f301e9a544f3b23">00235</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_network_source.html#b467024c93ec09ec9f301e9a544f3b23">NetworkSource::GetMaxWaitObjectCount</a>()<span class="keyword"> const</span><a name="l00236"></a>00236 <span class="keyword"></span>{<a name="l00237"></a>00237 <span class="keywordflow">return</span> <a class="code" href="class_limited_bandwidth.html#1f5898c4e376b0d205fd784eaf5dec56">LimitedBandwidth::GetMaxWaitObjectCount</a>()<a name="l00238"></a>00238 + <a class="code" href="class_network_source.html#f62a2cbe13c7127349aaeb595edb5edd">GetReceiver</a>().<a class="code" href="class_waitable.html#3cac959dd3d871d332b6ca87f3a044b3" title="maximum number of wait objects that this object can return">GetMaxWaitObjectCount</a>()<a name="l00239"></a>00239 + <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#051a0b5e3e4cc81aca43a9c6cb02e0f9" title="maximum number of wait objects that this object can return">GetMaxWaitObjectCount</a>();<a name="l00240"></a>00240 }<a name="l00241"></a>00241 <a name="l00242"></a><a class="code" href="class_network_source.html#6193d15e11af19041ac1ec17b1228e61">00242</a> <span class="keywordtype">void</span> <a class="code" href="class_network_source.html#6193d15e11af19041ac1ec17b1228e61">NetworkSource::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="l00243"></a>00243 {<a name="l00244"></a>00244 <span class="keywordflow">if</span> (<a class="code" href="class_nonblocking_source.html#32a9026054da9651a057a471c2256b45">BlockedBySpeedLimit</a>())<a name="l00245"></a>00245 <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">"NetworkSource::GetWaitObjects() - speed limit"</span>, &callStack));<a name="l00246"></a>00246 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!m_outputBlocked)<a name="l00247"></a>00247 {<a name="l00248"></a>00248 <span class="keywordflow">if</span> (m_dataBegin == m_dataEnd)<a name="l00249"></a>00249 AccessReceiver().<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">"NetworkSource::GetWaitObjects() - no data"</span>, &callStack)); <a name="l00250"></a>00250 <span class="keywordflow">else</span><a name="l00251"></a>00251 container.<a class="code" href="class_wait_object_container.html#ce9c529ebb1956ee2cb9121bdf30402d">SetNoWait</a>(<a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSource::GetWaitObjects() - have data"</span>, &callStack));<a name="l00252"></a>00252 }<a name="l00253"></a>00253 <a name="l00254"></a>00254 <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#127ccd1793fdda6548cd1295f848d0f7" title="put wait objects into container">GetWaitObjects</a>(container, <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSource::GetWaitObjects() - attachment"</span>, &callStack));<a name="l00255"></a>00255 }<a name="l00256"></a>00256 <a name="l00257"></a><a class="code" href="class_network_source.html#c3b25ad3c01985e0d1fdec420a47edff">00257</a> <span class="keywordtype">size_t</span> <a class="code" href="class_network_source.html#c3b25ad3c01985e0d1fdec420a47edff">NetworkSource::DoPump</a>(lword &byteCount, <span class="keywordtype">bool</span> blockingOutput, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> maxTime, <span class="keywordtype">bool</span> checkDelimiter, byte delimiter)<a name="l00258"></a>00258 {<a name="l00259"></a>00259 <a class="code" href="class_network_receiver.html" title="Network Receiver.">NetworkReceiver</a> &receiver = AccessReceiver();<a name="l00260"></a>00260 <a name="l00261"></a>00261 lword maxSize = byteCount;<a name="l00262"></a>00262 byteCount = 0;<a name="l00263"></a>00263 <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="l00264"></a>00264 <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="l00265"></a>00265 <a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> *t = <a class="code" href="class_filter.html#c8fc888888b2dad88bf64fc703044a93" title="returns the object immediately attached to this object or NULL for no attachment">AttachedTransformation</a>();<a name="l00266"></a>00266 <a name="l00267"></a>00267 <span class="keywordflow">if</span> (m_outputBlocked)<a name="l00268"></a>00268 <span class="keywordflow">goto</span> DoOutput;<a name="l00269"></a>00269 <a name="l00270"></a>00270 <span class="keywordflow">while</span> (<span class="keyword">true</span>)<a name="l00271"></a>00271 {<a name="l00272"></a>00272 <span class="keywordflow">if</span> (m_dataBegin == m_dataEnd)<a name="l00273"></a>00273 {<a name="l00274"></a>00274 <span class="keywordflow">if</span> (receiver.<a class="code" href="class_network_receiver.html#eba679e0b607742c7c7298a3796d069d">EofReceived</a>())<a name="l00275"></a>00275 <span class="keywordflow">break</span>;<a name="l00276"></a>00276 <a name="l00277"></a>00277 <span class="keywordflow">if</span> (m_waitingForResult)<a name="l00278"></a>00278 {<a name="l00279"></a>00279 <span class="keywordflow">if</span> (receiver.<a class="code" href="class_network_receiver.html#f043f80d3fc9ce4a30edd2eb77a4553a">MustWaitForResult</a>() &&<a name="l00280"></a>00280 !receiver.<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="l00281"></a>00281 <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSource::DoPump() - wait receive result"</span>, 0)))<a name="l00282"></a>00282 <span class="keywordflow">break</span>;<a name="l00283"></a>00283 <a name="l00284"></a>00284 <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="l00285"></a>00285 <span class="preprocessor">#if CRYPTOPP_TRACE_NETWORK</span><a name="l00286"></a>00286 <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="l00287"></a>00287 <span class="preprocessor">#endif</span><a name="l00288"></a>00288 <span class="preprocessor"></span> m_dataEnd += recvResult;<a name="l00289"></a>00289 m_waitingForResult = <span class="keyword">false</span>;<a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="keywordflow">if</span> (!receiver.<a class="code" href="class_network_receiver.html#27501ca6a36dae0cc344c57f413aea1d">MustWaitToReceive</a>() && !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>())<a name="l00292"></a>00292 <span class="keywordflow">goto</span> ReceiveNoWait;<a name="l00293"></a>00293 }<a name="l00294"></a>00294 <span class="keywordflow">else</span><a name="l00295"></a>00295 {<a name="l00296"></a>00296 m_dataEnd = m_dataBegin = 0;<a name="l00297"></a>00297 <a name="l00298"></a>00298 <span class="keywordflow">if</span> (receiver.<a class="code" href="class_network_receiver.html#27501ca6a36dae0cc344c57f413aea1d">MustWaitToReceive</a>())<a name="l00299"></a>00299 {<a name="l00300"></a>00300 <span class="keywordflow">if</span> (!receiver.<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="l00301"></a>00301 <a class="code" href="class_call_stack.html">CallStack</a>(<span class="stringliteral">"NetworkSource::DoPump() - wait receive"</span>, 0)))<a name="l00302"></a>00302 <span class="keywordflow">break</span>;<a name="l00303"></a>00303 <a name="l00304"></a>00304 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="l00305"></a>00305 m_waitingForResult = <span class="keyword">true</span>;<a name="l00306"></a>00306 }<a name="l00307"></a>00307 <span class="keywordflow">else</span><a name="l00308"></a>00308 {<a name="l00309"></a>00309 ReceiveNoWait:<a name="l00310"></a>00310 m_waitingForResult = <span class="keyword">true</span>;<a name="l00311"></a>00311 <span class="comment">// call Receive repeatedly as long as data is immediately available,</span><a name="l00312"></a>00312 <span class="comment">// because some receivers tend to return data in small pieces</span><a name="l00313"></a>00313 <span class="preprocessor">#if CRYPTOPP_TRACE_NETWORK</span><a name="l00314"></a>00314 <span class="preprocessor"></span> OutputDebugString((IntToString((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<span class="keyword">this</span>) + <span class="stringliteral">": Receiving "</span> + IntToString(m_buf.<a class="code" href="class_sec_block.html#f5999bffe3193e62719cc0792b0282a7">size</a>()-m_dataEnd) + <span class="stringliteral">" bytes\n"</span>).c_str());<a name="l00315"></a>00315 <span class="preprocessor">#endif</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -