<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>fastcgi++: transceiver.hpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>transceiver.hpp</h1><a href="transceiver_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00002"></a>00002 <span class="comment">/***************************************************************************</span> <a name="l00003"></a>00003 <span class="comment">* Copyright (C) 2007 Eddie *</span> <a name="l00004"></a>00004 <span class="comment">* *</span> <a name="l00005"></a>00005 <span class="comment">* This file is part of fastcgi++. *</span> <a name="l00006"></a>00006 <span class="comment">* *</span> <a name="l00007"></a>00007 <span class="comment">* fastcgi++ is free software: you can redistribute it and/or modify it *</span> <a name="l00008"></a>00008 <span class="comment">* under the terms of the GNU Lesser General Public License as published *</span> <a name="l00009"></a>00009 <span class="comment">* by the Free Software Foundation, either version 3 of the License, or (at *</span> <a name="l00010"></a>00010 <span class="comment">* your option) any later version. *</span> <a name="l00011"></a>00011 <span class="comment">* *</span> <a name="l00012"></a>00012 <span class="comment">* fastcgi++ is distributed in the hope that it will be useful, but WITHOUT *</span> <a name="l00013"></a>00013 <span class="comment">* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *</span> <a name="l00014"></a>00014 <span class="comment">* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public *</span> <a name="l00015"></a>00015 <span class="comment">* License for more details. *</span> <a name="l00016"></a>00016 <span class="comment">* *</span> <a name="l00017"></a>00017 <span class="comment">* You should have received a copy of the GNU Lesser General Public License *</span> <a name="l00018"></a>00018 <span class="comment">* along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *</span> <a name="l00019"></a>00019 <span class="comment">****************************************************************************/</span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#ifndef TRANSCEIVER_HPP</span> <a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#define TRANSCEIVER_HPP</span> <a name="l00024"></a>00024 <span class="preprocessor"></span> <a name="l00025"></a>00025 <span class="preprocessor">#include <map></span> <a name="l00026"></a>00026 <span class="preprocessor">#include <list></span> <a name="l00027"></a>00027 <span class="preprocessor">#include <queue></span> <a name="l00028"></a>00028 <span class="preprocessor">#include <algorithm></span> <a name="l00029"></a>00029 <span class="preprocessor">#include <map></span> <a name="l00030"></a>00030 <span class="preprocessor">#include <vector></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <functional></span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="preprocessor">#include <boost/function.hpp></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <boost/bind.hpp></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <boost/shared_array.hpp></span> <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="preprocessor">#include <unistd.h></span> <a name="l00038"></a>00038 <span class="preprocessor">#include <fcntl.h></span> <a name="l00039"></a>00039 <span class="preprocessor">#include <errno.h></span> <a name="l00040"></a>00040 <span class="preprocessor">#include <poll.h></span> <a name="l00041"></a>00041 <span class="preprocessor">#include <sys/socket.h></span> <a name="l00042"></a>00042 <span class="preprocessor">#include <sys/un.h></span> <a name="l00043"></a>00043 <span class="preprocessor">#include <signal.h></span> <a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="preprocessor">#include <<a class="code" href="protocol_8hpp.html" title="Defines FastCGI protocol.">fastcgi++/protocol.hpp</a>></span> <a name="l00046"></a>00046 <span class="preprocessor">#include <<a class="code" href="exceptions_8hpp.html" title="Defines fastcgi++ exceptions.">fastcgi++/exceptions.hpp</a>></span> <a name="l00047"></a>00047 <a name="l00049"></a>00049 <span class="keyword">namespace </span>Fastcgipp <a name="l00050"></a>00050 { <a name="l00052"></a>00052 <a name="l00056"></a><a class="code" href="structFastcgipp_1_1Block.html">00056</a> <span class="keyword">struct </span><a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a> <a name="l00057"></a>00057 { <a name="l00059"></a>00059 <a name="l00063"></a><a class="code" href="structFastcgipp_1_1Block.html#22087bb7e25a6ba6b45ccd0a80e23066">00063</a> <a class="code" href="structFastcgipp_1_1Block.html#22087bb7e25a6ba6b45ccd0a80e23066" title="Construct from a pointer and size.">Block</a>(<span class="keywordtype">char</span>* data_, <span class="keywordtype">size_t</span> size_): <a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3" title="Pointer to start of memory location.">data</a>(data_), <a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822" title="Size in bytes of memory location.">size</a>(size_) { } <a name="l00065"></a><a class="code" href="structFastcgipp_1_1Block.html#9226974a6c021b674e1abbb857f752bf">00065</a> <a class="code" href="structFastcgipp_1_1Block.html#22087bb7e25a6ba6b45ccd0a80e23066" title="Construct from a pointer and size.">Block</a>(<span class="keyword">const</span> <a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a>& block): <a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3" title="Pointer to start of memory location.">data</a>(block.<a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3" title="Pointer to start of memory location.">data</a>), <a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822" title="Size in bytes of memory location.">size</a>(block.<a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822" title="Size in bytes of memory location.">size</a>) { } <a name="l00067"></a><a class="code" href="structFastcgipp_1_1Block.html#90110dbc90ef7f2c6201ce06e625dfd2">00067</a> <span class="keyword">const</span> <a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a>& <a class="code" href="structFastcgipp_1_1Block.html#90110dbc90ef7f2c6201ce06e625dfd2" title="Copies pointer and size, not data.">operator=</a>(<span class="keyword">const</span> <a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a>& block) { <a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3" title="Pointer to start of memory location.">data</a>=block.<a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3" title="Pointer to start of memory location.">data</a>; <a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822" title="Size in bytes of memory location.">size</a>=block.<a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822" title="Size in bytes of memory location.">size</a>; } <a name="l00069"></a><a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3">00069</a> <span class="keywordtype">char</span>* <a class="code" href="structFastcgipp_1_1Block.html#bdc29a44ee3474fe007ac305504bd4b3" title="Pointer to start of memory location.">data</a>; <a name="l00071"></a><a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822">00071</a> <span class="keywordtype">size_t</span> <a class="code" href="structFastcgipp_1_1Block.html#7ae19c5d24797e378b8435a9c22a8822" title="Size in bytes of memory location.">size</a>; <a name="l00072"></a>00072 }; <a name="l00073"></a>00073 <a name="l00075"></a>00075 <a name="l00079"></a><a class="code" href="classFastcgipp_1_1Transceiver.html">00079</a> <span class="keyword">class </span><a class="code" href="classFastcgipp_1_1Transceiver.html" title="Handles low level communication with &quot;the other side&quot;.">Transceiver</a> <a name="l00080"></a>00080 { <a name="l00081"></a>00081 <span class="keyword">public</span>: <a name="l00083"></a>00083 <a name="l00090"></a>00090 <span class="keywordtype">bool</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#f06e586f5a49dd694f2ae98398870721" title="General transceiver handler.">handler</a>(); <a name="l00091"></a>00091 <a name="l00093"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#5019405a5a05d60fdaa73d349cca58c0">00093</a> <a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a> <a class="code" href="classFastcgipp_1_1Transceiver.html#5019405a5a05d60fdaa73d349cca58c0" title="Direct interface to Buffer::requestWrite().">requestWrite</a>(<span class="keywordtype">size_t</span> size) { <span class="keywordflow">return</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#8656d4bd7359d7e12a9cc5921fc3a1d4" title="Buffer for transmitting data">buffer</a>.<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#cf2cce1c96a7138adda98414f4e0d921" title="Request a write block in the buffer.">requestWrite</a>(size); } <a name="l00095"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#1a720bf113ad9781e59b0fc021988d29">00095</a> <span class="keywordtype">void</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#1a720bf113ad9781e59b0fc021988d29" title="Direct interface to Buffer::secureWrite().">secureWrite</a>(<span class="keywordtype">size_t</span> size, <a class="code" href="structFastcgipp_1_1Protocol_1_1FullId.html" title="A full ID value for a FastCGI request.">Protocol::FullId</a> <span class="keywordtype">id</span>, <span class="keywordtype">bool</span> kill) { <a class="code" href="classFastcgipp_1_1Transceiver.html#8656d4bd7359d7e12a9cc5921fc3a1d4" title="Buffer for transmitting data">buffer</a>.<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#a1a80f3feb1355bd5bc57545d16c309e" title="Secure a write in the buffer.">secureWrite</a>(size, <span class="keywordtype">id</span>, kill); <a class="code" href="classFastcgipp_1_1Transceiver.html#54ffa1d25fed65ff61024ff8ce26a99b" title="Transmit all buffered data possible.">transmit</a>(); } <a name="l00097"></a>00097 <a name="l00104"></a>00104 <a class="code" href="classFastcgipp_1_1Transceiver.html#b8be64ba57bcef64d313960544400d6c" title="Constructor.">Transceiver</a>(<span class="keywordtype">int</span> fd_, boost::function<<span class="keywordtype">void</span>(<a class="code" href="structFastcgipp_1_1Protocol_1_1FullId.html" title="A full ID value for a FastCGI request.">Protocol::FullId</a>, <a class="code" href="structFastcgipp_1_1Message.html" title="Data structure used to pass messages within the fastcgi++ task management system...">Message</a>)> sendMessage_); <a name="l00106"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#5c1bafc977eaa9e4c3e94a5b9eab59eb">00106</a> <span class="keywordtype">void</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#5c1bafc977eaa9e4c3e94a5b9eab59eb" title="Blocks until there is data to receive or a call to wake() is made.">sleep</a>() <a name="l00107"></a>00107 { <a name="l00108"></a>00108 poll(&<a class="code" href="classFastcgipp_1_1Transceiver.html#4b163da2ea08d648a34f9903b86d82fe" title="poll() file descriptors container">pollFds</a>.front(), <a class="code" href="classFastcgipp_1_1Transceiver.html#4b163da2ea08d648a34f9903b86d82fe" title="poll() file descriptors container">pollFds</a>.size(), -1); <a name="l00109"></a>00109 } <a name="l00110"></a>00110 <a name="l00112"></a>00112 <span class="keywordtype">void</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#4dfd5de627b92f6bb5a834a68b20bb85" title="Forces a wakeup from a call to sleep().">wake</a>(); <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="keyword">private</span>: <a name="l00116"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1fdBuffer.html">00116</a> <span class="keyword">struct </span><a class="code" href="structFastcgipp_1_1Transceiver_1_1fdBuffer.html" title="Buffer type for receiving FastCGI records">fdBuffer</a> <a name="l00117"></a>00117 { <a name="l00119"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1fdBuffer.html#abb4c73e67dceac86c5b4f35d50781bf">00119</a> <a class="code" href="classFastcgipp_1_1Protocol_1_1Header.html" title="Data structure used as the header for FastCGI records.">Protocol::Header</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1fdBuffer.html#abb4c73e67dceac86c5b4f35d50781bf" title="Buffer for header information.">headerBuffer</a>; <a name="l00121"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1fdBuffer.html#a15f4213ca5c0e90ddf167a70ad70cfd">00121</a> <a class="code" href="structFastcgipp_1_1Message.html" title="Data structure used to pass messages within the fastcgi++ task management system...">Message</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1fdBuffer.html#a15f4213ca5c0e90ddf167a70ad70cfd" title="Buffer of complete Message.">messageBuffer</a>; <a name="l00122"></a>00122 }; <a name="l00123"></a>00123 <a name="l00125"></a>00125 <a name="l00135"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html">00135</a> <span class="keyword">class </span><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html" title="Buffer type for transmission of FastCGI records">Buffer</a> <a name="l00136"></a>00136 { <a name="l00138"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html">00138</a> <span class="keyword">struct </span><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html" title="Frame of data associated with a file descriptor">Frame</a> <a name="l00139"></a>00139 { <a name="l00141"></a>00141 <a name="l00146"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#86bc160b0476082381dae9d15476d8dd">00146</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#86bc160b0476082381dae9d15476d8dd" title="Constructor.">Frame</a>(<span class="keywordtype">size_t</span> size_, <span class="keywordtype">bool</span> closeFd_, <a class="code" href="structFastcgipp_1_1Protocol_1_1FullId.html" title="A full ID value for a FastCGI request.">Protocol::FullId</a> id_): <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#e763a750b6b41fc8ef362cbf037af062" title="Size of the frame.">size</a>(size_), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#467f45421401b1e384a2d6e4a24eb0c0" title="Boolean value indication whether or not the file descriptor should be closed when...">closeFd</a>(closeFd_), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#d2947f9ccce71ae2357883cebc4b27ad" title="Complete ID (contains a file descriptor) of associated with the data frame.">id</a>(id_) { } <a name="l00148"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#e763a750b6b41fc8ef362cbf037af062">00148</a> <span class="keywordtype">size_t</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#e763a750b6b41fc8ef362cbf037af062" title="Size of the frame.">size</a>; <a name="l00150"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#467f45421401b1e384a2d6e4a24eb0c0">00150</a> <span class="keywordtype">bool</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#467f45421401b1e384a2d6e4a24eb0c0" title="Boolean value indication whether or not the file descriptor should be closed when...">closeFd</a>; <a name="l00152"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#d2947f9ccce71ae2357883cebc4b27ad">00152</a> <a class="code" href="structFastcgipp_1_1Protocol_1_1FullId.html" title="A full ID value for a FastCGI request.">Protocol::FullId</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Frame.html#d2947f9ccce71ae2357883cebc4b27ad" title="Complete ID (contains a file descriptor) of associated with the data frame.">id</a>; <a name="l00153"></a>00153 }; <a name="l00155"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#638c0333fd0b2f98e705ce3642e9a75b">00155</a> std::queue<Frame> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#638c0333fd0b2f98e705ce3642e9a75b" title="Queue of frames waiting to be transmitted.">frames</a>; <a name="l00157"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#e51b5b8802469636725c594f7a826619">00157</a> <span class="keyword">const</span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#e51b5b8802469636725c594f7a826619" title="Minimum Block size value that can be returned from requestWrite().">minBlockSize</a> = 256; <a name="l00159"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html">00159</a> <span class="keyword">struct </span><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html" title="Chunk of data in Buffer">Chunk</a> <a name="l00160"></a>00160 { <a name="l00162"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#454a1510c92af9c678b5a0f773317259">00162</a> <span class="keyword">const</span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#454a1510c92af9c678b5a0f773317259" title="Size of data section of the chunk.">size</a> = 131072; <a name="l00164"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c">00164</a> boost::shared_array<char> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c" title="Pointer to the first byte in the chunk data.">data</a>; <a name="l00166"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#17d175c5415979ca2a95f6c4ac0180fb">00166</a> <span class="keywordtype">char</span>* <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#17d175c5415979ca2a95f6c4ac0180fb" title="Pointer to the first write byte in the chunk or 1+ the last read byte.">end</a>; <a name="l00168"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#0d19a7134bbb0b3ecbd804e6d767526d">00168</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#0d19a7134bbb0b3ecbd804e6d767526d" title="Creates a new data chunk.">Chunk</a>(): <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c" title="Pointer to the first byte in the chunk data.">data</a>(new char[<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#454a1510c92af9c678b5a0f773317259" title="Size of data section of the chunk.">size</a>]), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#17d175c5415979ca2a95f6c4ac0180fb" title="Pointer to the first write byte in the chunk or 1+ the last read byte.">end</a>(<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c" title="Pointer to the first byte in the chunk data.">data</a>.get()) { } <a name="l00169"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#3ee2c11b5258b15519c9b1edb8c0ef0a">00169</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#3ee2c11b5258b15519c9b1edb8c0ef0a">~Chunk</a>() { } <a name="l00171"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#9db4ad7e1e3dbc18052280f067ad1eed">00171</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#0d19a7134bbb0b3ecbd804e6d767526d" title="Creates a new data chunk.">Chunk</a>(<span class="keyword">const</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html" title="Chunk of data in Buffer">Chunk</a>& chunk): <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c" title="Pointer to the first byte in the chunk data.">data</a>(chunk.<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c" title="Pointer to the first byte in the chunk data.">data</a>), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#17d175c5415979ca2a95f6c4ac0180fb" title="Pointer to the first write byte in the chunk or 1+ the last read byte.">end</a>(<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#215df54ee25b79180371073f9f218e2c" title="Pointer to the first byte in the chunk data.">data</a>.get()) { } <a name="l00172"></a>00172 }; <a name="l00173"></a>00173 <a name="l00175"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#09b6ee7ec4ba7a7872653211ab6c6e6c">00175</a> std::list<Chunk> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#09b6ee7ec4ba7a7872653211ab6c6e6c" title="A list of chunks. Can contain from 2-infinity.">chunks</a>; <a name="l00177"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b">00177</a> std::list<Chunk>::iterator <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b" title="Iterator pointing to the chunk currently used for writing.">writeIt</a>; <a name="l00178"></a>00178 <a name="l00180"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#ff72ebe5b6fb28ad04277d3d37c9456c">00180</a> <span class="keywordtype">char</span>* <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#ff72ebe5b6fb28ad04277d3d37c9456c" title="Current read spot in the buffer.">pRead</a>; <a name="l00181"></a>00181 <a name="l00183"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#5513b34f5f9acbefcf1f85caa69c1b5a">00183</a> std::vector<pollfd>& <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#5513b34f5f9acbefcf1f85caa69c1b5a" title="A reference to Transceiver::pollFds for removing file descriptors when they are closed...">pollFds</a>; <a name="l00185"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#f398abf41d5bd7ca3c9cb1b8aecf5609">00185</a> std::map<int, fdBuffer>& <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#f398abf41d5bd7ca3c9cb1b8aecf5609" title="A reference to Transceiver::fdBuffer for deleting buffers upon closing of the file...">fdBuffers</a>; <a name="l00186"></a>00186 <span class="keyword">public</span>: <a name="l00188"></a>00188 <a name="l00192"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#c518e3a2bef5e5627b30924eeb37c702">00192</a> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#c518e3a2bef5e5627b30924eeb37c702" title="Constructor.">Buffer</a>(std::vector<pollfd>& <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#5513b34f5f9acbefcf1f85caa69c1b5a" title="A reference to Transceiver::pollFds for removing file descriptors when they are closed...">pollFds</a>, std::map<int, fdBuffer>& fdBuffers_): pollFds(pollFds), <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#f398abf41d5bd7ca3c9cb1b8aecf5609" title="A reference to Transceiver::fdBuffer for deleting buffers upon closing of the file...">fdBuffers</a>(fdBuffers_), <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#09b6ee7ec4ba7a7872653211ab6c6e6c" title="A list of chunks. Can contain from 2-infinity.">chunks</a>(1), <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#ff72ebe5b6fb28ad04277d3d37c9456c" title="Current read spot in the buffer.">pRead</a>(<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#09b6ee7ec4ba7a7872653211ab6c6e6c" title="A list of chunks. Can contain from 2-infinity.">chunks</a>.begin()->data.get()), <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b" title="Iterator pointing to the chunk currently used for writing.">writeIt</a>(<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#09b6ee7ec4ba7a7872653211ab6c6e6c" title="A list of chunks. Can contain from 2-infinity.">chunks</a>.begin()) { } <a name="l00193"></a>00193 <a name="l00195"></a>00195 <a name="l00199"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#cf2cce1c96a7138adda98414f4e0d921">00199</a> <a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#cf2cce1c96a7138adda98414f4e0d921" title="Request a write block in the buffer.">requestWrite</a>(<span class="keywordtype">size_t</span> size) <a name="l00200"></a>00200 { <a name="l00201"></a>00201 <span class="keywordflow">return</span> <a class="code" href="structFastcgipp_1_1Block.html" title="A raw block of memory.">Block</a>(<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b" title="Iterator pointing to the chunk currently used for writing.">writeIt</a>->end, std::min(size, (<span class="keywordtype">size_t</span>)(<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b" title="Iterator pointing to the chunk currently used for writing.">writeIt</a>->data.get()+<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1Chunk.html#454a1510c92af9c678b5a0f773317259" title="Size of data section of the chunk.">Chunk::size</a>-<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b" title="Iterator pointing to the chunk currently used for writing.">writeIt</a>->end))); <a name="l00202"></a>00202 } <a name="l00204"></a>00204 <a name="l00209"></a>00209 <span class="keywordtype">void</span> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#a1a80f3feb1355bd5bc57545d16c309e" title="Secure a write in the buffer.">secureWrite</a>(<span class="keywordtype">size_t</span> size, <a class="code" href="structFastcgipp_1_1Protocol_1_1FullId.html" title="A full ID value for a FastCGI request.">Protocol::FullId</a> <span class="keywordtype">id</span>, <span class="keywordtype">bool</span> kill); <a name="l00210"></a>00210 <a name="l00212"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html">00212</a> <span class="keyword">struct </span><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html" title="Block of memory for extraction from Buffer">SendBlock</a> <a name="l00213"></a>00213 { <a name="l00215"></a>00215 <a name="l00220"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#d21c4df63e909b3d5ab23059b9268981">00220</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#d21c4df63e909b3d5ab23059b9268981" title="Constructor.">SendBlock</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* data_, <span class="keywordtype">size_t</span> size_, <span class="keywordtype">int</span> fd_): <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#5253398ffb776cfa9cb1fcac013f597b" title="Pointer to the first byte in the block.">data</a>(data_), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#87860ac5113f48c42d1b73c121b1c0b5" title="Size in bytes of the data.">size</a>(size_), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#892d72ea6a897c2a0f4fa364999ef1c1" title="File descriptor the data should be written to.">fd</a>(fd_) { } <a name="l00222"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#ffab5808ec21d9f6de04cc7b490e39c1">00222</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#d21c4df63e909b3d5ab23059b9268981" title="Constructor.">SendBlock</a>(<span class="keyword">const</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html" title="Block of memory for extraction from Buffer">SendBlock</a>& sendBlock): <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#5253398ffb776cfa9cb1fcac013f597b" title="Pointer to the first byte in the block.">data</a>(sendBlock.<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#5253398ffb776cfa9cb1fcac013f597b" title="Pointer to the first byte in the block.">data</a>), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#87860ac5113f48c42d1b73c121b1c0b5" title="Size in bytes of the data.">size</a>(sendBlock.<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#87860ac5113f48c42d1b73c121b1c0b5" title="Size in bytes of the data.">size</a>), <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#892d72ea6a897c2a0f4fa364999ef1c1" title="File descriptor the data should be written to.">fd</a>(sendBlock.<a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#892d72ea6a897c2a0f4fa364999ef1c1" title="File descriptor the data should be written to.">fd</a>) { } <a name="l00224"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#5253398ffb776cfa9cb1fcac013f597b">00224</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#5253398ffb776cfa9cb1fcac013f597b" title="Pointer to the first byte in the block.">data</a>; <a name="l00226"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#87860ac5113f48c42d1b73c121b1c0b5">00226</a> <span class="keywordtype">size_t</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#87860ac5113f48c42d1b73c121b1c0b5" title="Size in bytes of the data.">size</a>; <a name="l00228"></a><a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#892d72ea6a897c2a0f4fa364999ef1c1">00228</a> <span class="keywordtype">int</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html#892d72ea6a897c2a0f4fa364999ef1c1" title="File descriptor the data should be written to.">fd</a>; <a name="l00229"></a>00229 }; <a name="l00230"></a>00230 <a name="l00232"></a>00232 <a name="l00235"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#c017d6e4d7b8552a8c637da676ce7402">00235</a> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html" title="Block of memory for extraction from Buffer">SendBlock</a> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#c017d6e4d7b8552a8c637da676ce7402" title="Request a block of data for transmitting.">requestRead</a>() <a name="l00236"></a>00236 { <a name="l00237"></a>00237 <span class="keywordflow">return</span> <a class="code" href="structFastcgipp_1_1Transceiver_1_1Buffer_1_1SendBlock.html" title="Block of memory for extraction from Buffer">SendBlock</a>(<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#ff72ebe5b6fb28ad04277d3d37c9456c" title="Current read spot in the buffer.">pRead</a>, <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#638c0333fd0b2f98e705ce3642e9a75b" title="Queue of frames waiting to be transmitted.">frames</a>.empty()?0:<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#638c0333fd0b2f98e705ce3642e9a75b" title="Queue of frames waiting to be transmitted.">frames</a>.front().size, <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#638c0333fd0b2f98e705ce3642e9a75b" title="Queue of frames waiting to be transmitted.">frames</a>.empty()?-1:<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#638c0333fd0b2f98e705ce3642e9a75b" title="Queue of frames waiting to be transmitted.">frames</a>.front().id.fd); <a name="l00238"></a>00238 } <a name="l00240"></a>00240 <a name="l00243"></a>00243 <span class="keywordtype">void</span> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#ca9630cbe4c0c08d009fbeed5bd85e92" title="Mark data in the buffer as transmitted and free it&#39;s memory.">freeRead</a>(<span class="keywordtype">size_t</span> size); <a name="l00244"></a>00244 <a name="l00246"></a>00246 <a name="l00249"></a><a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#f3f403dd53cad518f8cc12d03ac67bd2">00249</a> <span class="keywordtype">bool</span> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#f3f403dd53cad518f8cc12d03ac67bd2" title="Test of the buffer is empty.">empty</a>() <a name="l00250"></a>00250 { <a name="l00251"></a>00251 <span class="keywordflow">return</span> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#ff72ebe5b6fb28ad04277d3d37c9456c" title="Current read spot in the buffer.">pRead</a>==<a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html#49fed2468b7b77194943f2b3ece6e12b" title="Iterator pointing to the chunk currently used for writing.">writeIt</a>->end; <a name="l00252"></a>00252 } <a name="l00253"></a>00253 }; <a name="l00254"></a>00254 <a name="l00256"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#8656d4bd7359d7e12a9cc5921fc3a1d4">00256</a> <a class="code" href="classFastcgipp_1_1Transceiver_1_1Buffer.html" title="Buffer type for transmission of FastCGI records">Buffer</a> <a class="code" href="classFastcgipp_1_1Transceiver.html#8656d4bd7359d7e12a9cc5921fc3a1d4" title="Buffer for transmitting data">buffer</a>; <a name="l00258"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#cc1090414ba4805db330e09a3f26178e">00258</a> boost::function<void(Protocol::FullId, Message)> <a class="code" href="classFastcgipp_1_1Transceiver.html#cc1090414ba4805db330e09a3f26178e" title="Function to call to pass messages to requests.">sendMessage</a>; <a name="l00259"></a>00259 <a name="l00261"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#4b163da2ea08d648a34f9903b86d82fe">00261</a> std::vector<pollfd> <a class="code" href="classFastcgipp_1_1Transceiver.html#4b163da2ea08d648a34f9903b86d82fe" title="poll() file descriptors container">pollFds</a>; <a name="l00263"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#19c7caeb43236b6c68f38d04e4bfca33">00263</a> <span class="keywordtype">int</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#19c7caeb43236b6c68f38d04e4bfca33" title="Socket to listen for connections on.">socket</a>; <a name="l00265"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#7b7f39053271cd4afd41b4672d7eeec4">00265</a> <span class="keywordtype">int</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#7b7f39053271cd4afd41b4672d7eeec4" title="Input file descriptor to the wakeup socket pair.">wakeUpFdIn</a>; <a name="l00267"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#ba0fbaf4469c1c7e36d75a4faade3b7e">00267</a> <span class="keywordtype">int</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#ba0fbaf4469c1c7e36d75a4faade3b7e" title="Output file descriptor to the wakeup socket pair.">wakeUpFdOut</a>; <a name="l00268"></a>00268 <a name="l00270"></a><a class="code" href="classFastcgipp_1_1Transceiver.html#28c9ac40d0fe11414bc86ad2b8ce4953">00270</a> std::map<int, fdBuffer> <a class="code" href="classFastcgipp_1_1Transceiver.html#28c9ac40d0fe11414bc86ad2b8ce4953" title="Container associating file descriptors with their receive buffers.">fdBuffers</a>; <a name="l00271"></a>00271 <a name="l00273"></a>00273 <span class="keywordtype">int</span> <a class="code" href="classFastcgipp_1_1Transceiver.html#54ffa1d25fed65ff61024ff8ce26a99b" title="Transmit all buffered data possible.">transmit</a>(); <a name="l00274"></a>00274 }; <a name="l00275"></a>00275 <a name="l00277"></a><a class="code" href="structFastcgipp_1_1equalsFd.html">00277</a> <span class="keyword">struct </span><a class="code" href="structFastcgipp_1_1equalsFd.html" title="Predicate for comparing the file descriptor of a pollfd.">equalsFd</a> : <span class="keyword">public</span> std::unary_function<pollfd, bool> <a name="l00278"></a>00278 { <a name="l00279"></a><a class="code" href="structFastcgipp_1_1equalsFd.html#03c4e66a736eb9b1cebed2a83e15a637">00279</a> <span class="keywordtype">int</span> <a class="code" href="structFastcgipp_1_1equalsFd.html#03c4e66a736eb9b1cebed2a83e15a637">fd</a>; <a name="l00280"></a><a class="code" href="structFastcgipp_1_1equalsFd.html#848f55ab00a5feedf1988c7ccc180be3">00280</a> <span class="keyword">explicit</span> <a class="code" href="structFastcgipp_1_1equalsFd.html#848f55ab00a5feedf1988c7ccc180be3">equalsFd</a>(<span class="keywordtype">int</span> fd_): <a class="code" href="structFastcgipp_1_1equalsFd.html#03c4e66a736eb9b1cebed2a83e15a637">fd</a>(fd_) {} <a name="l00281"></a><a class="code" href="structFastcgipp_1_1equalsFd.html#f6c0071d8f8aca29c9c94deda3a064e8">00281</a> <span class="keywordtype">bool</span> <a class="code" href="structFastcgipp_1_1equalsFd.html#f6c0071d8f8aca29c9c94deda3a064e8">operator()</a>(<span class="keyword">const</span> pollfd& x)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> x.fd==<a class="code" href="structFastcgipp_1_1equalsFd.html#03c4e66a736eb9b1cebed2a83e15a637">fd</a>; }; <a name="l00282"></a>00282 }; <a name="l00283"></a>00283 <a name="l00285"></a><a class="code" href="namespaceFastcgipp.html#b81025146f21643e6e765612d5d57462">00285</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceFastcgipp.html#b81025146f21643e6e765612d5d57462" title="Predicate for testing if the revents in a pollfd is non-zero.">reventsZero</a>(<span class="keyword">const</span> pollfd& x) <a name="l00286"></a>00286 { <a name="l00287"></a>00287 <span class="keywordflow">return</span> x.revents; <a name="l00288"></a>00288 } <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="preprocessor">#endif</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Tue Sep 16 15:17:47 2008 for fastcgi++ by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>