// ------------------------------------------------- // events void TcpServerSocketEmul::OnNewConnection(Utils::SafeRef<ITcpSocketEmul> pClient) { boost::shared_ptr<TcpSocketEmul> pServer(new TcpSocketEmul(m_thread)); TUT_ASSERT(pServer.get() != 0); pServer->setOther(pClient); pClient->setOther(pServer.get()); pServer->ConnectToHost(pClient->LocalHostInf()); pClient->Connected(); // pServer->Connected(); m_pOwner->NewConnection(pServer); }
CRef< CTaxon3_reply > CTaxon3::SendRequest(const CTaxon3_request& request) { SetLastError(NULL); unsigned reconnect_attempts = 0; while (reconnect_attempts < m_nReconnectAttempts) { try { auto_ptr<CObjectOStream> pOut; auto_ptr<CObjectIStream> pIn; auto_ptr<CConn_ServiceStream> pServer( new CConn_ServiceStream(m_sService, fSERV_Any, 0, 0, m_timeout) ); pOut.reset( CObjectOStream::Open(m_eDataFormat, *pServer) ); pIn.reset( CObjectIStream::Open(m_eDataFormat, *pServer) ); CObjectIStream* ppIn = pIn.release(); CObjectOStream* ppOut = pOut.release(); try { *ppOut << request; ppOut->Flush(); ppOut->Close(); try { CRef< CTaxon3_reply > response(new CTaxon3_reply); *ppIn >> *response; delete ppIn; delete ppOut; return response; } catch (exception& e) { SetLastError( e.what() ); } } catch (exception& e) { SetLastError( e.what() ); } } catch( exception& e ) { SetLastError( e.what() ); } reconnect_attempts++; } // return NULL CRef<CTaxon3_reply> reply; return reply; }
void HttpServer::OnAccept(NetSocket socket , sockaddr_in * addr) { if (m_pNetReactor) { char szAddress[MAX_NAME_LENGTH]; UINT16 usPort = 0; Net::NetHelper::GetAddressAndPortByAddrIn(addr , szAddress , usPort); ServerSession * pServerSession = new HttpSession(szAddress , usPort , "" , "", -1 , NET_STATE_CONNECTED , socket); NetHandlerHttpServerPtr pServer( new NetHandlerHttpServer(this , m_pNetReactor , pServerSession) ); m_pNetReactor->AddNetHandler(pServer); } }
int main(int argc, char * argv[]) { try{ boost::scoped_ptr<WatchdogBridge> pServer ( new WatchdogBridge("WatchdogSM")); CliCommandParser p(argc,argv); CliCommandParser::CommandsArray commands = p.parse(); std::for_each( commands.begin(), commands.end(), Sender( pServer.get() ) ); if ( commands.empty() ) LOG( "Commands array is empty. No command given. Shouldn't happen" ); } catch( const boost::interprocess::interprocess_exception& ex) { LOG( " Exception what=" << ex.what() << " native error code=" << ex.get_native_error() << " err code=" << ex.get_error_code()); } return 0 ; }
void main() { try { std::unique_ptr<Server> pServer(new Server()); std::future<void> server = std::async(std::launch::async, &Server::StartServer, pServer.get()); Sleep(1000); std::string fileName = "C:\\Users\\POMA\\Downloads\\rmn.xml"; std::string out = "C:\\Users\\POMA\\Downloads\\rmnOut.xml"; std::unique_ptr<Client> pClient(new Client()); //std::future<void> cl = std::async(std::launch::async, &Client::Start, pClient.get()); pClient->Start(fileName); pClient->WritePrimes(out); } catch(...) { std::cout << "Unhandled exception!" << std::endl; } system("pause"); }