FIX::HttpServer Class Reference

Basic HTTP Server. More...

`#include <HttpServer.h>`

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

## Public Member Functions

| HttpServer (const SessionSettings &) throw ( ConfigError )
void | start () throw ( ConfigError, RuntimeError )
void | stop ()
Public Member Functions inherited from FIX::SocketServer::Strategy
virtual | ~Strategy ()

## 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

## HttpServer()

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 ) {}
FIX::HttpServer::m_threadid
thread_id m_threadid
Definition: HttpServer.h:67
FIX::HttpServer::m_pServer
SocketServer * m_pServer
Definition: HttpServer.h:65
FIX::HttpServer::m_stop
bool m_stop
Definition: HttpServer.h:69
FIX::HttpServer::m_settings
SessionSettings m_settings
Definition: HttpServer.h:66
FIX::HttpServer::m_port
int m_port
Definition: HttpServer.h:68

## Member Function Documentation

## onConfigure()

void FIX::HttpServer::onConfigure | ( | const SessionSettings & | s | ) |
throw | ( | ConfigError
| ) |  |

private

Definition at line 69 of file HttpServer.cpp.

References FIX::HTTP_ACCEPT_PORT, and m_port.

Referenced by start().

{
m_port = s.get().getInt( HTTP_ACCEPT_PORT );
}
FIX::HTTP_ACCEPT_PORT
const char HTTP_ACCEPT_PORT[]
Definition: SessionSettings.h:126
FIX::HttpServer::m_port
int m_port
Definition: HttpServer.h:68

## onConnect()

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 );
}
FIX::socket_isValid
bool socket_isValid(int socket)
Definition: Utility.cpp:255
FIX::SocketServer::getMonitor
SocketMonitor & getMonitor()
Definition: SocketServer.h:70
FIX::HttpServer::m_pServer
SocketServer * m_pServer
Definition: HttpServer.h:65
FIX::SocketMonitor::drop
bool drop(int socket)
Definition: SocketMonitor.cpp:98

## onData()

bool FIX::HttpServer::onData | ( | SocketServer & | server,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 147 of file HttpServer.cpp.

{
return true;
}

## onDisconnect()

void FIX::HttpServer::onDisconnect | ( | SocketServer & | ,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 152 of file HttpServer.cpp.

{
}

## onError()

void FIX::HttpServer::onError | ( | SocketServer & |  | ) |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 156 of file HttpServer.cpp.

{}

## onInitialize()

void FIX::HttpServer::onInitialize | ( | const SessionSettings & | s | ) |
throw | ( | RuntimeError
| ) |  |

private

Definition at line 75 of file HttpServer.cpp.

References FIX::SocketServer::add(), FIX::IntConvertor::convert(), m_port, and m_pServer.

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 ) );
}
}
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:154
FIX::HttpServer::m_pServer
SocketServer * m_pServer
Definition: HttpServer.h:65
FIX::SocketServer::add
int add(int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0)
Definition: SocketServer.cpp:97
FIX::HttpServer::m_port
int m_port
Definition: HttpServer.h:68

## onPoll()

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;
}
FIX::HttpServer::m_pServer
SocketServer * m_pServer
Definition: HttpServer.h:65
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:148
FIX::HttpServer::m_stop
bool m_stop
Definition: HttpServer.h:69

## onStart()

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;
}
FIX::HttpServer::m_pServer
SocketServer * m_pServer
Definition: HttpServer.h:65
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:148
FIX::SocketServer::close
void close()
Definition: SocketServer.cpp:137
FIX::HttpServer::m_stop
bool m_stop
Definition: HttpServer.h:69

## onStop()

void FIX::HttpServer::onStop | ( |  | ) |

private

Definition at line 131 of file HttpServer.cpp.

Referenced by stop().

{
}

## onTimeout()

void FIX::HttpServer::onTimeout | ( | SocketServer & |  | ) |

private virtual

Reimplemented from FIX::SocketServer::Strategy.

