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

📄 a00193.html

📁 UIP完整的协议栈
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="l00117"></a><a class="code" href="a00082.html#a408ca8630154ebd039f37a828399f7b">00117</a>   <a class="code" href="a00153.html#g77570ac4fcab86864fa1916e55676da2">u16_t</a> <a class="code" href="a00082.html#a408ca8630154ebd039f37a828399f7b">readlen</a>;         <span class="comment">/* The number of bytes left to be read. */</span><a name="l00118"></a>00118 <a name="l00119"></a><a class="code" href="a00082.html#d6bd03239291629676e4c0286ebb650f">00119</a>   <span class="keyword">struct </span><a class="code" href="a00083.html">psock_buf</a> <a class="code" href="a00082.html#d6bd03239291629676e4c0286ebb650f">buf</a>;  <span class="comment">/* The structure holding the state of the</span><a name="l00120"></a>00120 <span class="comment">                            input buffer. */</span><a name="l00121"></a><a class="code" href="a00082.html#a6bfaf327ce839ba70accd71014398d0">00121</a>   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="a00082.html#a6bfaf327ce839ba70accd71014398d0">bufsize</a>;  <span class="comment">/* The size of the input buffer. */</span><a name="l00122"></a>00122   <a name="l00123"></a><a class="code" href="a00082.html#fda184638130452f3570966acc5b97f9">00123</a>   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="a00082.html#fda184638130452f3570966acc5b97f9">state</a>;   <span class="comment">/* The state of the protosocket. */</span><a name="l00124"></a>00124 };<a name="l00125"></a>00125 <a name="l00126"></a>00126 <span class="keywordtype">void</span> psock_init(<span class="keyword">struct</span> <a class="code" href="a00082.html">psock</a> *<a class="code" href="a00082.html">psock</a>, <span class="keywordtype">char</span> *buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> buffersize);<span class="comment"></span><a name="l00127"></a>00127 <span class="comment">/**</span><a name="l00128"></a>00128 <span class="comment"> * Initialize a protosocket.</span><a name="l00129"></a>00129 <span class="comment"> *</span><a name="l00130"></a>00130 <span class="comment"> * This macro initializes a protosocket and must be called before the</span><a name="l00131"></a>00131 <span class="comment"> * protosocket is used. The initialization also specifies the input buffer</span><a name="l00132"></a>00132 <span class="comment"> * for the protosocket.</span><a name="l00133"></a>00133 <span class="comment"> *</span><a name="l00134"></a>00134 <span class="comment"> * \param psock (struct psock *) A pointer to the protosocket to be</span><a name="l00135"></a>00135 <span class="comment"> * initialized</span><a name="l00136"></a>00136 <span class="comment"> *</span><a name="l00137"></a>00137 <span class="comment"> * \param buffer (char *) A pointer to the input buffer for the</span><a name="l00138"></a>00138 <span class="comment"> * protosocket.</span><a name="l00139"></a>00139 <span class="comment"> *</span><a name="l00140"></a>00140 <span class="comment"> * \param buffersize (unsigned int) The size of the input buffer.</span><a name="l00141"></a>00141 <span class="comment"> *</span><a name="l00142"></a>00142 <span class="comment"> * \hideinitializer</span><a name="l00143"></a>00143 <span class="comment"> */</span><a name="l00144"></a><a class="code" href="a00158.html#g26ae707402e494f3895a9f012a93ea29">00144</a> <span class="preprocessor">#define PSOCK_INIT(psock, buffer, buffersize) \</span><a name="l00145"></a>00145 <span class="preprocessor">  psock_init(psock, buffer, buffersize)</span><a name="l00146"></a>00146 <span class="preprocessor"></span><span class="comment"></span><a name="l00147"></a>00147 <span class="comment">/**</span><a name="l00148"></a>00148 <span class="comment"> * Start the protosocket protothread in a function.</span><a name="l00149"></a>00149 <span class="comment"> *</span><a name="l00150"></a>00150 <span class="comment"> * This macro starts the protothread associated with the protosocket and</span><a name="l00151"></a>00151 <span class="comment"> * must come before other protosocket calls in the function it is used.</span><a name="l00152"></a>00152 <span class="comment"> *</span><a name="l00153"></a>00153 <span class="comment"> * \param psock (struct psock *) A pointer to the protosocket to be</span><a name="l00154"></a>00154 <span class="comment"> * started.</span><a name="l00155"></a>00155 <span class="comment"> *</span><a name="l00156"></a>00156 <span class="comment"> * \hideinitializer</span><a name="l00157"></a>00157 <span class="comment"> */</span><a name="l00158"></a><a class="code" href="a00158.html#g84901a5aa60040e96d272a69977edd22">00158</a> <span class="preprocessor">#define PSOCK_BEGIN(psock) PT_BEGIN(&amp;((psock)-&gt;pt))</span><a name="l00159"></a>00159 <span class="preprocessor"></span><a name="l00160"></a>00160 <a class="code" href="a00142.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(psock_send(<span class="keyword">struct</span> <a class="code" href="a00082.html">psock</a> *<a class="code" href="a00082.html">psock</a>, <span class="keyword">const</span> <span class="keywordtype">char</span> *buf, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len));<span class="comment"></span><a name="l00161"></a>00161 <span class="comment">/**</span><a name="l00162"></a>00162 <span class="comment"> * Send data.</span><a name="l00163"></a>00163 <span class="comment"> *</span><a name="l00164"></a>00164 <span class="comment"> * This macro sends data over a protosocket. The protosocket protothread blocks</span><a name="l00165"></a>00165 <span class="comment"> * until all data has been sent and is known to have been received by</span><a name="l00166"></a>00166 <span class="comment"> * the remote end of the TCP connection.</span><a name="l00167"></a>00167 <span class="comment"> *</span><a name="l00168"></a>00168 <span class="comment"> * \param psock (struct psock *) A pointer to the protosocket over which</span><a name="l00169"></a>00169 <span class="comment"> * data is to be sent.</span><a name="l00170"></a>00170 <span class="comment"> *</span><a name="l00171"></a>00171 <span class="comment"> * \param data (char *) A pointer to the data that is to be sent.</span><a name="l00172"></a>00172 <span class="comment"> *</span><a name="l00173"></a>00173 <span class="comment"> * \param datalen (unsigned int) The length of the data that is to be</span><a name="l00174"></a>00174 <span class="comment"> * sent.</span><a name="l00175"></a>00175 <span class="comment"> *</span><a name="l00176"></a>00176 <span class="comment"> * \hideinitializer</span><a name="l00177"></a>00177 <span class="comment"> */</span><a name="l00178"></a><a class="code" href="a00158.html#g70d236d1cf34b4e21836edda60247b70">00178</a> <span class="preprocessor">#define PSOCK_SEND(psock, data, datalen)                \</span><a name="l00179"></a>00179 <span class="preprocessor">    PT_WAIT_THREAD(&amp;((psock)-&gt;pt), psock_send(psock, data, datalen))</span><a name="l00180"></a>00180 <span class="preprocessor"></span><span class="comment"></span><a name="l00181"></a>00181 <span class="comment">/**</span><a name="l00182"></a>00182 <span class="comment"> * \brief      Send a null-terminated string.</span><a name="l00183"></a>00183 <span class="comment"> * \param psock Pointer to the protosocket.</span><a name="l00184"></a>00184 <span class="comment"> * \param str  The string to be sent.</span><a name="l00185"></a>00185 <span class="comment"> *</span><a name="l00186"></a>00186 <span class="comment"> *             This function sends a null-terminated string over the</span><a name="l00187"></a>00187 <span class="comment"> *             protosocket.</span><a name="l00188"></a>00188 <span class="comment"> *</span><a name="l00189"></a>00189 <span class="comment"> * \hideinitializer</span><a name="l00190"></a>00190 <span class="comment"> */</span><a name="l00191"></a><a class="code" href="a00158.html#gb0ad55aa96dd1d200cd0fc5a99f6a4f7">00191</a> <span class="preprocessor">#define PSOCK_SEND_STR(psock, str)                      \</span><a name="l00192"></a>00192 <span class="preprocessor">    PT_WAIT_THREAD(&amp;((psock)-&gt;pt), psock_send(psock, str, strlen(str)))</span><a name="l00193"></a>00193 <span class="preprocessor"></span><a name="l00194"></a>00194 <a class="code" href="a00142.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(psock_generator_send(<span class="keyword">struct</span> <a class="code" href="a00082.html">psock</a> *<a class="code" href="a00082.html">psock</a>,<a name="l00195"></a>00195                                 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> (*f)(<span class="keywordtype">void</span> *), <span class="keywordtype">void</span> *arg));<a name="l00196"></a>00196 <span class="comment"></span><a name="l00197"></a>00197 <span class="comment">/**</span><a name="l00198"></a>00198 <span class="comment"> * \brief      Generate data with a function and send it</span><a name="l00199"></a>00199 <span class="comment"> * \param psock Pointer to the protosocket.</span><a name="l00200"></a>00200 <span class="comment"> * \param generator Pointer to the generator function</span><a name="l00201"></a>00201 <span class="comment"> * \param arg   Argument to the generator function</span><a name="l00202"></a>00202 <span class="comment"> *</span><a name="l00203"></a>00203 <span class="comment"> *             This function generates data and sends it over the</span><a name="l00204"></a>00204 <span class="comment"> *             protosocket. This can be used to dynamically generate</span><a name="l00205"></a>00205 <span class="comment"> *             data for a transmission, instead of generating the data</span><a name="l00206"></a>00206 <span class="comment"> *             in a buffer beforehand. This function reduces the need for</span><a name="l00207"></a>00207 <span class="comment"> *             buffer memory. The generator function is implemented by</span><a name="l00208"></a>00208 <span class="comment"> *             the application, and a pointer to the function is given</span><a name="l00209"></a>00209 <span class="comment"> *             as an argument with the call to PSOCK_GENERATOR_SEND().</span><a name="l00210"></a>00210 <span class="comment"> *</span><a name="l00211"></a>00211 <span class="comment"> *             The generator function should place the generated data</span><a name="l00212"></a>00212 <span class="comment"> *             directly in the uip_appdata buffer, and return the</span><a name="l00213"></a>00213 <span class="comment"> *             length of the generated data. The generator function is</span><a name="l00214"></a>00214 <span class="comment"> *             called by the protosocket layer when the data first is</span><a name="l00215"></a>00215 <span class="comment"> *             sent, and once for every retransmission that is needed.</span><a name="l00216"></a>00216 <span class="comment"> *</span><a name="l00217"></a>00217 <span class="comment"> * \hideinitializer</span><a name="l00218"></a>00218 <span class="comment"> */</span><a name="l00219"></a><a class="code" href="a00158.html#g10d9a9201cba1a6db623284c475c6cea">00219</a> <span class="preprocessor">#define PSOCK_GENERATOR_SEND(psock, generator, arg)     \</span><a name="l00220"></a>00220 <span class="preprocessor">    PT_WAIT_THREAD(&amp;((psock)-&gt;pt),                                      \</span><a name="l00221"></a>00221 <span class="preprocessor">                   psock_generator_send(psock, generator, arg))</span><a name="l00222"></a>00222 <span class="preprocessor"></span><a name="l00223"></a>00223 <span class="comment"></span><a name="l00224"></a>00224 <span class="comment">/**</span><a name="l00225"></a>00225 <span class="comment"> * Close a protosocket.</span><a name="l00226"></a>00226 <span class="comment"> *</span><a name="l00227"></a>00227 <span class="comment"> * This macro closes a protosocket and can only be called from within the</span><a name="l00228"></a>00228 <span class="comment"> * protothread in which the protosocket lives.</span><a name="l00229"></a>00229 <span class="comment"> *</span><a name="l00230"></a>00230 <span class="comment"> * \param psock (struct psock *) A pointer to the protosocket that is to</span><a name="l00231"></a>00231 <span class="comment"> * be closed.</span><a name="l00232"></a>00232 <span class="comment"> *</span><a name="l00233"></a>00233 <span class="comment"> * \hideinitializer</span><a name="l00234"></a>00234 <span class="comment"> */</span><a name="l00235"></a><a class="code" href="a00158.html#g5d56800f82bfc7bbf53bb4a659589812">00235</a> <span class="preprocessor">#define PSOCK_CLOSE(psock) uip_close()</span><a name="l00236"></a>00236 <span class="preprocessor"></span><a name="l00237"></a>00237 <a class="code" href="a00142.html#g3d4c8bd4aada659eb34f5d2ffd3e7901">PT_THREAD</a>(psock_readbuf(<span class="keyword">struct</span> psock *psock));<span class="comment"></span><a name="l00238"></a>00238 <span class="comment">/**</span><a name="l00239"></a>00239 <span class="comment"> * Read data until the buffer is full.</span><a name="l00240"></a>00240 <span class="comment"> *</span><a name="l00241"></a>00241 <span class="comment"> * This macro will block waiting for data and read the data into the</span><a name="l00242"></a>00242 <span class="comment"> * input buffer specified with the call to PSOCK_INIT(). Data is read</span><a name="l00243"></a>00243 <span class="comment"> * until the buffer is full..</span><a name="l00244"></a>00244 <span class="comment"> *</span><a name="l00245"></a>00245 <span class="comment"> * \param psock (struct psock *) A pointer to the protosocket from which</span><a name="l00246"></a>00246 <span class="comment"> * data should be read.</span><a name="l00247"></a>00247 <span class="comment"> *</span><a name="l00248"></a>00248 <span class="comment"> * \hideinitializer</span><a name="l00249"></a>00249 <span class="comment"> */</span><a name="l00250"></a><a class="code" href="a00158.html#gd895ab98c54d9966ff554aa873151751">00250</a> <span class="preprocessor">#define PSOCK_READBUF(psock)                            \</span><a name="l00251"></a>00251 <span class="preprocessor">  PT_WAIT_THREAD(&amp;((psock)-&gt;pt), psock_readbuf(psock))</span><a name="l00252"></a>00252 <span class="preprocessor"></span>

⌨️ 快捷键说明

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