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

# FIX::HttpServer Class Reference

Basic HTTP Server. More...

`#include <HttpServer.h>`

Inheritance diagram for FIX::HttpServer:
[legend]
Collaboration diagram for FIX::HttpServer:
[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

SocketServer * | m_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 HttpServer * | s_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 67 of file HttpServer.cpp.

    00068 : 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 70 of file HttpServer.cpp.

References FIX::HTTP_ACCEPT_PORT, QF_STACK_POP, and QF_STACK_PUSH.

Referenced by start().

    00072 { QF_STACK_PUSH(HttpServer::onConfigure)
    00073   m_port = s.get().getLong( HTTP_ACCEPT_PORT );
    00074   QF_STACK_POP
    00075 }

void FIX::HttpServer::onConnect | ( | SocketServer & | server,
|  | int | a,
|  | int | s |
| ) |  |  | `[private, virtual]`

Implements FIX::SocketServer::Strategy.

Definition at line 153 of file HttpServer.cpp.

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

    00154 { QF_STACK_PUSH(HttpServer::onConnect)
    00155
    00156   if ( !socket_isValid( s ) ) return;
    00157   HttpConnection connection( s );
    00158   while( connection.read() ) {}
    00159   m_pServer->getMonitor().drop( s );
    00160
    00161   QF_STACK_POP
    00162 }

bool FIX::HttpServer::onData | ( | SocketServer & | server,
|  | int | s |
| ) |  |  | `[private, virtual]`

Implements FIX::SocketServer::Strategy.

Definition at line 169 of file HttpServer.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

    00170 { QF_STACK_PUSH(HttpServer::onData)
    00171
    00172   return true;
    00173
    00174   QF_STACK_POP
    00175 }

void FIX::HttpServer::onDisconnect | ( | SocketServer & | ,
|  | int | s |
| ) |  |  | `[private, virtual]`

Implements FIX::SocketServer::Strategy.

Definition at line 177 of file HttpServer.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

    00178 { QF_STACK_PUSH(HttpServer::onDisconnect)
    00179   QF_STACK_POP
    00180 }

void FIX::HttpServer::onError | ( | SocketServer & |  | ) | `[private, virtual]`

Implements FIX::SocketServer::Strategy.

Definition at line 182 of file HttpServer.cpp.

    00182 {}

void FIX::HttpServer::onInitialize | ( | const SessionSettings & | s | ) | throw ( RuntimeError )`[private]`

Definition at line 77 of file HttpServer.cpp.

References FIX::IntConvertor::convert(), QF_STACK_POP, and QF_STACK_PUSH.

Referenced by onTimeout(), and start().

    00079 { QF_STACK_PUSH(HttpServer::onInitialize)
    00080
    00081   try
    00082   {
    00083     m_pServer = new SocketServer( 1 );
    00084     m_pServer->add( m_port, true, false, 0, 0 );
    00085   }
    00086   catch( std::exception& )
    00087   {
    00088     throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)m_port ) );
    00089   }
    00090
    00091   QF_STACK_POP
    00092 }

bool FIX::HttpServer::onPoll | ( |  | ) | `[private]`

Definition at line 136 of file HttpServer.cpp.

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

    00137 { QF_STACK_PUSH(HttpServer::onPoll)
    00138
    00139   if( !m_pServer || m_stop )
    00140     return false;
    00141
    00142   m_pServer->block( *this, true );
    00143   return true;
    00144
    00145   QF_STACK_POP
    00146 }

void FIX::HttpServer::onStart | ( |  | ) | `[private]`

Definition at line 121 of file HttpServer.cpp.

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

    00122 { QF_STACK_PUSH(HttpServer::start)
    00123
    00124   while ( !m_stop && m_pServer && m_pServer->block( *this ) ) {}
    00125
    00126   if( !m_pServer )
    00127     return;
    00128
    00129   m_pServer->close();
    00130   delete m_pServer;
    00131   m_pServer = 0;
    00132
    00133   QF_STACK_POP
    00134 }

void FIX::HttpServer::onStop | ( |  | ) | `[private]`

Definition at line 148 of file HttpServer.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

Referenced by stop().

    00149 { QF_STACK_PUSH(HttpServer::onStop)
    00150   QF_STACK_POP
    00151 }

