Merge remote branch 'peter/network-streaming' into network-streaming-vcpp2010

This commit is contained in:
Tobias Oberstein
2011-10-28 12:44:13 +02:00
4 changed files with 85 additions and 53 deletions

View File

@@ -39,6 +39,13 @@
namespace websocketpp {
/* policies to abstract out
- random number generation
- utf8 validation
*/
class frame {
public:
enum opcode_s {

View File

@@ -30,6 +30,8 @@
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
using websocketpp::server;
@@ -42,7 +44,19 @@ server::server(boost::asio::io_service& io_service,
m_max_message_size(DEFAULT_MAX_MESSAGE_SIZE),
m_io_service(io_service),
m_acceptor(io_service, endpoint),
m_def_con_handler(defc) {}
m_def_con_handler(defc),
m_desc("test") {
m_desc.add_options()
("help", "produce help message")
("intval",po::value<int>(), "set compression level")
;
}
void server::parse_command_line(int ac, char* av[]) {
po::store(po::parse_command_line(ac,av, m_desc),m_vm);
po::notify(m_vm);
}
void server::add_host(std::string host) {
m_hosts.insert(host);

View File

@@ -30,6 +30,8 @@
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
#include <set>
@@ -60,61 +62,66 @@ private:
};
class server : public boost::enable_shared_from_this<server> {
public:
server(boost::asio::io_service& io_service,
const tcp::endpoint& endpoint,
connection_handler_ptr defc);
// creates a new session object and connects the next websocket
// connection to it.
void start_accept();
// INTERFACE FOR LOCAL APPLICATIONS
public:
server(boost::asio::io_service& io_service,
const tcp::endpoint& endpoint,
connection_handler_ptr defc);
// creates a new session object and connects the next websocket
// connection to it.
void start_accept();
// INTERFACE FOR LOCAL APPLICATIONS
// Add or remove a host string (host:port) to the list of acceptable
// hosts to accept websocket connections from. Additions/deletions here
// only affect new connections.
void add_host(std::string host);
void remove_host(std::string host);
void set_max_message_size(uint64_t val);
// Test methods determine if a message of the given level should be
// written. elog shows all values above the level set. alog shows only
// the values explicitly set.
bool test_elog_level(uint16_t level);
void set_elog_level(uint16_t level);
bool test_alog_level(uint16_t level);
void set_alog_level(uint16_t level);
void unset_alog_level(uint16_t level);
// Add or remove a host string (host:port) to the list of acceptable
// hosts to accept websocket connections from. Additions/deletions here
// only affect new connections.
void add_host(std::string host);
void remove_host(std::string host);
void set_max_message_size(uint64_t val);
// Test methods determine if a message of the given level should be
// written. elog shows all values above the level set. alog shows only
// the values explicitly set.
bool test_elog_level(uint16_t level);
void set_elog_level(uint16_t level);
bool test_alog_level(uint16_t level);
void set_alog_level(uint16_t level);
void unset_alog_level(uint16_t level);
void parse_command_line(int ac, char* av[]);
// INTERFACE FOR SESSIONS
// INTERFACE FOR SESSIONS
// Check if this server will respond to this host.
bool validate_host(std::string host);
// Check if message size is within server's acceptable parameters
bool validate_message_size(uint64_t val);
// write to the server's logs
void log(std::string msg,uint16_t level = LOG_ERROR);
void access_log(std::string msg,uint16_t level);
private:
// if no errors starts the session's read loop and returns to the
// start_accept phase.
void handle_accept(server_session_ptr session,
const boost::system::error_code& error);
private:
uint16_t m_elog_level;
uint16_t m_alog_level;
// Check if this server will respond to this host.
bool validate_host(std::string host);
// Check if message size is within server's acceptable parameters
bool validate_message_size(uint64_t val);
// write to the server's logs
void log(std::string msg,uint16_t level = LOG_ERROR);
void access_log(std::string msg,uint16_t level);
private:
// if no errors starts the session's read loop and returns to the
// start_accept phase.
void handle_accept(server_session_ptr session,
const boost::system::error_code& error);
private:
uint16_t m_elog_level;
uint16_t m_alog_level;
std::set<std::string> m_hosts;
uint64_t m_max_message_size;
boost::asio::io_service& m_io_service;
tcp::acceptor m_acceptor;
connection_handler_ptr m_def_con_handler;
std::set<std::string> m_hosts;
uint64_t m_max_message_size;
boost::asio::io_service& m_io_service;
tcp::acceptor m_acceptor;
connection_handler_ptr m_def_con_handler;
po::options_description m_desc;
po::variables_map m_vm;
};
}

View File

@@ -69,6 +69,7 @@
B6DF1CDE1435EDF00029A1B1 /* libwebsocketpp.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B6DF1C721434A8280029A1B1 /* libwebsocketpp.dylib */; };
B6DF1CE21435F1860029A1B1 /* libboost_system.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B6DF1CE11435F1860029A1B1 /* libboost_system.dylib */; };
B6DF1CE41435F8250029A1B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6DF1CE31435F8250029A1B1 /* Foundation.framework */; };
B6FE8CEC145A0F1900B32547 /* libboost_program_options.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -167,6 +168,7 @@
B6DF1CE11435F1860029A1B1 /* libboost_system.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_system.dylib; path = usr/local/lib/libboost_system.dylib; sourceTree = SDKROOT; };
B6DF1CE31435F8250029A1B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
B6FE8CE2144DE17F00B32547 /* readme.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = readme.txt; sourceTree = "<group>"; };
B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_program_options.dylib; path = usr/local/lib/libboost_program_options.dylib; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -200,6 +202,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B6FE8CEC145A0F1900B32547 /* libboost_program_options.dylib in Frameworks */,
B682888D1437464A002BA48B /* libboost_random.dylib in Frameworks */,
B6DF1CC11434AF6A0029A1B1 /* libboost_date_time.dylib in Frameworks */,
B6DF1CC21434AF6A0029A1B1 /* libboost_regex.dylib in Frameworks */,
@@ -235,6 +238,7 @@
B6DF1C451434A5940029A1B1 = {
isa = PBXGroup;
children = (
B6FE8CEB145A0F1900B32547 /* libboost_program_options.dylib */,
B6CF182B1437C3CA009295BE /* libboost_system.dylib */,
B682888E14374689002BA48B /* libboost_thread.dylib */,
B682888C1437464A002BA48B /* libboost_random.dylib */,