Click here to Skip to main content
12,356,052 members (72,249 online)
Click here to Skip to main content

Stats

1.7M views
7.4K downloads
325 bookmarked
Posted

RCF - Interprocess Communication for C++

, 25 Oct 2011 CPOL
A server/client IPC framework, using the C++ preprocessor as an IDL compiler.
RCF-0.4
demo
vs2003
RCF
Client
Server
doc
html
class_r_c_f_1_1_exception.png
class_r_c_f_1_1_filter.png
class_r_c_f_1_1_filter_factory.png
class_r_c_f_1_1_filter_service.png
class_r_c_f_1_1_identity_filter.png
class_r_c_f_1_1_identity_filter_factory.png
class_r_c_f_1_1_i___client_transport.png
class_r_c_f_1_1_i___endpoint.png
class_r_c_f_1_1_i___service.png
class_r_c_f_1_1_i___session_manager.png
class_r_c_f_1_1_multicast_client_transport.png
class_r_c_f_1_1_object_factory_service.png
class_r_c_f_1_1_open_ssl_encryption_filter.png
class_r_c_f_1_1_open_ssl_encryption_filter_factory.png
class_r_c_f_1_1_publishing_service.png
class_r_c_f_1_1_rcf_server.png
class_r_c_f_1_1_remote_exception.png
class_r_c_f_1_1_subscription_service.png
class_r_c_f_1_1_tcp_endpoint.png
class_r_c_f_1_1_udp_endpoint.png
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.png
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.png
doxygen.png
ftv2blank.png
ftv2doc.png
ftv2folderclosed.png
ftv2folderopen.png
ftv2lastnode.png
ftv2link.png
ftv2mlastnode.png
ftv2mnode.png
ftv2node.png
ftv2plastnode.png
ftv2pnode.png
ftv2vertline.png
tab_b.gif
tab_l.gif
tab_r.gif
latex
annotated.tex
class_r_c_f_1_1_client_stub.tex
class_r_c_f_1_1_exception.eps
class_r_c_f_1_1_exception.tex
class_r_c_f_1_1_filter.eps
class_r_c_f_1_1_filter.tex
class_r_c_f_1_1_filter_description.tex
class_r_c_f_1_1_filter_factory.eps
class_r_c_f_1_1_filter_factory.tex
class_r_c_f_1_1_filter_service.eps
class_r_c_f_1_1_filter_service.tex
class_r_c_f_1_1_identity_filter.eps
class_r_c_f_1_1_identity_filter.tex
class_r_c_f_1_1_identity_filter_factory.eps
class_r_c_f_1_1_identity_filter_factory.tex
class_r_c_f_1_1_i___client_transport.eps
class_r_c_f_1_1_i___client_transport.tex
class_r_c_f_1_1_i___endpoint.eps
class_r_c_f_1_1_i___endpoint.tex
class_r_c_f_1_1_i___proactor.tex
class_r_c_f_1_1_i___rcf_client.tex
class_r_c_f_1_1_i___server_transport.tex
class_r_c_f_1_1_i___server_transport_ex.tex
class_r_c_f_1_1_i___service.eps
class_r_c_f_1_1_i___service.tex
class_r_c_f_1_1_i___session.tex
class_r_c_f_1_1_i___session_manager.eps
class_r_c_f_1_1_i___session_manager.tex
class_r_c_f_1_1_multicast_client_transport.eps
class_r_c_f_1_1_multicast_client_transport.tex
class_r_c_f_1_1_object_factory_service.eps
class_r_c_f_1_1_object_factory_service.tex
class_r_c_f_1_1_open_ssl_encryption_filter.eps
class_r_c_f_1_1_open_ssl_encryption_filter.tex
class_r_c_f_1_1_open_ssl_encryption_filter_factory.eps
class_r_c_f_1_1_open_ssl_encryption_filter_factory.tex
class_r_c_f_1_1_publishing_service.eps
class_r_c_f_1_1_publishing_service.tex
class_r_c_f_1_1_rcf_server.eps
class_r_c_f_1_1_rcf_server.tex
class_r_c_f_1_1_remote_exception.eps
class_r_c_f_1_1_remote_exception.tex
class_r_c_f_1_1_subscription_service.eps
class_r_c_f_1_1_subscription_service.tex
class_r_c_f_1_1_tcp_endpoint.eps
class_r_c_f_1_1_tcp_endpoint.tex
class_r_c_f_1_1_udp_endpoint.eps
class_r_c_f_1_1_udp_endpoint.tex
class_r_c_f_1_1_zlib_stateful_compression_filter.tex
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.eps
class_r_c_f_1_1_zlib_stateful_compression_filter_factory.tex
class_r_c_f_1_1_zlib_stateless_compression_filter.tex
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.eps
class_r_c_f_1_1_zlib_stateless_compression_filter_factory.tex
dirs.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2F.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2F.tex
dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2FProtocol_2F.tex
doxygen.sty
Helvetica.ttf
hierarchy.tex
Makefile
refman.tex
struct_r_c_f_1_1_filter_id_comparison.tex
include
RCF
Marshal.inl
Protocol
RcfServer.inl
ServerStub.inl
test
util
Platform
Machine
SPARC
x86
OS
Unix
Windows
Threads
SF
src
RCF
Protocol
SF
test
borland
Jamfile
Jamrules
Jamfile
Jamrules
vs2003
RCF
RCF
RCFTest
client.pem
server.pem
RCF-0.9c
demo
vs2003
RCF
Client
Server
include
RCF
Marshal.inl
Protocol
RcfServer.inl
ServerStub.inl
test
util
Platform
Machine
SPARC
x86
OS
Unix
Windows
Threads
SF
src
RCF
Protocol
util
SF
test
bcc
Jamfile
Jamrules
data
caCertA.pem
caCertB.pem
certA.pem
certB.pem
ssCert1.pem
ssCert2.pem
Jamfile
Jamrules
vc6
Jamfile
Jamrules
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>RCF: TcpIocpServerTransport.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.4.5 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="dirs.html"><span>Directories</span></a></li>
  </ul></div>
