Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
FIX::HttpServer Class Reference

Basic HTTP Server. More...

#include <HttpServer.h>

Inheritance diagram for FIX::HttpServer:
Inheritance graph
[legend]
Collaboration diagram for FIX::HttpServer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 HttpServer (const SessionSettings &) throw ( ConfigError )
void start () throw ( ConfigError, RuntimeError )
void stop ()

Static Public Member Functions

static void startGlobal (const SessionSettings &) throw ( ConfigError, RuntimeError )
static void stopGlobal ()

Private Member Functions

void onConfigure (const SessionSettings &) throw ( ConfigError )
void onInitialize (const SessionSettings &) throw ( RuntimeError )
void onStart ()
bool onPoll ()
void onStop ()
void onConnect (SocketServer &, int, int)
void onWrite (SocketServer &, int)
bool onData (SocketServer &, int)
void onDisconnect (SocketServer &, int)
void onError (SocketServer &)
void onTimeout (SocketServer &)

Static Private Member Functions

static THREAD_PROC startThread (void *p)

Private Attributes

SocketServerm_pServer
SessionSettings m_settings
thread_id m_threadid
int m_port
bool m_stop

Static Private Attributes

static Mutex s_mutex
static int s_count = 0
static HttpServers_pServer = 0

Detailed Description

Basic HTTP Server.

Definition at line 37 of file HttpServer.h.


Constructor & Destructor Documentation

FIX::HttpServer::HttpServer ( const SessionSettings settings) throw ( ConfigError )

Definition at line 66 of file HttpServer.cpp.

: m_pServer( 0 ), m_settings( settings ), m_threadid( 0 ), m_port( 0 ), m_stop( false ) {}

Member Function Documentation

void FIX::HttpServer::onConfigure ( const SessionSettings s) throw ( ConfigError ) [private]

Definition at line 69 of file HttpServer.cpp.

References FIX::HTTP_ACCEPT_PORT.

Referenced by start().

{  
  m_port = s.get().getInt( HTTP_ACCEPT_PORT );
}
void FIX::HttpServer::onConnect ( SocketServer server,
int  a,
int  s 
) [private, virtual]

Implements FIX::SocketServer::Strategy.

Definition at line 135 of file HttpServer.cpp.

References FIX::SocketMonitor::drop(), FIX::SocketServer::getMonitor(), m_pServer, FIX::HttpConnection::read(), and FIX::socket_isValid().

{
  if ( !socket_isValid( s ) ) return;
  HttpConnection connection( s );
  while( connection.read() ) {}
  m_pServer->getMonitor().drop( s );
}
bool FIX::HttpServer::onData ( SocketServer server,
int  s 
) [private, virtual]

Implements FIX::SocketServer::Strategy.

Definition at line 147 of file HttpServer.cpp.

{
  return true;
}
void FIX::HttpServer::onDisconnect ( SocketServer ,
int  s 
) [private, virtual]

Implements FIX::SocketServer::Strategy.

Definition at line 152 of file HttpServer.cpp.

{
}
void FIX::HttpServer::onError ( SocketServer ) [private, virtual]

Implements FIX::SocketServer::Strategy.

Definition at line 156 of file HttpServer.cpp.

{}
void FIX::HttpServer::onInitialize ( const SessionSettings s) throw ( RuntimeError ) [private]

Definition at line 75 of file HttpServer.cpp.

References FIX::IntConvertor::convert().

Referenced by start().

{
  try
  {
    m_pServer = new SocketServer( 1 );
    m_pServer->add( m_port, true, false, 0, 0 );
  }
  catch( std::exception& )
  {
    throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)m_port ) );
  }
}
bool FIX::HttpServer::onPoll ( ) [private]

Definition at line 122 of file HttpServer.cpp.

References FIX::SocketServer::block(), m_pServer, and m_stop.

{
  if( !m_pServer || m_stop )
    return false;

  m_pServer->block( *this, true );
  return true;
}
void FIX::HttpServer::onStart ( ) [private]

