ThreadedSocketInitiator.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef FIX_THREADEDSOCKETINITIATOR_H
  21. #define FIX_THREADEDSOCKETINITIATOR_H
  22. #ifdef _MSC_VER
  23. #pragma warning( disable : 4503 4355 4786 4290 )
  24. #endif
  25. #include "Initiator.h"
  26. #include "ThreadedSocketConnection.h"
  27. #include <map>
  28. namespace FIX
  29. {
  30. /*! \addtogroup user
  31. * @{
  32. */
  33. /// Threaded Socket implementation of Initiator.
  34. class ThreadedSocketInitiator : public Initiator
  35. {
  36. public:
  37. ThreadedSocketInitiator( Application&, MessageStoreFactory&,
  38. const SessionSettings& ) throw( ConfigError );
  39. ThreadedSocketInitiator( Application&, MessageStoreFactory&,
  40. const SessionSettings&,
  41. LogFactory& ) throw( ConfigError );
  42. virtual ~ThreadedSocketInitiator();
  43. private:
  44. typedef std::map < int, thread_id > SocketToThread;
  45. typedef std::map < SessionID, int > SessionToHostNum;
  46. typedef std::pair < ThreadedSocketInitiator*, ThreadedSocketConnection* > ThreadPair;
  47. void onConfigure( const SessionSettings& ) throw ( ConfigError );
  48. void onInitialize( const SessionSettings& ) throw ( RuntimeError );
  49. void onStart();
  50. bool onPoll( double timeout );
  51. void onStop();
  52. void doConnect( const SessionID& s, const Dictionary& d );
  53. void addThread( int s, thread_id t );
  54. void removeThread( int s );
  55. void lock() { Locker l(m_mutex); }
  56. static THREAD_PROC socketThread( void* p );
  57. void getHost( const SessionID&, const Dictionary&, std::string&, short& );
  58. SessionSettings m_settings;
  59. SessionToHostNum m_sessionToHostNum;
  60. time_t m_lastConnect;
  61. int m_reconnectInterval;
  62. bool m_noDelay;
  63. int m_sendBufSize;
  64. int m_rcvBufSize;
  65. SocketToThread m_threads;
  66. Mutex m_mutex;
  67. };
  68. /*! @} */
  69. }
  70. #endif //FIX_THREADEDSOCKETINITIATOR_H