<div class="nav">
<a class="el" href="dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2F.html">include</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2F.html">RCF</a></div>
<h1>TcpIocpServerTransport.hpp</h1><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">// RCF - Remote Call Framework</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (c) 2005. All rights reserved.</span>
<a name="l00005"></a>00005 <span class="comment">// Developed by Jarl Lindrud.</span>
<a name="l00006"></a>00006 <span class="comment">// Contact: jlindrud@hotmail.com .</span>
<a name="l00007"></a>00007 <span class="comment">//*****************************************************************************</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="preprocessor">#ifndef INCLUDE_RCF_TCPIOCPSERVERTRANSPORT_HPP</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="preprocessor">#define INCLUDE_RCF_TCPIOCPSERVERTRANSPORT_HPP</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;memory&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;boost/noncopyable.hpp&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;boost/shared_ptr.hpp&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;boost/weak_ptr.hpp&gt;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;RCF/AsyncFilter.hpp&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;RCF/IpAddress.hpp&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;RCF/IpServerTransport.hpp&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;RCF/ServerTask.hpp&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;RCF/ServerTransport.hpp&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;RCF/Service.hpp&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;RCF/ThreadLibrary.hpp&gt;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">namespace </span>RCF {
<a name="l00029"></a>00029 
<a name="l00030"></a>00030     <span class="keyword">class </span>RcfServer;
<a name="l00031"></a>00031 
<a name="l00032"></a>00032     <span class="keyword">class </span>Iocp
<a name="l00033"></a>00033     {
<a name="l00034"></a>00034     <span class="keyword">public</span>:
<a name="l00035"></a>00035         Iocp(<span class="keywordtype">int</span> nMaxConcurrency = -1);
<a name="l00036"></a>00036         ~Iocp();
<a name="l00037"></a>00037         BOOL Create(<span class="keywordtype">int</span> nMaxConcurrency = 0);
<a name="l00038"></a>00038         BOOL AssociateDevice(HANDLE hDevice, ULONG_PTR CompKey);
<a name="l00039"></a>00039         BOOL AssociateSocket(SOCKET hSocket, ULONG_PTR CompKey);
<a name="l00040"></a>00040         BOOL PostStatus(ULONG_PTR CompKey, DWORD dwNumBytes = 0, OVERLAPPED* po = NULL) ;
<a name="l00041"></a>00041         BOOL GetStatus(ULONG_PTR* pCompKey, PDWORD pdwNumBytes, OVERLAPPED** ppo, DWORD dwMilliseconds = INFINITE);
<a name="l00042"></a>00042 
<a name="l00043"></a>00043     <span class="keyword">private</span>:
<a name="l00044"></a>00044         HANDLE m_hIOCP;
<a name="l00045"></a>00045     };
<a name="l00046"></a>00046 
<a name="l00047"></a>00047     <span class="keyword">class </span>WsaRecvFunctor
<a name="l00048"></a>00048     {
<a name="l00049"></a>00049     <span class="keyword">public</span>:
<a name="l00050"></a>00050         WsaRecvFunctor(WSAOVERLAPPED *pOverlapped, <span class="keyword">const</span> <span class="keywordtype">int</span> &amp;fd, <span class="keyword">const</span> <span class="keywordtype">bool</span> &amp;zombie,  ReadWriteMutex &amp;rwm);
<a name="l00051"></a>00051         <span class="keywordtype">void</span> operator()(<span class="keywordtype">char</span> *buffer, std::size_t bufferLen);
<a name="l00052"></a>00052         Filter::ReadFunction getReadFunction();
<a name="l00053"></a>00053         <span class="keywordtype">int</span> getError();
<a name="l00054"></a>00054 
<a name="l00055"></a>00055     <span class="keyword">private</span>:
<a name="l00056"></a>00056         <span class="keyword">const</span> <span class="keywordtype">int</span> &amp;fd;
<a name="l00057"></a>00057         <span class="keyword">const</span> <span class="keywordtype">bool</span> &amp;zombie;
<a name="l00058"></a>00058         ReadWriteMutex &amp;rwm;
<a name="l00059"></a>00059         WSAOVERLAPPED *mpOverlapped;
<a name="l00060"></a>00060         <span class="keywordtype">int</span> mError;
<a name="l00061"></a>00061     };
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     <span class="keyword">class </span>WsaSendFunctor
<a name="l00064"></a>00064     {
<a name="l00065"></a>00065     <span class="keyword">public</span>:
<a name="l00066"></a>00066         WsaSendFunctor(WSAOVERLAPPED *pOverlapped, <span class="keyword">const</span> <span class="keywordtype">int</span> &amp;fd, <span class="keyword">const</span> <span class="keywordtype">bool</span> &amp;zombie, ReadWriteMutex &amp;rwm);
<a name="l00067"></a>00067         <span class="keywordtype">void</span> operator()(<span class="keyword">const</span> <span class="keywordtype">char</span> *buffer, std::size_t bufferLen);
<a name="l00068"></a>00068         Filter::WriteFunction getWriteFunction();
<a name="l00069"></a>00069         <span class="keywordtype">int</span> getError();
<a name="l00070"></a>00070 
<a name="l00071"></a>00071     <span class="keyword">private</span>:
<a name="l00072"></a>00072         <span class="keyword">const</span> <span class="keywordtype">int</span> &amp;fd;
<a name="l00073"></a>00073         <span class="keyword">const</span> <span class="keywordtype">bool</span> &amp;zombie;
<a name="l00074"></a>00074         ReadWriteMutex &amp;rwm;
<a name="l00075"></a>00075         WSAOVERLAPPED *mpOverlapped;
<a name="l00076"></a>00076         <span class="keywordtype">int</span> mError;
<a name="l00077"></a>00077     };
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <span class="comment">// Synchronization -</span>
<a name="l00080"></a>00080     <span class="comment">// SessionState::fd is immutable, and is only physically closed (closesocket()) from the SessionState destructor, which is thread-safe</span>
<a name="l00081"></a>00081     <span class="comment">// since we only refer to SessionState object's through shared_ptr's. Any thread wishing to close a session must set the </span>
<a name="l00082"></a>00082     <span class="comment">// SessionState::zombie flag. Eventually the SessionState will be ejected from the server by a server thread, and the destructor will close the connection.</span>
<a name="l00083"></a>00083     <span class="comment">// Ownership of the fd can be taken from the SessionState, by setting ownFd to false. The server-wide read_write_mutex rwm is used to </span>
<a name="l00084"></a>00084     <span class="comment">// synchronize reads and writes of ownFd and zombie for all SessionState objects.</span>
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     <span class="comment">// SessionState's with set zombie flags cannot be summarily removed from the servers session map, since that might delete the SessionState object</span>
<a name="l00087"></a>00087     <span class="comment">// while the iocp is polling it, =&gt; core dump. They can only be safely removed when it is known that the iocp is not polling them.</span>
<a name="l00088"></a>00088 
<a name="l00089"></a>00089     <span class="keyword">class </span>TcpIocpServerTransport;
<a name="l00090"></a>00090     
<a name="l00091"></a>00091     <span class="keyword">typedef</span> boost::shared_ptr&lt;TcpIocpServerTransport&gt; TcpIocpServerTransportPtr;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     <span class="keyword">class </span>TcpIocpServerTransport : 
<a name="l00094"></a>00094         <span class="keyword">public</span> I_ServerTransport, 
<a name="l00095"></a>00095         <span class="keyword">public</span> I_ServerTransportEx, 
<a name="l00096"></a>00096         <span class="keyword">public</span> I_IpServerTransport,
<a name="l00097"></a>00097         <span class="keyword">public</span> I_Service,
<a name="l00098"></a>00098         boost::noncopyable
<a name="l00099"></a>00099     {
<a name="l00100"></a>00100     <span class="keyword">private</span>:
<a name="l00101"></a>00101         <span class="keyword">typedef</span> <span class="keywordtype">int</span> Fd;
<a name="l00102"></a>00102         <span class="keyword">typedef</span> boost::shared_ptr&lt;I_Session&gt; SessionPtr; <span class="comment">//NB: not the same as RCF::SessionPtr!</span>
<a name="l00103"></a>00103         <span class="keyword">class </span>SessionState;
<a name="l00104"></a>00104         <span class="keyword">typedef</span> boost::shared_ptr&lt;SessionState&gt; SessionStatePtr;
<a name="l00105"></a>00105         <span class="keyword">typedef</span> boost::weak_ptr&lt;SessionState&gt; SessionStateWeakPtr;
<a name="l00106"></a>00106 
<a name="l00107"></a>00107         <span class="keyword">class </span>SessionState : <span class="keyword">public</span> OVERLAPPED
<a name="l00108"></a>00108         {
<a name="l00109"></a>00109         <span class="keyword">public</span>:
<a name="l00110"></a>00110 
<a name="l00111"></a>00111             <span class="keyword">enum</span> State {
<a name="l00112"></a>00112                 Accepting,
<a name="l00113"></a>00113                 ReadingDataCount,
<a name="l00114"></a>00114                 ReadingData,
<a name="l00115"></a>00115                 WritingData,
<a name="l00116"></a>00116                 Ready
<a name="l00117"></a>00117             };
<a name="l00118"></a>00118 
<a name="l00119"></a>00119             SessionState(TcpIocpServerTransport &amp;transport, Fd fd);
<a name="l00120"></a>00120             ~SessionState();
<a name="l00121"></a>00121             <span class="keywordtype">void</span> setTransportFilters(<span class="keyword">const</span> std::vector&lt;FilterPtr&gt; &amp;filters);
<a name="l00122"></a>00122             <span class="keywordtype">void</span> clearOverlapped();
<a name="l00123"></a>00123             <span class="keywordtype">bool</span> isReflecting();
<a name="l00124"></a>00124             <span class="keyword">const</span> I_RemoteAddress &amp;getRemoteAddress();
<a name="l00125"></a>00125             sockaddr_in getRemoteSockAddr() { <span class="keywordflow">return</span> remoteAddress.getSockAddr(); }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127             Fd getFd() <span class="keyword">const</span>;
<a name="l00128"></a>00128             <span class="keywordtype">void</span> setLocalAddress(<span class="keyword">const</span> IpAddress &amp;ipAddress) { localAddress = ipAddress; }
<a name="l00129"></a>00129             IpAddress getLocalAddress()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> localAddress; }
<a name="l00130"></a>00130             <span class="keywordtype">void</span> setRemoteAddress(<span class="keyword">const</span> IpAddress &amp;ipAddress) { remoteAddress = ipAddress; }
<a name="l00131"></a>00131             std::vector&lt;char&gt; &amp;getReadBuffer() { <span class="keywordflow">return</span> readBuffer; }
<a name="l00132"></a>00132             std::size_t getReadBufferRemaining()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> readBufferRemaining; }
<a name="l00133"></a>00133             <span class="keywordtype">void</span> setReadBufferRemaining(std::size_t readBufferRemaining) { this-&gt;readBufferRemaining = readBufferRemaining; }
<a name="l00134"></a>00134             std::vector&lt;char&gt; &amp;getWriteBuffer() { <span class="keywordflow">return</span> writeBuffer; }
<a name="l00135"></a>00135             std::size_t getWriteBufferRemaining()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> writeBufferRemaining; }
<a name="l00136"></a>00136             <span class="keywordtype">void</span> setWriteBufferRemaining(std::size_t writeBufferRemaining) { this-&gt;writeBufferRemaining = writeBufferRemaining; }
<a name="l00137"></a>00137             State getState()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> state; }
<a name="l00138"></a>00138             <span class="keywordtype">void</span> setState(State state) { this-&gt;state = state; }
<a name="l00139"></a>00139             SessionPtr getSessionPtr()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sessionPtr; }
<a name="l00140"></a>00140             <span class="keywordtype">void</span> setSessionPtr(SessionPtr sessionPtr) { this-&gt;sessionPtr = sessionPtr; }
<a name="l00141"></a>00141             <span class="keywordtype">void</span> setWeakThisPtr(SessionStateWeakPtr sessionStateWeakPtr) { this-&gt;weakThisPtr = sessionStateWeakPtr; }
<a name="l00142"></a>00142             SessionStateWeakPtr getWeakThisPtr()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> weakThisPtr; }
<a name="l00143"></a>00143             Fd getReflectionFd()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> reflectionFd; }
<a name="l00144"></a>00144             <span class="keywordtype">void</span> setReflectionFd(Fd reflectionFd) { this-&gt;reflectionFd = reflectionFd; }
<a name="l00145"></a>00145             SessionStateWeakPtr getReflectionSessionStateWeakPtr()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> reflectionSessionStateWeakPtr; }
<a name="l00146"></a>00146             <span class="keywordtype">void</span> setReflectionSessionStateWeakPtr(SessionStateWeakPtr sessionStateWeakPtr) { this-&gt;reflectionSessionStateWeakPtr = sessionStateWeakPtr; }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148             <span class="keywordtype">int</span> read(<span class="keywordtype">char</span> *buffer, std::size_t bufferLen);
<a name="l00149"></a>00149             <span class="keywordtype">int</span> write(<span class="keywordtype">char</span> *buffer, std::size_t bufferLen);
<a name="l00150"></a>00150             <span class="keywordtype">void</span> onReadWriteCompleted(std::size_t bytesTransferred, <span class="keywordtype">int</span> error);
<a name="l00151"></a>00151 
<a name="l00152"></a>00152             <span class="keywordtype">bool</span> ownFd; <span class="comment">// synchronized through rwm</span>
<a name="l00153"></a>00153             <span class="keywordtype">bool</span> zombie; <span class="comment">// synchronized through rwm</span>
<a name="l00154"></a>00154 
<a name="l00155"></a>00155         <span class="keyword">private</span>:
<a name="l00156"></a>00156 
<a name="l00157"></a>00157             <span class="comment">// data structures for reflecting. NB: not synchronized!</span>
<a name="l00158"></a>00158             <span class="keywordtype">int</span> reflectionFd;
<a name="l00159"></a>00159             SessionStateWeakPtr reflectionSessionStateWeakPtr;
<a name="l00160"></a>00160 
<a name="l00161"></a>00161             State state;
<a name="l00162"></a>00162             SessionPtr sessionPtr;
<a name="l00163"></a>00163             std::vector&lt;char&gt; readBuffer;
<a name="l00164"></a>00164             std::size_t readBufferRemaining;
<a name="l00165"></a>00165             std::vector&lt;char&gt; writeBuffer;
<a name="l00166"></a>00166             std::size_t writeBufferRemaining;
<a name="l00167"></a>00167             <span class="keyword">const</span> Fd fd;
<a name="l00168"></a>00168             SessionStateWeakPtr weakThisPtr;
<a name="l00169"></a>00169             std::vector&lt;FilterPtr&gt; mTransportFilters;
<a name="l00170"></a>00170             WsaRecvFunctor wsaRecvFunctor;
<a name="l00171"></a>00171             WsaSendFunctor wsaSendFunctor;
<a name="l00172"></a>00172             TcpIocpServerTransport &amp;transport;
<a name="l00173"></a>00173             IpAddress localAddress;
<a name="l00174"></a>00174             IpAddress remoteAddress;
<a name="l00175"></a>00175         };
<a name="l00176"></a>00176 
<a name="l00177"></a>00177         <span class="keyword">friend</span> <span class="keyword">class </span>TcpIocpServerTransport::SessionState;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         <span class="keyword">class </span>TcpIocpProactor : <span class="keyword">public</span> I_Proactor
<a name="l00180"></a>00180         {
<a name="l00181"></a>00181         <span class="keyword">public</span>:
<a name="l00182"></a>00182             TcpIocpProactor(TcpIocpServerTransport &amp;transport, boost::shared_ptr&lt;SessionState&gt; sessionStatePtr);
<a name="l00183"></a>00183             <span class="keywordtype">void</span> postRead();
<a name="l00184"></a>00184             <span class="keywordtype">void</span> postWrite();
<a name="l00185"></a>00185             <span class="keywordtype">void</span> postClose();
<a name="l00186"></a>00186             std::vector&lt;char&gt; &amp;getWriteBuffer();
<a name="l00187"></a>00187             std::size_t getWriteOffset();
<a name="l00188"></a>00188             std::vector&lt;char&gt; &amp;getReadBuffer();
<a name="l00189"></a>00189             std::size_t getReadOffset();
<a name="l00190"></a>00190             I_ServerTransport &amp;getServerTransport();
<a name="l00191"></a>00191             SessionState &amp;getSessionState();
<a name="l00192"></a>00192             SessionStatePtr getSessionStatePtr();
<a name="l00193"></a>00193             <span class="keyword">const</span> I_RemoteAddress &amp;getRemoteAddress();
<a name="l00194"></a>00194             <span class="keywordtype">void</span> setTransportFilters(<span class="keyword">const</span> std::vector&lt;FilterPtr&gt; &amp;filters);
<a name="l00195"></a>00195         <span class="keyword">private</span>:
<a name="l00196"></a>00196             TcpIocpServerTransport &amp;transport;
<a name="l00197"></a>00197             boost::weak_ptr&lt;SessionState&gt; sessionStatePtr; <span class="comment">// using a shared_ptr here would make a cycle SessionState-&gt;Session-&gt;Proactor-&gt;SessionState</span>
<a name="l00198"></a>00198         };
<a name="l00199"></a>00199 
<a name="l00200"></a>00200         <span class="keyword">friend</span> <span class="keyword">class </span>TcpIocpServerTransport::TcpIocpProactor;
<a name="l00201"></a>00201     
<a name="l00202"></a>00202     <span class="keyword">public</span>:
<a name="l00203"></a>00203         TcpIocpServerTransport(<span class="keywordtype">int</span> port = 0);
<a name="l00204"></a>00204         ServerTransportPtr clone() { <span class="keywordflow">return</span> ServerTransportPtr( <span class="keyword">new</span> TcpIocpServerTransport(port) ); }
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     <span class="keyword">public</span>:
<a name="l00207"></a>00207         <span class="keywordtype">void</span> open();
<a name="l00208"></a>00208         <span class="keywordtype">void</span> close();
<a name="l00209"></a>00209         <span class="keywordtype">void</span> cycle(<span class="keywordtype">int</span> timeoutMs, <span class="keyword">const</span> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> &amp;stopFlag);
<a name="l00210"></a>00210         <span class="keywordtype">bool</span> cycleTransportAndServer(RcfServer &amp;server, <span class="keywordtype">int</span> timeoutMs, <span class="keyword">const</span> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> &amp;stopFlag);
<a name="l00211"></a>00211 
<a name="l00212"></a>00212         <span class="keywordtype">void</span> setPort(<span class="keywordtype">int</span> port);
<a name="l00213"></a>00213         <span class="keywordtype">int</span> getPort();
<a name="l00214"></a>00214         
<a name="l00215"></a>00215         <span class="keywordtype">void</span> setMaxPendingConnectionCount(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> maxPendingConnectionCount);
<a name="l00216"></a>00216         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> getMaxPendingConnectionCount();
<a name="l00217"></a>00217 
<a name="l00218"></a>00218         <span class="keywordtype">void</span> setSessionManager(I_SessionManager &amp;sessionManager);
<a name="l00219"></a>00219         I_SessionManager &amp;getSessionManager();
<a name="l00220"></a>00220  
<a name="l00221"></a>00221     <span class="keyword">private</span>:
<a name="l00222"></a>00222         Fd hash(Fd fd);
<a name="l00223"></a>00223         SessionStatePtr createSession(<span class="keywordtype">int</span> fd);
<a name="l00224"></a>00224         <span class="keywordtype">bool</span> monitorSession(SessionStatePtr sessionStatePtr);
<a name="l00225"></a>00225         <span class="keywordtype">bool</span> unmonitorSession(SessionStatePtr sessionStatePtr);
<a name="l00226"></a>00226         <span class="keywordtype">void</span> closeSession(SessionStatePtr sessionStatePtr);
<a name="l00227"></a>00227         <span class="keywordtype">void</span> transition(SessionStatePtr sessionStatePtr);
<a name="l00228"></a>00228         <span class="keywordtype">void</span> reflectSession(SessionStatePtr sessionStatePtr, DWORD bytesRead, ULONG_PTR completionKey);
<a name="l00229"></a>00229         <span class="keywordtype">bool</span> isReflecting(SessionStatePtr sessionStatePtr);
<a name="l00230"></a>00230         <span class="keywordtype">void</span> stopAccepts();
<a name="l00231"></a>00231         <span class="keywordtype">bool</span> cycleAccepts(<span class="keywordtype">int</span> timeoutMs, <span class="keyword">const</span> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> &amp;stopFlag);
<a name="l00232"></a>00232         <span class="keywordtype">void</span> generateAccepts();
<a name="l00233"></a>00233         
<a name="l00234"></a>00234         <span class="keywordtype">void</span> onReadWriteCompleted(SessionStatePtr sessionStatePtr, std::size_t bytesTransferred, <span class="keywordtype">int</span> error);
<a name="l00235"></a>00235         <span class="keywordtype">void</span> onAcceptCompleted(SessionStatePtr sessionStatePtr);
<a name="l00236"></a>00236         <span class="comment">//Filter::ReadWriteCompletionCallback getReadWriteCompletionCallback();</span>
<a name="l00237"></a>00237         <span class="keywordtype">void</span> postWrite(SessionStatePtr sessionStatePtr);
<a name="l00238"></a>00238         <span class="keywordtype">void</span> postRead(SessionStatePtr sessionStatePtr);
<a name="l00239"></a>00239         SessionStatePtr getSessionStatePtr(Fd fd);
<a name="l00240"></a>00240 
<a name="l00241"></a>00241         <span class="comment">// I_ServerTransportEx implementation</span>
<a name="l00242"></a>00242     <span class="keyword">private</span>:
<a name="l00243"></a>00243         <span class="keywordtype">void</span> externalCloseSession(SessionStatePtr sessionStatePtr);
<a name="l00244"></a>00244         <span class="keywordtype">void</span> externalCloseSession(SessionStatePtr sessionStatePtr, <span class="keywordtype">int</span> &amp;fd);
<a name="l00245"></a>00245         <span class="keywordtype">void</span> externalCloseSession0(SessionStatePtr sessionStatePtr, <span class="keywordtype">int</span> &amp;fd);
<a name="l00246"></a>00246         std::auto_ptr&lt;I_ClientTransport&gt; createClientTransport(<span class="keyword">const</span> I_Endpoint &amp;endpoint);
<a name="l00247"></a>00247         ClientTransportAutoPtr createClientTransport(boost::shared_ptr&lt;I_Session&gt; sessionPtr);
<a name="l00248"></a>00248         boost::shared_ptr&lt;I_Session&gt; createServerSession(ClientTransportAutoPtr clientTransportAutoPtr);
<a name="l00249"></a>00249         <span class="keywordtype">bool</span> reflect(boost::shared_ptr&lt;I_Session&gt; sessionPtr1, boost::shared_ptr&lt;I_Session&gt; sessionPtr2);
<a name="l00250"></a>00250         <span class="keywordtype">bool</span> reflect(SessionStatePtr sessionStatePtr1, SessionStatePtr sessionStatePtr2);
<a name="l00251"></a>00251         <span class="keywordtype">bool</span> isConnected(boost::shared_ptr&lt;I_Session&gt; sessionPtr);
<a name="l00252"></a>00252 
<a name="l00253"></a>00253         <span class="comment">// I_IpServerTransport implementation</span>
<a name="l00254"></a>00254     <span class="keyword">private</span>:
<a name="l00255"></a>00255         <span class="comment">//void setNetworkInterface(const std::string &amp;networkInterface);</span>
<a name="l00256"></a>00256         <span class="comment">//std::string  getNetworkInterface();</span>
<a name="l00257"></a>00257         <span class="comment">//void setAllowedClientIps(const std::vector&lt;std::string&gt; &amp;allowedClientIps);</span>
<a name="l00258"></a>00258         <span class="comment">//std::vector&lt;std::string&gt; getAllowedClientIps();</span>
<a name="l00259"></a>00259         <span class="comment">//bool isClientIpAllowed(const sockaddr_in &amp;addr);</span>
<a name="l00260"></a>00260         
<a name="l00261"></a>00261         <span class="comment">// I_Service implementation</span>
<a name="l00262"></a>00262     <span class="keyword">private</span>:
<a name="l00263"></a>00263         <span class="keywordtype">void</span> onServiceAdded(RcfServer &amp;server);
<a name="l00264"></a>00264         <span class="keywordtype">void</span> onServiceRemoved(RcfServer &amp;server);
<a name="l00265"></a>00265         <span class="keywordtype">void</span> onServerStart(RcfServer &amp;server);
<a name="l00266"></a>00266         <span class="keywordtype">void</span> onServerStop(RcfServer &amp;server);
<a name="l00267"></a>00267         <span class="keywordtype">void</span> onServerOpen(RcfServer &amp;server);
<a name="l00268"></a>00268         <span class="keywordtype">void</span> onServerClose(RcfServer &amp;server);
<a name="l00269"></a>00269         <span class="keywordtype">bool</span> mOpen;
<a name="l00270"></a>00270 
<a name="l00271"></a>00271         <span class="comment">// member variables</span>
<a name="l00272"></a>00272     <span class="keyword">private</span>:
<a name="l00273"></a>00273         <span class="keyword">typedef</span> boost::shared_ptr&lt;Mutex&gt; MutexPtr;
<a name="l00274"></a>00274         <span class="keyword">typedef</span> std::map&lt;Fd, SessionStatePtr&gt; SessionStateMap;
<a name="l00275"></a>00275         <span class="keyword">typedef</span> std::vector&lt; std::pair&lt;MutexPtr, SessionStateMap &gt; &gt; SynchronizedSessionMaps;
<a name="l00276"></a>00276 
<a name="l00277"></a>00277         SynchronizedSessionMaps sessionMaps;
<a name="l00278"></a>00278         I_SessionManager *pSessionManager;
<a name="l00279"></a>00279         std::string acceptorInterface;
<a name="l00280"></a>00280         <span class="keywordtype">int</span> acceptorPort;
<a name="l00281"></a>00281         Fd acceptorFd;
<a name="l00282"></a>00282         <span class="keywordtype">int</span> port;
<a name="l00283"></a>00283         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> maxPendingConnectionCount;
<a name="l00284"></a>00284         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> fdPartitionCount;
<a name="l00285"></a>00285         std::auto_ptr&lt;Iocp&gt; iocp;
<a name="l00286"></a>00286         ReadWriteMutex rwm;
<a name="l00287"></a>00287 
<a name="l00288"></a>00288         Mutex mQueuedAcceptsMutex;
<a name="l00289"></a>00289         Condition mQueuedAcceptsCondition;
<a name="l00290"></a>00290         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mQueuedAccepts; <span class="comment">// to be accessed only through InterlockedIncrement()/InterlockedDecrement()</span>
<a name="l00291"></a>00291         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mQueuedAcceptsThreshold;
<a name="l00292"></a>00292         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mQueuedAcceptsAugment;
<a name="l00293"></a>00293 
<a name="l00294"></a>00294         LPFN_ACCEPTEX mlpfnAcceptEx;
<a name="l00295"></a>00295         LPFN_GETACCEPTEXSOCKADDRS mlpfnGetAcceptExSockAddrs;
<a name="l00296"></a>00296 
<a name="l00297"></a>00297         <span class="keyword">volatile</span> <span class="keywordtype">bool</span> mStopFlag;
<a name="l00298"></a>00298     };
<a name="l00299"></a>00299     
<a name="l00300"></a>00300 } <span class="comment">// namespace RCF</span>
<a name="l00301"></a>00301 
<a name="l00302"></a>00302 <span class="preprocessor">#endif // ! INCLUDE_RCF_TCPIOCPSERVERTRANSPORT_HPP</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Sep 19 19:02:37 2006 for RCF by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.5 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jarl Lindrud
Australia Australia
Software developer, ex-resident of Sweden and now living in Canberra, Australia, working on distributed C++ applications. Jarl enjoys programming, but prefers skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 25 Oct 2011
Article Copyright 2005 by Jarl Lindrud
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid