-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Acceptor.Stop() then restart doesn't work? #196
Comments
This is definitely an issue and I've made some changes that seem to fix it and, as such, I've created a pull request for this issue. https://github.com/connamara/quickfixn/pull/351/files At it's basic the issue is that the "Acceptor.Start()" method only calls the "StartAcceptingConnections()" method if the isStarted_ flag is false: public void Start() but when you call "Acceptor.Stop()" it doesn't do anything to this flag so calling Start() after Stop() effectively does nothing: public void Stop(bool force) Unfortunately, simply setting the isStarted_ flag at this point to false doesn't work as the StartAcceptingConnections method calls the Start method on the SocketReactor which subsequently calls the Run method which only actually runs if the ReactorState is set to State.Running but the start method doesn't do this so it's left in the SHUTDOWN_COMPLETED state: public void Start() public void Run() Unfortunately, setting the ReactorState in the Start method to State.RUNNING didn't work either as the Session/SocketReader starts complaining "Multiple logons/connections for this session are not allowed" as it looks like the SocketReader and/or the Session has not been closed/logged out correctly during the shutdown. This was due to the non-implementation of WaitForLogout in the socket acceptor. So I've implemented this method. However, that didn't finally resolve it as there were some threading issues. public void Log(string s) The next issue was that the Run method in SocketReactor used the blocking AcceptTcpClient which meant that even if the state was changed the ShutdownClientHandlerthreads would never be called. So I've changed this to a sleep based loop using TcpListener.Pending: if( !tcpListener_.Pending() ) though I think moving to using the BeginAcceptTcpClient/EndAcceptTcpClient asynchronous methods might be a better approach. Unfortunately, I have to work on something else just now but I might look into this next time I have a spare moment. The other change I made was that the start of the run method would call TcpListener.Start. However, if someone called stop before this method had finished it could leave the class in the SHUTDOWN_REQUESTED state so I moved the call to start to before the Run thread is started. Anyway, I've added some tests around the ThreadedSocketAccecptor in terms of starting and stopping and logging on to test various scenarios. Huw |
Hi guys. Any progress? |
Reported by @TomasVetrovsky in #185. Needs verification.
If a fix is needed, maybe this and #185 can be fixed together.
The text was updated successfully, but these errors were encountered: