Exemplo n.º 1
0
 internal SocketReader(TcpClient tcpClient, SocketSettings settings, ClientHandlerThread responder, AcceptorSocketDescriptor acceptorDescriptor)
 {
     tcpClient_          = tcpClient;
     responder_          = responder;
     acceptorDescriptor_ = acceptorDescriptor;
     stream_             = Transport.StreamFactory.CreateServerStream(tcpClient, settings, responder.GetLog());
 }
        private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(SessionSettings settings, SessionID sessionID)
        {
            QuickFix.Dictionary dict      = settings_.Get(sessionID);
            int            port           = System.Convert.ToInt32(dict.GetLong(SessionSettings.SOCKET_ACCEPT_PORT));
            SocketSettings socketSettings = new SocketSettings();

            IPEndPoint socketEndPoint;

            if (dict.Has(SessionSettings.SOCKET_ACCEPT_HOST))
            {
                string      host  = dict.GetString(SessionSettings.SOCKET_ACCEPT_HOST);
                IPAddress[] addrs = Dns.GetHostAddresses(host);
                socketEndPoint = new IPEndPoint(addrs[0], port);
            }
            else
            {
                socketEndPoint = new IPEndPoint(IPAddress.Any, port);
            }

            if (dict.Has(SessionSettings.SOCKET_NODELAY))
            {
                socketSettings.SocketNodelay = dict.GetBool(SessionSettings.SOCKET_NODELAY);
            }

            AcceptorSocketDescriptor descriptor;

            if (!socketDescriptorForAddress_.TryGetValue(socketEndPoint, out descriptor))
            {
                descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, dict);
                socketDescriptorForAddress_[socketEndPoint] = descriptor;
            }

            return(descriptor);
        }
Exemplo n.º 3
0
        private AcceptorSocketDescriptor GetAcceptorSocketDescriptor(Dictionary dict)
        {
            int            port           = System.Convert.ToInt32(dict.GetLong(SessionSettings.SOCKET_ACCEPT_PORT));
            SocketSettings socketSettings = new SocketSettings();

            IPEndPoint socketEndPoint;

            if (dict.Has(SessionSettings.SOCKET_ACCEPT_HOST))
            {
                string      host  = dict.GetString(SessionSettings.SOCKET_ACCEPT_HOST);
                IPAddress[] addrs = Dns.GetHostAddresses(host);
                socketEndPoint = new IPEndPoint(addrs[0], port);
                // Set hostname (if it is not already configured)
                socketSettings.ServerCommonName = socketSettings.ServerCommonName ?? host;
            }
            else
            {
                socketEndPoint = new IPEndPoint(IPAddress.Any, port);
            }

            socketSettings.Configure(dict);


            AcceptorSocketDescriptor descriptor;

            if (!socketDescriptorForAddress_.TryGetValue(socketEndPoint, out descriptor))
            {
                descriptor = new AcceptorSocketDescriptor(socketEndPoint, socketSettings, dict);
                socketDescriptorForAddress_[socketEndPoint] = descriptor;
            }

            return(descriptor);
        }
 internal ThreadedSocketReactor(IPEndPoint serverSocketEndPoint, SocketSettings socketSettings, QuickFix.Dictionary sessionDict, AcceptorSocketDescriptor acceptorDescriptor)
 {
     socketSettings_     = socketSettings;
     tcpListener_        = new TcpListener(serverSocketEndPoint);
     sessionDict_        = sessionDict;
     acceptorDescriptor_ = acceptorDescriptor;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Create session, either at start-up or as an ad-hoc operation
 /// </summary>
 /// <param name="sessionID">ID of new session</param>
 /// <param name="dict">config settings for new session</param>
 /// <returns>true if session added successfully, false if session already exists or is not an acceptor</returns>
 private bool CreateSession(SessionID sessionID, Dictionary dict)
 {
     if (!sessions_.ContainsKey(sessionID))
     {
         string connectionType = dict.GetString(SessionSettings.CONNECTION_TYPE);
         if ("acceptor" == connectionType)
         {
             AcceptorSocketDescriptor descriptor = GetAcceptorSocketDescriptor(dict);
             Session session = sessionFactory_.Create(sessionID, dict);
             descriptor.AcceptSession(session);
             sessions_[sessionID] = session;
             return(true);
         }
     }
     return(false);
 }
        private void CreateSessions(SessionSettings settings)
        {
            foreach (SessionID sessionID in settings.GetSessions())
            {
                QuickFix.Dictionary dict = settings.Get(sessionID);
                string connectionType    = dict.GetString(SessionSettings.CONNECTION_TYPE);

                if ("acceptor".Equals(connectionType))
                {
                    AcceptorSocketDescriptor descriptor = GetAcceptorSocketDescriptor(settings, sessionID);
                    Session session = sessionFactory_.Create(sessionID, dict);
                    descriptor.AcceptSession(session);
                    sessions_[sessionID] = session;
                }
            }

            if (0 == socketDescriptorForAddress_.Count)
            {
                throw new ConfigError("No acceptor sessions found in SessionSettings.");
            }
        }
Exemplo n.º 7
0
        internal ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict,
                                     SocketSettings socketSettings, AcceptorSocketDescriptor acceptorDescriptor)
        {
            string debugLogFilePath = "";

            if (settingsDict.Has(SessionSettings.DEBUG_FILE_LOG_PATH))
            {
                debugLogFilePath = settingsDict.GetString(SessionSettings.DEBUG_FILE_LOG_PATH);
            }
            //else if (settingsDict.Has(SessionSettings.FILE_LOG_PATH))
            //    debugLogFilePath = settingsDict.GetString(SessionSettings.FILE_LOG_PATH);

            // FIXME - do something more flexible than hardcoding a filelog
            if (!string.IsNullOrEmpty(debugLogFilePath))
            {
                log_ = new FileLog(debugLogFilePath, new SessionID(
                                       "ClientHandlerThread", clientId.ToString(), "Debug-" + Guid.NewGuid().ToString()));
            }
            this.Id       = clientId;
            socketReader_ = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor);
        }