Definition at line 110 of file HttpServer.cpp.

References FIX::SocketServer::block(), FIX::SocketServer::close(), m_pServer, and m_stop.

Referenced by startThread().

{
  while ( !m_stop && m_pServer && m_pServer->block( *this ) ) {}

  if( !m_pServer )
    return;

  m_pServer->close();
  delete m_pServer;
  m_pServer = 0;
}
void FIX::HttpServer::onStop ( ) [private]

Definition at line 131 of file HttpServer.cpp.

Referenced by stop().

{
}
void FIX::HttpServer::onTimeout ( SocketServer ) [private, virtual]

Reimplemented from FIX::SocketServer::Strategy.

Definition at line 158 of file HttpServer.cpp.

{
}
void FIX::HttpServer::onWrite ( SocketServer server,
int  s 
) [private, virtual]

Implements FIX::SocketServer::Strategy.

Definition at line 143 of file HttpServer.cpp.

{
}

Definition at line 89 of file HttpServer.cpp.

References m_settings, m_stop, m_threadid, onConfigure(), onInitialize(), startThread(), and FIX::thread_spawn().

{
  m_stop = false;
  onConfigure( m_settings );
  onInitialize( m_settings );

  if( !thread_spawn( &startThread, this, m_threadid ) )
    throw RuntimeError("Unable to spawn thread");
}
void FIX::HttpServer::startGlobal ( const SessionSettings s) throw ( ConfigError, RuntimeError ) [static]

Definition at line 37 of file HttpServer.cpp.

References FIX::HTTP_ACCEPT_PORT.

Referenced by FIX::Initiator::start(), and FIX::Acceptor::start().

{
  Locker l( s_mutex );

  if( !s.get().has(HTTP_ACCEPT_PORT) )
    return;

  s_count += 1;
  if( !s_pServer )
  {
    s_pServer = new HttpServer( s );
    s_pServer->start();
  }
}
THREAD_PROC FIX::HttpServer::startThread ( void *  p) [static, private]

Definition at line 162 of file HttpServer.cpp.

References onStart().

Referenced by start().

{
  HttpServer * pServer = static_cast < HttpServer* > ( p );
  pServer->onStart();
  return 0;
}

Definition at line 99 of file HttpServer.cpp.

References m_stop, m_threadid, onStop(), and FIX::thread_join().

Referenced by stopGlobal().

{
  if( m_stop ) return;
  m_stop = true;
  onStop();

  if( m_threadid )
    thread_join( m_threadid );
  m_threadid = 0;
}
void FIX::HttpServer::stopGlobal ( ) [static]

Definition at line 53 of file HttpServer.cpp.

References s_count, s_mutex, s_pServer, and stop().

Referenced by FIX::Initiator::stop(), and FIX::Acceptor::stop().

{
  Locker l( s_mutex );

  s_count -= 1;
  if( !s_count && s_pServer )
  {
    s_pServer->stop();
    delete s_pServer;
    s_pServer = 0;
  }  
}

Member Data Documentation

int FIX::HttpServer::m_port [private]

Definition at line 68 of file HttpServer.h.

Definition at line 65 of file HttpServer.h.

Referenced by onConnect(), onPoll(), and onStart().

Definition at line 66 of file HttpServer.h.

Referenced by start().

bool FIX::HttpServer::m_stop [private]

Definition at line 69 of file HttpServer.h.

Referenced by onPoll(), onStart(), start(), and stop().

Definition at line 67 of file HttpServer.h.

Referenced by start(), and stop().

int FIX::HttpServer::s_count = 0 [static, private]

Definition at line 72 of file HttpServer.h.

Referenced by stopGlobal().

Mutex FIX::HttpServer::s_mutex [static, private]

Definition at line 71 of file HttpServer.h.

Referenced by stopGlobal().

HttpServer * FIX::HttpServer::s_pServer = 0 [static, private]

Definition at line 73 of file HttpServer.h.

Referenced by stopGlobal().


The documentation for this class was generated from the following files:

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001