void ThreadedSocketAcceptor::onInitialize( const SessionSettings& s ) throw ( RuntimeError ) { short port = 0; std::set<int> ports; std::set<SessionID> sessions = s.getSessions(); std::set<SessionID>::iterator i = sessions.begin(); for( ; i != sessions.end(); ++i ) { const Dictionary& settings = s.get( *i ); port = (short)settings.getInt( SOCKET_ACCEPT_PORT ); m_portToSessions[port].insert( *i ); if( ports.find(port) != ports.end() ) continue; ports.insert( port ); const bool reuseAddress = settings.has( SOCKET_REUSE_ADDRESS ) ? settings.getBool( SOCKET_REUSE_ADDRESS ) : true; const bool noDelay = settings.has( SOCKET_NODELAY ) ? settings.getBool( SOCKET_NODELAY ) : false; const int sendBufSize = settings.has( SOCKET_SEND_BUFFER_SIZE ) ? settings.getInt( SOCKET_SEND_BUFFER_SIZE ) : 0; const int rcvBufSize = settings.has( SOCKET_RECEIVE_BUFFER_SIZE ) ? settings.getInt( SOCKET_RECEIVE_BUFFER_SIZE ) : 0; int socket = socket_createAcceptor( port, reuseAddress ); if( socket < 0 ) { SocketException e; socket_close( socket ); throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)port ) + " (" + e.what() + ")" ); } if( noDelay ) socket_setsockopt( socket, TCP_NODELAY ); if( sendBufSize ) socket_setsockopt( socket, SO_SNDBUF, sendBufSize ); if( rcvBufSize ) socket_setsockopt( socket, SO_RCVBUF, rcvBufSize ); m_socketToPort[socket] = port; m_sockets.insert( socket ); } }
void ThreadedSocketAcceptor::onConfigure( const SessionSettings& s ) throw ( ConfigError ) { std::set<SessionID> sessions = s.getSessions(); std::set<SessionID>::iterator i; for( i = sessions.begin(); i != sessions.end(); ++i ) { const Dictionary& settings = s.get( *i ); settings.getInt( SOCKET_ACCEPT_PORT ); if( settings.has(SOCKET_REUSE_ADDRESS) ) settings.getBool( SOCKET_REUSE_ADDRESS ); if( settings.has(SOCKET_NODELAY) ) settings.getBool( SOCKET_NODELAY ); } }
/** * We are overidding start to prevent Adapter processing of session life cycle */ void QuickFIXAdapter::start() { //std::cout << "QuickFIXAdapter: start()" << std::endl; // Perform all QuickFIX initialisation std::string settingsFileName = "QuickFIXAdapter.cfg"; SessionSettings *settings = new SessionSettings( settingsFileName); std::cout << "QuickFIXAdapter: settings loaded from " << settingsFileName << std::endl; MyApplication *application = new MyApplication( this); FileStoreFactory *storeFactory = new FileStoreFactory(*settings); FileLogFactory *logFactory = new FileLogFactory(*settings); this->initiator = new SocketInitiator( *application, *storeFactory, *settings, *logFactory /*optional*/); //std::cout << "QuickFIXAdapter: starting initiator" << std::endl; this->initiator->start(); // memorize session std::set<SessionID> sessions = settings->getSessions(); std::cout << "QuickFIXAdapter: adapter started with " << sessions.size() << " session(s)" << std::endl; if( sessions.size() > 0) { this->session = FIX::Session::lookupSession( *sessions.begin()); } }