Exemplo n.º 8
0
        internal ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict,
                                     SocketSettings socketSettings, AcceptorSocketDescriptor acceptorDescriptor)
        {
            string debugLogFilePath = "log";

            if (settingsDict.Has(SessionSettings.DEBUG_FILE_LOG_PATH))
            {
                debugLogFilePath = settingsDict.GetString(SessionSettings.DEBUG_FILE_LOG_PATH);
            }
            else if (settingsDict.Has(SessionSettings.FILE_LOG_PATH))
            {
                debugLogFilePath = settingsDict.GetString(SessionSettings.FILE_LOG_PATH);
            }

            // FIXME - do something more flexible than hardcoding a filelog
            log_ = new FileLog(debugLogFilePath, new SessionID(
                                   "ClientHandlerThread", clientId.ToString(), "Debug-" + Guid.NewGuid().ToString()));

            this.Id            = clientId;
            this.SourceAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address.ToString();
            socketReader_      = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create session, either at start-up or as an ad-hoc operation
        /// </summary>
        /// <param name="sessionID">ID of new session</param>
        /// <param name="dict">config settings for new session</param>
        /// <returns>true if session added successfully, false if session already exists or is not an acceptor</returns>
        private bool CreateSession(SessionID sessionID, Dictionary dict)
        {
            if (!sessions_.ContainsKey(sessionID))
            {
                string connectionType = dict.GetString(SessionSettings.CONNECTION_TYPE);
                if ("acceptor" == connectionType)
                {
                    AcceptorSocketDescriptor descriptor = GetAcceptorSocketDescriptor(dict);
                    Session session = sessionFactory_.Create(sessionID, dict);

                    // start descriptor if it was just created and if acceptor is already started
                    if (isStarted_ && !_disposed && !descriptor.SocketReactor.IsStarted)
                    {
                        descriptor.SocketReactor.Start();
                    }

                    descriptor.AcceptSession(session);
                    sessions_[sessionID] = session;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 10
0
        internal ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict, SocketSettings socketSettings, AcceptorSocketDescriptor acceptorDescriptor
                                     )
        {
            string debugLogFilePath = "log";

            if (settingsDict.Has(SessionSettings.DEBUG_FILE_LOG_PATH))
            {
                debugLogFilePath = settingsDict.GetString(SessionSettings.DEBUG_FILE_LOG_PATH);
            }
            else if (settingsDict.Has(SessionSettings.FILE_LOG_PATH))
            {
                debugLogFilePath = settingsDict.GetString(SessionSettings.FILE_LOG_PATH);
            }

            var sessionId = new SessionID("ClientHandlerThread", clientId.ToString(), "Debug");

            try
            {
                // FIXME - do something more flexible than hardcoding a filelog
                log_ = new FileLog(debugLogFilePath, sessionId);
            }
            catch
            {
                // TODO: fix this the correct way
                log_ = new ScreenLog(sessionId, true, true, true);
            }

            this.Id       = clientId;
            socketReader_ = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor);
        }