DLLEXPORT double socket_accept(double handle) { AcceptorPtr acceptor = handles.find<CombinedTcpAcceptor> (handle); if (acceptor) { boost::shared_ptr<TcpSocket> accepted = acceptor->accept(); if (accepted) { return handles.allocate(accepted); } } return -1; }
DLLEXPORT double socket_local_port(double handle) { boost::shared_ptr<Socket> socket = handles.find<Socket> (handle); if (socket) { return socket->getLocalPort(); } AcceptorPtr acceptor = handles.find<CombinedTcpAcceptor> (handle); if(acceptor) { return acceptor->getLocalPort(); } return 0; }
int main( int argc, char** argv ) { std::string file; bool threaded = false; if ( getopt( argc, argv, "+f:" ) == 'f' ) file = optarg; else { std::cout << "usage: " << argv[ 0 ] << " -f FILE [-t]" << std::endl; return 1; } if ( getopt( argc, argv, "+t" ) == 't' ) threaded = true; try { FIX::SessionSettings settings( file ); Application application; FIX::FileStoreFactory factory( "store" ); AcceptorPtr pAcceptor; if ( threaded ) { pAcceptor.reset( new FIX::ThreadedSocketAcceptor ( application, factory, settings ) ); } else { pAcceptor.reset( new FIX::SocketAcceptor ( application, factory, settings ) ); } pAcceptor->start(); while ( true ) FIX::process_sleep( 1 ); pAcceptor->stop(); } catch ( std::exception & e ) { std::cout << e.what(); return 2; } return 0; }
void run() { std::string myBigString; for (int i = 0; i<10000; ++i) { myBigString += as_string(i); } AC_PRINT << "the following might cause 'broken pipe' warnings - this is normal"; setSilentSuccess(true); #ifdef WIN32 int myIterations = 10; // aborting is VERY slow in windows. #else int myIterations = 100; // don't increase this or the socket table will fill up with TIME_WAIT sockets, waiting to die #endif for (int i = 0; i < myIterations; ++i) { // start server thread AcceptorPtr myAcceptor = AcceptorPtr(new ConduitAcceptor<POLICY>(_myLocalEndpoint, myLowercaseServer<POLICY>::create)); ENSURE(myAcceptor->start()); // start client { CharBuffer myInputBuffer; typename Conduit<POLICY>::Ptr myClient(new Conduit<POLICY>(_myLocalEndpoint)); ENSURE(myClient); ENSURE(myClient->sendData(myBigString.c_str(), myBigString.length())); /* string myReceiveString; while (myReceiveString.length() < myBigString.length() && myClient->isValid()) { if (myClient->receiveData(myInputBuffer)) { myReceiveString += string(&myInputBuffer[0], myInputBuffer.size()); } } ENSURE(myReceiveString == myBigString); */ } // close the server (also test if the server is cancelable) ENSURE_MSG(myAcceptor->stop(), "Cancelling server thread"); myAcceptor = AcceptorPtr(0); } setSilentSuccess(false); }
int main( int argc, char** argv ) { std::string file; if ( getopt( argc, argv, "+f:" ) == 'f' ) file = optarg; else { std::cout << "usage: " << argv[ 0 ] << " -f FILE" << std::endl; return 1; } try { FIX::SessionSettings settings( file ); Application application; FIX::FileStoreFactory factory( "store" ); AcceptorPtr pAcceptor; pAcceptor = std::auto_ptr < FIX::Acceptor > ( new FIX::SocketAcceptor ( application, factory, settings ) ); pAcceptor->start(); while ( true ) FIX::process_sleep( 1 ); pAcceptor->stop(); } catch ( std::exception & e ) { std::cout << e.what(); return 2; } return 0; }
void HttpServer::start_accept(AcceptorPtr acceptor) { if (running_) { auto connection = new HTTP::Connection(*this, pool_->getService(), acceptor->ssl_ctx.get()); mark(connection); acceptor->async_accept(connection->socket_, std::bind(&HttpServer::accept_callback, this, std::placeholders::_1, acceptor, connection)); } }