SocketConnection.h
Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /****************************************************************************
00004 ** Copyright (c) 2001-2014
00005 **
00006 ** This file is part of the QuickFIX FIX Engine
00007 **
00008 ** This file may be distributed under the terms of the quickfixengine.org
00009 ** license as defined by quickfixengine.org and appearing in the file
00010 ** LICENSE included in the packaging of this file.
00011 **
00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00016 **
00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00018 ** not clear to you.
00019 **
00020 ****************************************************************************/
00021 
00022 #ifndef FIX_SOCKETCONNECTION_H
00023 #define FIX_SOCKETCONNECTION_H
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028 
00029 #include "Parser.h"
00030 #include "Responder.h"
00031 #include "SessionID.h"
00032 #include "SocketMonitor.h"
00033 #include "Utility.h"
00034 #include "Mutex.h"
00035 #include <set>
00036 
00037 namespace FIX
00038 {
00039 class SocketAcceptor;
00040 class SocketServer;
00041 class SocketConnector;
00042 class SocketInitiator;
00043 class Session;
00044 
00046 class SocketConnection : Responder
00047 {
00048 public:
00049   typedef std::set<SessionID> Sessions;
00050 
00051   SocketConnection( int s, Sessions sessions, SocketMonitor* pMonitor );
00052   SocketConnection( SocketInitiator&, const SessionID&, int, SocketMonitor* );
00053   virtual ~SocketConnection();
00054 
00055   int getSocket() const { return m_socket; }
00056   Session* getSession() const { return m_pSession; }
00057 
00058   bool read( SocketConnector& s );
00059   bool read( SocketAcceptor&, SocketServer& );
00060   bool processQueue();
00061 
00062   void signal()
00063   {
00064     Locker l( m_mutex );
00065     if( m_sendQueue.size() == 1 )
00066       m_pMonitor->signal( m_socket );
00067   }
00068 
00069   void unsignal()
00070   {
00071     Locker l( m_mutex );
00072     if( m_sendQueue.size() == 0 )
00073       m_pMonitor->unsignal( m_socket );
00074   }
00075 
00076   void onTimeout();
00077 
00078 private:
00079   typedef std::deque<std::string, ALLOCATOR<std::string> >
00080     Queue;
00081 
00082   bool isValidSession();
00083   void readFromSocket() throw( SocketRecvFailed );
00084   bool readMessage( std::string& msg );
00085   void readMessages( SocketMonitor& s );
00086   bool send( const std::string& );
00087   void disconnect();
00088 
00089   int m_socket;
00090   char m_buffer[BUFSIZ];
00091 
00092   Parser m_parser;
00093   Queue m_sendQueue;
00094   unsigned m_sendLength;
00095   Sessions m_sessions;
00096   Session* m_pSession;
00097   SocketMonitor* m_pMonitor;
00098   Mutex m_mutex;
00099   fd_set m_fds;
00100 };
00101 }
00102 
00103 #endif //FIX_SOCKETCONNECTION_H

Generated on Mon Sep 15 2014 01:23:54 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001