network_8cpp-source.html
来自「Crypto++是一个非常强大的密码学库,主要是功能全」· HTML 代码 · 共 225 行 · 第 1/2 页
HTML
225 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Crypto++: network.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div><h1>network.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// network.cpp - written and placed in the public domain by Wei Dai</span>00002 00003 <span class="preprocessor">#include "pch.h"</span>00004 <span class="preprocessor">#include "network.h"</span>00005 00006 NAMESPACE_BEGIN(CryptoPP)00007 00008 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> NonblockingSource::PumpMessages2(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &messageCount, <span class="keywordtype">bool</span> blocking)00009 {00010 <span class="keywordflow">if</span> (messageCount == 0)00011 <span class="keywordflow">return</span> 0;00012 00013 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> byteCount = ULONG_MAX;00014 messageCount = 0;00015 RETURN_IF_NONZERO(Pump2(byteCount, blocking));00016 <span class="keywordflow">if</span> (!m_messageEndSent && SourceExhausted())00017 {00018 RETURN_IF_NONZERO(<a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>()-><a class="code" href="class_buffered_transformation.html#_unflushable_3_01_sink_01_4z1_9">Put2</a>(NULL, 0, GetAutoSignalPropagation(), <span class="keyword">true</span>));00019 m_messageEndSent = <span class="keyword">true</span>;00020 messageCount = 1;00021 }00022 <span class="keywordflow">return</span> 0;00023 }00024 00025 <span class="keywordtype">bool</span> NonblockingSink::IsolatedFlush(<span class="keywordtype">bool</span> hardFlush, <span class="keywordtype">bool</span> blocking)00026 {00027 <a class="code" href="class_nonblocking_sink.html#_nonblocking_sinka1">TimedFlush</a>(blocking ? INFINITE_TIME : 0);00028 <span class="keywordflow">return</span> hardFlush && !!GetCurrentBufferSize();00029 }00030 00031 <span class="comment">// *************************************************************</span>00032 00033 <span class="preprocessor">#ifdef HIGHRES_TIMER_AVAILABLE</span>00034 <span class="preprocessor"></span>00035 NetworkSource::NetworkSource(<a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *attachment)00036 : <a class="code" href="class_nonblocking_source.html">NonblockingSource</a>(attachment), m_buf(1024*4), m_bufSize(0), m_state(NORMAL)00037 {00038 }00039 <a name="l00040"></a><a class="code" href="class_network_source.html#_windows_pipe_sourcea10">00040</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_network_source.html#_windows_pipe_sourcea10">NetworkSource::GeneralPump2</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> &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)00041 {00042 <a class="code" href="class_network_receiver.html">NetworkReceiver</a> &receiver = AccessReceiver();00043 00044 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> maxSize = byteCount;00045 byteCount = 0;00046 <span class="keywordtype">bool</span> forever = maxTime == <a class="code" href="cryptlib_8h.html#a0">INFINITE_TIME</a>;00047 <a class="code" href="class_timer.html">Timer</a> timer(Timer::MILLISECONDS, forever);00048 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> timeout;00049 <a class="code" href="class_buffered_transformation.html">BufferedTransformation</a> *t = <a class="code" href="class_filter.html#_zlib_decompressora8">AttachedTransformation</a>();00050 00051 <span class="keywordflow">if</span> (m_state == OUTPUT_BLOCKED)00052 <span class="keywordflow">goto</span> DoOutput;00053 00054 <span class="keywordflow">while</span> (<span class="keyword">true</span>)00055 {00056 <span class="keywordflow">if</span> (m_state == WAITING_FOR_RESULT)00057 {00058 <span class="keywordflow">if</span> (receiver.<a class="code" href="class_network_receiver.html#_network_receivera1">MustWaitForResult</a>())00059 {00060 timeout = SaturatingSubtract(maxTime, timer.<a class="code" href="class_timer.html#_timera2">ElapsedTime</a>());00061 <span class="keywordflow">if</span> (!receiver.<a class="code" href="class_waitable.html#_zlib_decompressora19">Wait</a>(timeout))00062 <span class="keywordflow">break</span>;00063 }00064 00065 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> recvResult = receiver.<a class="code" href="class_network_receiver.html#_network_receivera3">GetReceiveResult</a>();00066 <span class="comment">// assert(recvResult > 0 || receiver.EofReceived());</span>00067 m_bufSize += recvResult;00068 m_state = NORMAL;00069 }00070 00071 <span class="keywordflow">if</span> (m_bufSize == 0)00072 {00073 <span class="keywordflow">if</span> (receiver.<a class="code" href="class_network_receiver.html#_network_receivera4">EofReceived</a>())00074 <span class="keywordflow">break</span>;00075 }00076 <span class="keywordflow">else</span>00077 {00078 m_putSize = STDMIN((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)m_bufSize, maxSize - byteCount);00079 <span class="keywordflow">if</span> (checkDelimiter)00080 m_putSize = std::find(m_buf.<a class="code" href="class_sec_block.html#_sec_block_with_hinta7">begin</a>(), m_buf+m_putSize, delimiter) - m_buf;00081 00082 DoOutput:00083 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> result = t->PutModifiable2(m_buf, m_putSize, 0, forever || blockingOutput);00084 <span class="keywordflow">if</span> (result)00085 {00086 timeout = SaturatingSubtract(maxTime, timer.<a class="code" href="class_timer.html#_timera2">ElapsedTime</a>());00087 <span class="keywordflow">if</span> (t->Wait(timeout))00088 <span class="keywordflow">goto</span> DoOutput;00089 <span class="keywordflow">else</span>00090 {00091 m_state = OUTPUT_BLOCKED;00092 <span class="keywordflow">return</span> result;00093 }00094 }00095 m_state = NORMAL;00096 00097 byteCount += m_putSize;00098 m_bufSize -= m_putSize;00099 <span class="keywordflow">if</span> (m_bufSize > 0)00100 {00101 memmove(m_buf, m_buf+m_putSize, m_bufSize);00102 <span class="keywordflow">if</span> (checkDelimiter && m_buf[0] == delimiter)00103 <span class="keywordflow">break</span>;00104 }00105 }00106
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?