Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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]

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

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

◆ HttpServer()

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

Definition at line 66 of file HttpServer.cpp.

67 : m_pServer( 0 ), m_settings( settings ), m_threadid( 0 ), m_port( 0 ), m_stop( false ) {}
SessionSettings m_settings
Definition: HttpServer.h:66
SocketServer * m_pServer
Definition: HttpServer.h:65
thread_id m_threadid
Definition: HttpServer.h:67

Member Function Documentation

◆ onConfigure()

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

Definition at line 69 of file HttpServer.cpp.

71 {
72  m_port = s.get().getInt( HTTP_ACCEPT_PORT );
73 }
const char HTTP_ACCEPT_PORT[]

References FIX::HTTP_ACCEPT_PORT.

Referenced by start().

◆ onConnect()

void FIX::HttpServer::onConnect ( SocketServer server,
int  a,
int  s 
)
privatevirtual

Implements FIX::SocketServer::Strategy.

Definition at line 135 of file HttpServer.cpp.

136 {
137  if ( !socket_isValid( s ) ) return;
138  HttpConnection connection( s );
139  while( connection.read() ) {}
140  m_pServer->getMonitor().drop( s );
141 }
bool drop(int socket)
SocketMonitor & getMonitor()
Definition: SocketServer.h:70
bool socket_isValid(int socket)
Definition: Utility.cpp:277

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

◆ onData()

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

Implements FIX::SocketServer::Strategy.

Definition at line 147 of file HttpServer.cpp.

148 {
149  return true;
150 }

◆ onDisconnect()

void FIX::HttpServer::onDisconnect ( SocketServer ,
int  s 
)
privatevirtual

Implements FIX::SocketServer::Strategy.

Definition at line 152 of file HttpServer.cpp.

153 {
154 }

◆ onError()

void FIX::HttpServer::onError ( SocketServer )
privatevirtual

Implements FIX::SocketServer::Strategy.

Definition at line 156 of file HttpServer.cpp.

156 {}

◆ onInitialize()

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

Definition at line 75 of file HttpServer.cpp.

77 {
78  try
79  {
80  m_pServer = new SocketServer( 1 );
81  m_pServer->add( m_port, true, false, 0, 0 );
82  }
83  catch( std::exception& )
84  {
85  throw RuntimeError( "Unable to create, bind, or listen to port " + IntConvertor::convert( (unsigned short)m_port ) );
86  }
87 }
int add(int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0)
static std::string convert(signed_int value)

References FIX::IntConvertor::convert().

Referenced by start().

◆ onPoll()

bool FIX::HttpServer::onPoll ( )
private

Definition at line 122 of file HttpServer.cpp.

123 {
124  if( !m_pServer || m_stop )
125  return false;
126 
127  m_pServer->block( *this, true );
128  return true;
129 }
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)

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

◆ onStart()

void FIX::HttpServer::onStart ( )
private

Definition at line 110 of file HttpServer.cpp.

111 {
112  while ( !m_stop && m_pServer && m_pServer->block( *this ) ) {}
113 
114  if( !m_pServer )
115  return;
116 
117  m_pServer->close();
118  delete m_pServer;
119  m_pServer = 0;
120 }

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

Referenced by startThread().

◆ onStop()

void FIX::HttpServer::onStop ( )
private

Definition at line 131 of file HttpServer.cpp.

132 {
133 }

Referenced by stop().

◆ onTimeout()

void FIX::HttpServer::onTimeout ( SocketServer )
privatevirtual

Reimplemented from FIX::SocketServer::Strategy.

Definition at line 158 of file HttpServer.cpp.

159 {
160 }

◆ onWrite()

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

Implements FIX::SocketServer::Strategy.

Definition at line 143 of file HttpServer.cpp.

144 {
145 }

◆ start()

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

Definition at line 89 of file HttpServer.cpp.

90 {
91  m_stop = false;
94 
95  if( !thread_spawn( &startThread, this, m_threadid ) )
96  throw RuntimeError("Unable to spawn thread");
97 }
void onConfigure(const SessionSettings &)
Definition: HttpServer.cpp:69
void onInitialize(const SessionSettings &)
Definition: HttpServer.cpp:75
static THREAD_PROC startThread(void *p)
Definition: HttpServer.cpp:162
bool thread_spawn(THREAD_START_ROUTINE func, void *var, thread_id &thread)
Definition: Utility.cpp:416

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

◆ startGlobal()

void FIX::HttpServer::startGlobal ( const SessionSettings s)
throw ( ConfigError,
RuntimeError
)
static

Definition at line 37 of file HttpServer.cpp.

39 {
40  Locker l( s_mutex );
41 
42  if( !s.get().has(HTTP_ACCEPT_PORT) )
43  return;
44 
45  s_count += 1;
46  if( !s_pServer )
47  {
48  s_pServer = new HttpServer( s );
49  s_pServer->start();
50  }
51 }
static int s_count
Definition: HttpServer.h:72
HttpServer(const SessionSettings &)
Definition: HttpServer.cpp:66
static HttpServer * s_pServer
Definition: HttpServer.h:73
static Mutex s_mutex
Definition: HttpServer.h:71

References FIX::HTTP_ACCEPT_PORT.

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

◆ startThread()

THREAD_PROC FIX::HttpServer::startThread ( void *  p)
staticprivate

Definition at line 162 of file HttpServer.cpp.

163 {
164  HttpServer * pServer = static_cast < HttpServer* > ( p );
165  pServer->onStart();
166  return 0;
167 }

References onStart().

Referenced by start().

◆ stop()

void FIX::HttpServer::stop ( )

Definition at line 99 of file HttpServer.cpp.

100 {
101  if( m_stop ) return;
102  m_stop = true;
103  onStop();
104 
105  if( m_threadid )
107  m_threadid = 0;
108 }
void thread_join(thread_id thread)
Definition: Utility.cpp:437

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

Referenced by stopGlobal().

◆ stopGlobal()

void FIX::HttpServer::stopGlobal ( )
static

Definition at line 53 of file HttpServer.cpp.

54 {
55  Locker l( s_mutex );
56 
57  s_count -= 1;
58  if( !s_count && s_pServer )
59  {
60  s_pServer->stop();
61  delete s_pServer;
62  s_pServer = 0;
63  }
64 }

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

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

Member Data Documentation

◆ m_port

int FIX::HttpServer::m_port
private

Definition at line 68 of file HttpServer.h.

◆ m_pServer

SocketServer* FIX::HttpServer::m_pServer
private

Definition at line 65 of file HttpServer.h.

Referenced by onConnect(), 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
staticprivate

Definition at line 72 of file HttpServer.h.

Referenced by stopGlobal().

◆ s_mutex

Mutex FIX::HttpServer::s_mutex
staticprivate

Definition at line 71 of file HttpServer.h.

Referenced by stopGlobal().

◆ s_pServer

HttpServer * FIX::HttpServer::s_pServer = 0
staticprivate

Definition at line 73 of file HttpServer.h.

Referenced by stopGlobal().


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

Generated on Wed Nov 24 2021 09:55:53 for QuickFIX by doxygen 1.9.1 written by Dimitri van Heesch, © 1997-2001