void FIX::HttpServer::onTimeout | ( | SocketServer & |  | ) | `[private, virtual]`

Reimplemented from FIX::SocketServer::Strategy.

Definition at line 184 of file HttpServer.cpp.

References onInitialize(), QF_STACK_POP, and QF_STACK_PUSH.

    00185 { QF_STACK_PUSH(HttpServer::onInitialize)
    00186   QF_STACK_POP
    00187 }

void FIX::HttpServer::onWrite | ( | SocketServer & | server,
|  | int | s |
| ) |  |  | `[private, virtual]`

Implements FIX::SocketServer::Strategy.

Definition at line 164 of file HttpServer.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

    00165 { QF_STACK_PUSH(HttpServer::onWrite)
    00166   QF_STACK_POP
    00167 }

void FIX::HttpServer::start | ( |  | ) | throw ( ConfigError, RuntimeError )

Definition at line 94 of file HttpServer.cpp.

References m_settings, m_stop, m_threadid, onConfigure(), onInitialize(), QF_STACK_POP, QF_STACK_PUSH, FIX::Acceptor::start(), startThread(), and FIX::thread_spawn().

Referenced by onStart().

    00095 { QF_STACK_PUSH( Acceptor::start )
    00096
    00097   m_stop = false;
    00098   onConfigure( m_settings );
    00099   onInitialize( m_settings );
    00100
    00101   if( !thread_spawn( &startThread, this, m_threadid ) )
    00102     throw RuntimeError("Unable to spawn thread");
    00103
    00104   QF_STACK_POP
    00105 }

void FIX::HttpServer::startGlobal | ( | const SessionSettings & | s | ) | throw ( ConfigError, RuntimeError )`[static]`

Definition at line 38 of file HttpServer.cpp.

References FIX::HTTP_ACCEPT_PORT.

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

    00040 {
    00041   Locker l( s_mutex );
    00042
    00043   if( !s.get().has(HTTP_ACCEPT_PORT) )
    00044     return;
    00045
    00046   s_count += 1;
    00047   if( !s_pServer )
    00048   {
    00049     s_pServer = new HttpServer( s );
    00050     s_pServer->start();
    00051   }
    00052 }

THREAD_PROC FIX::HttpServer::startThread | ( | void * | p | ) | `[static, private]`

Definition at line 189 of file HttpServer.cpp.

References QF_STACK_CATCH, QF_STACK_POP, QF_STACK_PUSH, and QF_STACK_TRY.

Referenced by start().

    00190 { QF_STACK_TRY
    00191   QF_STACK_PUSH( HttpServer::startThread )
    00192
    00193   HttpServer * pServer = static_cast < HttpServer* > ( p );
    00194   pServer->onStart();
    00195   return 0;
    00196
    00197   QF_STACK_POP
    00198   QF_STACK_CATCH
    00199 }

void FIX::HttpServer::stop | ( |  | ) |

Definition at line 107 of file HttpServer.cpp.

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

Referenced by stopGlobal().

    00108 { QF_STACK_PUSH( HttpServer::stop )
    00109
    00110   if( m_stop ) return;
    00111   m_stop = true;
    00112   onStop();
    00113
    00114   if( m_threadid )
    00115     thread_join( m_threadid );
    00116   m_threadid = 0;
    00117
    00118   QF_STACK_POP
    00119 }

void FIX::HttpServer::stopGlobal | ( |  | ) | `[static]`

Definition at line 54 of file HttpServer.cpp.

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

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

    00055 {
    00056   Locker l( s_mutex );
    00057
    00058   s_count -= 1;
    00059   if( !s_count && s_pServer )
    00060   {
    00061     s_pServer->stop();
    00062     delete s_pServer;
    00063     s_pServer = 0;
    00064   }
    00065 }

## Member Data Documentation

int FIX::HttpServer::m_port`[private]`

Definition at line 68 of file HttpServer.h.

SocketServer* FIX::HttpServer::m_pServer`[private]`

Definition at line 65 of file HttpServer.h.

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

SessionSettings FIX::HttpServer::m_settings`[private]`

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().

thread_id FIX::HttpServer::m_threadid`[private]`

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:

- /home/omiller/Development/autobuild/quickfix/src/C++/HttpServer.h
- /home/omiller/Development/autobuild/quickfix/src/C++/HttpServer.cpp