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

/home/orenmnero/autobuild/quickfix/src/C++/SocketConnector.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (c) quickfixengine.org  All rights reserved.
00003 **
00004 ** This file is part of the QuickFIX FIX Engine
00005 **
00006 ** This file may be distributed under the terms of the quickfixengine.org
00007 ** license as defined by quickfixengine.org and appearing in the file
00008 ** LICENSE included in the packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00014 **
00015 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 ****************************************************************************/
00019 
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 #include "CallStack.h"
00026 
00027 #include "SocketConnector.h"
00028 #include "Utility.h"
00029 #ifndef _MSC_VER
00030 #include <unistd.h>
00031 #include <sys/ioctl.h>
00032 #include <sys/types.h>
00033 #include <sys/stat.h>
00034 #endif
00035 #include <iostream>
00036 
00037 namespace FIX
00038 {
00040 class ConnectorWrapper : public SocketMonitor::Strategy
00041 {
00042 public:
00043   ConnectorWrapper( SocketConnector& connector,
00044                     SocketConnector::Strategy& strategy )
00045 : m_connector( connector ), m_strategy( strategy ) {}
00046 
00047 private:
00048   void onConnect( SocketMonitor&, int socket )
00049   { QF_STACK_PUSH(ConnectorWrapper::onConnect)
00050     
00051     m_strategy.onConnect( m_connector, socket );
00052 
00053     QF_STACK_POP
00054   }
00055 
00056   void onWrite( SocketMonitor&, int socket )
00057   { QF_STACK_PUSH(ConnectorWrapper::onWrite)
00058 
00059     m_strategy.onWrite( m_connector, socket );
00060     
00061     QF_STACK_POP
00062   }
00063 
00064   void onEvent( SocketMonitor&, int socket )
00065   { QF_STACK_PUSH(ConnectorWrapper::onEvent)
00066 
00067     m_strategy.onData( m_connector, socket );
00068 
00069     QF_STACK_POP
00070   }
00071 
00072   void onError( SocketMonitor&, int socket )
00073   { QF_STACK_PUSH(ConnectorWrapper::onError)
00074 
00075     m_strategy.onDisconnect( m_connector, socket );
00076     m_connector.getMonitor().drop( socket );
00077 
00078     QF_STACK_POP
00079   }
00080 
00081   void onError( SocketMonitor& )
00082   { QF_STACK_PUSH(ConnectorWrapper::onError)
00083     m_strategy.onError( m_connector );
00084     QF_STACK_POP
00085   }
00086 
00087   void onTimeout( SocketMonitor& )
00088   { QF_STACK_PUSH(ConnectorWrapper::onTimeout)
00089     m_strategy.onTimeout( m_connector );
00090     QF_STACK_POP
00091   };
00092 
00093   SocketConnector& m_connector;
00094   SocketConnector::Strategy& m_strategy;
00095 };
00096 
00097 SocketConnector::SocketConnector( int timeout )
00098 : m_monitor( timeout ) {}
00099 
00100 int SocketConnector::connect( const std::string& address, int port, bool noDelay )
00101 { QF_STACK_PUSH(SocketConnector::connect)
00102 
00103   int socket = socket_createConnector();
00104 
00105   if ( socket != -1 )
00106   {
00107     if( noDelay )
00108       socket_setsockopt( socket, TCP_NODELAY );
00109     m_monitor.addConnect( socket );
00110     socket_connect( socket, address.c_str(), port );
00111   }
00112   return socket;
00113 
00114   QF_STACK_POP
00115 }
00116 
00117 int SocketConnector::connect( const std::string& address, int port, bool noDelay,
00118                               Strategy& strategy )
00119 { QF_STACK_PUSH(SocketConnector::connect)
00120 
00121   int socket = connect( address, port, noDelay );
00122   return socket;
00123 
00124   QF_STACK_POP
00125 }
00126 
00127 void SocketConnector::block( Strategy& strategy, bool poll )
00128 { QF_STACK_PUSH(SocketConnector::block)
00129 
00130   ConnectorWrapper wrapper( *this, strategy );
00131   m_monitor.block( wrapper, poll );
00132 
00133   QF_STACK_POP
00134 }
00135 }

Generated on Mon Jul 24 19:36:30 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001