SocketConnector.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_SOCKETCONNECTOR_H
  21. #define FIX_SOCKETCONNECTOR_H
  22. #ifdef _MSC_VER
  23. #pragma warning( disable : 4503 4355 4786 4290 )
  24. #endif
  25. #include "SocketMonitor.h"
  26. #include <string>
  27. namespace FIX
  28. {
  29. /// Connects sockets to remote ports and addresses.
  30. class SocketConnector
  31. {
  32. public:
  33. class Strategy;
  34. SocketConnector( int timeout = 0 );
  35. int connect( const std::string& address, int port, bool noDelay,
  36. int sendBufSize, int rcvBufSize );
  37. int connect( const std::string& address, int port, bool noDelay,
  38. int sendBufSize, int rcvBufSize, Strategy& );
  39. void block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
  40. SocketMonitor& getMonitor() { return m_monitor; }
  41. private:
  42. SocketMonitor m_monitor;
  43. public:
  44. class Strategy
  45. {
  46. public:
  47. virtual ~Strategy() {}
  48. virtual void onConnect( SocketConnector&, int socket ) = 0;
  49. virtual void onWrite( SocketConnector&, int socket ) = 0;
  50. virtual bool onData( SocketConnector&, int socket ) = 0;
  51. virtual void onDisconnect( SocketConnector&, int socket ) = 0;
  52. virtual void onError( SocketConnector& ) = 0;
  53. virtual void onTimeout( SocketConnector& ) {};
  54. };
  55. };
  56. }
  57. #endif //FIX_SOCKETCONNECTOR_H