Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy 

SocketConnection.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /****************************************************************************
00004 ** Copyright (c) quickfixengine.org  All rights reserved.
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 <set>
00035 
00036 namespace FIX
00037 {
00038 class SocketAcceptor;
00039 class SocketServer;
00040 class SocketConnector;
00041 class SocketInitiator;
00042 class Session;
00043 
00045 class SocketConnection : Responder
00046 {
00047 public:
00048   typedef std::set<SessionID> Sessions;
00049 
00050   SocketConnection( int s, Sessions sessions, SocketMonitor* pMonitor );
00051   SocketConnection( SocketInitiator&, const SessionID&, int, SocketMonitor* );
00052   virtual ~SocketConnection();
00053 
00054   int getSocket() const { return m_socket; }
00055   Session* getSession() const { return m_pSession; }
00056 
00057   bool read( SocketConnector& s );
00058   bool read( SocketAcceptor&, SocketServer& );
00059   bool processQueue();
00060 
00061   void signal()
00062   {
00063     Locker l( m_mutex );
00064     if( m_sendQueue.size() == 1 )
00065       m_pMonitor->signal( m_socket );
00066   }
00067 
00068   void unsignal()
00069   {
00070     Locker l( m_mutex );
00071     if( m_sendQueue.size() == 0 )
00072       m_pMonitor->unsignal( m_socket );
00073   }
00074 
00075   void onTimeout();
00076 
00077 private:
00078   typedef std::deque<std::string, ALLOCATOR<std::string> >
00079     Queue;
00080 
00081   bool isValidSession();
00082   void readFromSocket() throw( SocketRecvFailed );
00083   bool readMessage( std::string& msg );
00084   void readMessages( SocketMonitor& s );
00085   bool send( const std::string& );
00086   void disconnect();
00087 
00088   int m_socket;
00089   char m_buffer[BUFSIZ];
00090 
00091   Parser m_parser;
00092   Queue m_sendQueue;
00093   unsigned m_sendLength;
00094   Sessions m_sessions;
00095   Session* m_pSession;
00096   SocketMonitor* m_pMonitor;
00097   Mutex m_mutex;
00098   fd_set m_fds;
00099 };
00100 }
00101 
00102 #endif //FIX_SOCKETCONNECTION_H

Generated on Mon Apr 5 20:59:51 2010 for QuickFIX by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2001