Definition at line 158 of file HttpServer.cpp.

{
}

## onWrite()

void FIX::HttpServer::onWrite | ( | SocketServer & | server,
|  | int | s
| ) |  |

private virtual

Implements FIX::SocketServer::Strategy.

Definition at line 143 of file HttpServer.cpp.

{
}

## start()

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

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");
}
FIX::thread_spawn
bool thread_spawn(THREAD_START_ROUTINE func, void *var, thread_id &thread)
Definition: Utility.cpp:394
FIX::HttpServer::m_threadid
thread_id m_threadid
Definition: HttpServer.h:67
FIX::HttpServer::startThread
static THREAD_PROC startThread(void *p)
Definition: HttpServer.cpp:162
FIX::HttpServer::onConfigure
void onConfigure(const SessionSettings &)
Definition: HttpServer.cpp:69
FIX::HttpServer::onInitialize
void onInitialize(const SessionSettings &)
Definition: HttpServer.cpp:75
FIX::HttpServer::m_stop
bool m_stop
Definition: HttpServer.h:69
FIX::HttpServer::m_settings
SessionSettings m_settings
Definition: HttpServer.h:66

## startGlobal()

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();
}
}
FIX::HttpServer::HttpServer
HttpServer(const SessionSettings &)
Definition: HttpServer.cpp:66
FIX::HttpServer::start
void start()
Definition: HttpServer.cpp:89
FIX::HttpServer::s_mutex
static Mutex s_mutex
Definition: HttpServer.h:71
FIX::HttpServer::s_count
static int s_count
Definition: HttpServer.h:72
FIX::HttpServer::s_pServer
static HttpServer * s_pServer
Definition: HttpServer.h:73
FIX::HTTP_ACCEPT_PORT
const char HTTP_ACCEPT_PORT[]
Definition: SessionSettings.h:126

## startThread()

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;
}
FIX::HttpServer::HttpServer
HttpServer(const SessionSettings &)
Definition: HttpServer.cpp:66

## stop()

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

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;
}
FIX::thread_join
void thread_join(thread_id thread)
Definition: Utility.cpp:415
FIX::HttpServer::m_threadid
thread_id m_threadid
Definition: HttpServer.h:67
FIX::HttpServer::onStop
void onStop()
Definition: HttpServer.cpp:131
FIX::HttpServer::m_stop
bool m_stop
Definition: HttpServer.h:69

## stopGlobal()

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;
}
}
FIX::HttpServer::stop
void stop()
Definition: HttpServer.cpp:99
FIX::HttpServer::s_mutex
static Mutex s_mutex
Definition: HttpServer.h:71
FIX::HttpServer::s_count
static int s_count
Definition: HttpServer.h:72
FIX::HttpServer::s_pServer
static HttpServer * s_pServer
Definition: HttpServer.h:73

## Member Data Documentation

## m_port

int FIX::HttpServer::m_port

private

Definition at line 68 of file HttpServer.h.

Referenced by onConfigure(), and onInitialize().

## m_pServer

SocketServer* FIX::HttpServer::m_pServer

private

Definition at line 65 of file HttpServer.h.

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

## m_settings

SessionSettings FIX::HttpServer::m_settings

private

Definition at line 66 of file HttpServer.h.

Referenced by start().

## m_stop

bool FIX::HttpServer::m_stop

private

Definition at line 69 of file HttpServer.h.

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

## m_threadid

thread_id FIX::HttpServer::m_threadid

private

Definition at line 67 of file HttpServer.h.

Referenced by start(), and stop().

## s_count

int FIX::HttpServer::s_count = 0

static private

Definition at line 72 of file HttpServer.h.

Referenced by stopGlobal().

## s_mutex

Mutex FIX::HttpServer::s_mutex

static private

Definition at line 71 of file HttpServer.h.

Referenced by stopGlobal().

## s_pServer

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:

- HttpServer.h
- HttpServer.cpp