ThreadedSocketConnection.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_THREADEDSOCKETCONNECTION_H
  21. #define FIX_THREADEDSOCKETCONNECTION_H
  22. #ifdef _MSC_VER
  23. #pragma warning( disable : 4503 4355 4786 4290 )
  24. #endif
  25. #include "Parser.h"
  26. #include "Responder.h"
  27. #include "SessionID.h"
  28. #include <set>
  29. #include <map>
  30. namespace FIX
  31. {
  32. class ThreadedSocketAcceptor;
  33. class ThreadedSocketInitiator;
  34. class Session;
  35. class Application;
  36. class Log;
  37. /// Encapsulates a socket file descriptor (multi-threaded).
  38. class ThreadedSocketConnection : Responder
  39. {
  40. public:
  41. typedef std::set<SessionID> Sessions;
  42. ThreadedSocketConnection( int s, Sessions sessions, Log* pLog );
  43. ThreadedSocketConnection( const SessionID&, int s,
  44. const std::string& address, short port,
  45. Log* pLog );
  46. virtual ~ThreadedSocketConnection() ;
  47. Session* getSession() const { return m_pSession; }
  48. int getSocket() const { return m_socket; }
  49. bool connect();
  50. void disconnect();
  51. bool read();
  52. private:
  53. bool readMessage( std::string& msg ) throw( SocketRecvFailed );
  54. void processStream();
  55. bool send( const std::string& );
  56. bool setSession( const std::string& msg );
  57. int m_socket;
  58. char m_buffer[BUFSIZ];
  59. std::string m_address;
  60. int m_port;
  61. Log* m_pLog;
  62. Parser m_parser;
  63. Sessions m_sessions;
  64. Session* m_pSession;
  65. bool m_disconnect;
  66. fd_set m_fds;
  67. };
  68. }
  69. #endif //FIX_THREADEDSOCKETCONNECTION_H