00001 00007 #include "stdafx.h" 00008 #include <bzscmn/bzscmn.h> 00009 #include "../kdvm/kdrpc.h" 00010 #include "../kdvm/kdxxx.h" 00011 #include "../rpcdispatch/pipesrv.h" 00012 #include "../rpcdispatch/rpcdisp.h" 00013 #include "../rpcdispatch/kdcomdisp.h" 00014 #include "../rpcdispatch/reporter.h" 00015 00016 #ifndef KDVMWARE_USE_PROXY 00017 #error KDVMWARE_USE_PROXY should be defined in project properties for headers to work correctly 00018 #endif 00019 00020 static const TCHAR tszProxyPipeName[] = _T("\\\\.\\pipe\\kd_proxy"); 00021 00023 00042 class RpcProxy 00043 { 00044 private: 00045 enum {TEMP_BUF_SIZE = 262144}; 00046 PipeServer<true, false> m_Server; 00047 KdRpcDispatcher m_Client; 00048 00049 char *m_pBuf1; 00050 00051 public: 00052 RpcProxy() 00053 : m_Server(_T("\\\\.\\pipe\\kdvmware_proxypipe")) 00054 , m_Client(new KdComDispatcher(tszProxyPipeName)) 00055 { 00056 m_pBuf1 = new char[TEMP_BUF_SIZE]; 00057 wcsncpy(g_pReporter->GetStatusPointer()->PipeName, tszProxyPipeName, __countof(g_pReporter->GetStatusPointer()->PipeName)); 00058 g_pReporter->GetStatusPointer()->PatchErrorPlus1 = 1; 00059 } 00060 00061 ~RpcProxy() 00062 { 00063 delete m_pBuf1; 00064 } 00065 00066 void MainLoop() 00067 { 00068 for (;;) 00069 { 00070 size_t done = m_Server.Receive(m_pBuf1, TEMP_BUF_SIZE); 00071 if (!done) 00072 { 00073 if (m_Server.ReconnectPending()) 00074 { 00075 m_Server.ReconnectPipe(); 00076 continue; 00077 } 00078 } 00079 char *pReply = NULL; 00080 size_t replySize = m_Client.OnRequest(m_pBuf1, done, &pReply); 00081 if (!m_Server.Send(pReply, replySize)) 00082 { 00083 if (m_Server.ReconnectPending()) 00084 { 00085 m_Server.ReconnectPipe(); 00086 continue; 00087 } 00088 } 00089 } 00090 } 00091 }; 00092 00093 StatusReporter *g_pReporter = NULL; 00094 00095 int _tmain(int argc, _TCHAR* argv[]) 00096 { 00097 g_pReporter = new StatusReporter(); 00098 RpcProxy proxy; 00099 proxy.MainLoop(); 00100 return 0; 00101 } 00102