本文整理汇总了C++中server类的典型用法代码示例。如果您正苦于以下问题:C++ server类的具体用法?C++ server怎么用?C++ server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了server类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: shutDown
void shutDown() {
cout << "System shutting down." << endl;
websocket_server.close(currentState.client, 0, "shutdown");
websocket_server.stop();
gpioTerminate();
std::exit(EXIT_SUCCESS);
//system("shutdown -P now");
return;
}
开发者ID:RubberRobot,项目名称:SeniorDesignSuperCar,代码行数:9,代码来源:RoadStarServer.cpp
示例2: add_to_autoload
static bool
add_to_autoload (server& srv, const std::string& world_name)
{
auto& conn = srv.sql ().pop ();
int count = conn.query (
"SELECT count(*) FROM `autoloaded-worlds` WHERE `name`='"
+ world_name + "'").step ().at (0).as_int ();
if (count != 0)
return false;
conn.execute (
"INSERT INTO `autoloaded-worlds` (`name`) VALUES ('"
+ world_name + "')");
srv.sql ().push (conn);
return true;
}
开发者ID:thaingo,项目名称:hCraft,代码行数:16,代码来源:wload.cpp
示例3: report_time
void report_time(const server& s, boost::posix_time::time_duration time)
{
server_times_.update_resp_time(s.get_id(), time.total_microseconds());
uint32_t new_reqs_sec = server_times_.reqs_sec(s);
update_server(s, new_reqs_sec);
}
开发者ID:ghoff,项目名称:accessl,代码行数:7,代码来源:servers.hpp
示例4: remove_from_autoload
static bool
remove_from_autoload (server& srv, const std::string& world_name)
{
auto& conn = srv.sql ().pop ();
int count = conn.query (
"SELECT count(*) FROM `autoload-worlds` WHERE `name`='"
+ world_name + "'").step ().at (0).as_int ();
if (count == 0)
return false;
conn.execute (
"DELETE FROM `autoload-worlds` WHERE `name`='"
+ world_name + "'");
srv.sql ().push (conn);
return true;
}
开发者ID:hCraft,项目名称:hCraft,代码行数:16,代码来源:wunload.cpp
示例5: report_timeout
void report_timeout(const server& s)
{
server_times_.update_resp_timeout(s.get_id());
uint32_t new_reqs_sec = server_times_.reqs_sec(s);
update_server(s, new_reqs_sec);
}
开发者ID:ghoff,项目名称:accessl,代码行数:7,代码来源:servers.hpp
示例6: switch
void _test_websocket_server::send_msg(const test_websocket_msg& msg)
{
// Wait for the websocket server to be initialized.
pplx::task<void>(m_server_connected).wait();
const auto& data = msg.data();
auto flags = websocketpp::frame::opcode::close;
switch (msg.msg_type())
{
case test_websocket_message_type::WEB_SOCKET_UTF8_MESSAGE_TYPE:
flags = websocketpp::frame::opcode::text; // WebSocket::FRAME_FLAG_FIN | WebSocket::FRAME_OP_TEXT;
break;
case test_websocket_message_type::WEB_SOCKET_BINARY_MESSAGE_TYPE:
flags = websocketpp::frame::opcode::binary; // WebSocket::FRAME_FLAG_FIN | WebSocket::FRAME_OP_BINARY;
break;
case test_websocket_message_type::WEB_SOCKET_CLOSE_TYPE:
flags = websocketpp::frame::opcode::close; // WebSocket::FRAME_OP_CLOSE;
break;
case test_websocket_message_type::WEB_SOCKET_UTF8_FRAGMENT_TYPE:
case test_websocket_message_type::WEB_SOCKET_BINARY_FRAGMENT_TYPE:
default:
throw std::runtime_error("invalid message type");
}
std::string strmsg(data.begin(), data.end());
if (msg.msg_type() == test_websocket_message_type::WEB_SOCKET_CLOSE_TYPE)
{
close(strmsg);
}
else
{
// std::cerr << "Sending message from server: " << strmsg << std::endl;
m_srv.send(m_con, strmsg, flags);
}
}
开发者ID:PKRoma,项目名称:cpprestsdk,代码行数:35,代码来源:test_websocket_server.cpp
示例7: senddata
int senddata( const server &sv, const char *buffer, u32 len ) {
sockaddr_in to = ( sv.tosockaddr() );
int bytes = sendto( mSocket, buffer, len, 0, (sockaddr *)&to, sizeof( to ) );
if ( bytes > 0 )
UPLOAD.update( bytes + UDP_HEADER_SIZE );
return ( bytes );
}
开发者ID:KVoksel,项目名称:t1master,代码行数:8,代码来源:t1master.cpp
示例8: update_server
void update_server(const server& s, uint32_t new_reqs_sec)
{
server_tree_iter_map::const_iterator it = servers_map_.find(s.get_id());
if (it != servers_map_.end())
{
servers_.change_count(it->second, new_reqs_sec);
}
}
开发者ID:ghoff,项目名称:accessl,代码行数:8,代码来源:servers.hpp
示例9: run_server_test
/* Run server and return output test rig */
std::string run_server_test(server& s, std::string input) {
server::connection_ptr con;
std::stringstream output;
s.register_ostream(&output);
s.clear_access_channels(websocketpp::log::alevel::all);
s.clear_error_channels(websocketpp::log::elevel::all);
con = s.get_connection();
con->start();
std::stringstream channel;
channel << input;
channel >> *con;
return output.str();
}
开发者ID:CodeShark,项目名称:ripple-lib-cpp,代码行数:19,代码来源:server.cpp
示例10: speedometer
void * speedometer(void * argument) {
const timespec waitTime = { 0, MOUSE_SAMPLE_RATE };
cout << waitTime.tv_nsec << " " << waitTime.tv_sec << endl;
int fd;
struct input_event ie;
if ((fd = open(MOUSE_FILE, O_RDONLY)) == -1) {
perror("opening device");
// exit(1);
}
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
int counter = 0;
while (true) {
//cout << "hello from the speedometer" << endl;
nanosleep(&waitTime, NULL);
//cout << "wait over" << endl;
counter = 0;
while (read(fd, &ie, sizeof(struct input_event)) != -1) {
//cout << "reading mouse" << endl;
if ((ie.type == 2) && (ie.code == 8)) {
counter++;
// cout << "new mouse event " << counter << endl;
}
}
//cout << "aquireing mutex" << endl;
//cout << "aquired mutex" << endl;
currentState.speed = (counter * MOUSE_MM_PER_CLICK) * 10; //mm/s
currentState.distanceTraveled = counter * MOUSE_MM_PER_CLICK; //mm.
//cout << "speed: " << currentState.speed << " distance: " << currentState.distanceTraveled << endl;
ptree answerJson;
stringstream jsonWriteStream;
answerJson.put("speed", currentState.speed);
answerJson.put("distanceTraveled", currentState.distanceTraveled);
write_json(jsonWriteStream, answerJson);
//cout << "sending speedometer" << endl;
//pthread_mutex_lock(&watchDog_mutex);
if (currentState.connected) {
websocket_server.send(currentState.client, jsonWriteStream.str(),
websocketpp::frame::opcode::text);
}
//pthread_mutex_unlock(&watchDog_mutex);
//cout << "released mutex" << endl;
}
return 0;
}
开发者ID:RubberRobot,项目名称:SeniorDesignSuperCar,代码行数:55,代码来源:RoadStarServer.cpp
示例11: do_accept
void worker::do_accept(tcp::acceptor& acceptor, server& srv) {
while (acceptor.is_open()) {
bs::error_code ec;
// get an io service to use for a new client, we pick them via round robin
auto& worker = srv.impl()->get_worker();
auto& iosvc = worker.io_service();
auto new_session = std::make_shared<session>(srv, iosvc);
acceptor.async_accept(new_session->socket(), bfa::yield[ec]);
if (!ec) {
worker.add_session(new_session);
worker.m_new_session_cv.notify_one();
}
}
}
开发者ID:apohl79,项目名称:petrel,代码行数:14,代码来源:worker.cpp
示例12: srv
/*
* Constructs a new IRC client on top of hte specified socket and event base.
*/
irc_client::irc_client (server &srv, struct event_base *evbase, int sock)
: srv (srv), log (srv.get_logger ())
{
this->evbase = evbase;
this->sock = sock;
this->bufev = bufferevent_socket_new (evbase, sock, BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb (this->bufev, &hCraft::irc_client::handle_read,
&hCraft::irc_client::handle_write, &hCraft::irc_client::handle_event, this);
bufferevent_enable (this->bufev, EV_READ | EV_WRITE);
this->total_read = 0;
this->fail = false;
this->connected = false;
}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:19,代码来源:irc.cpp
示例13: validate
bool validate(server & s, connection_hdl hdl) {
server::connection_ptr con = s.get_con_from_hdl(hdl);
std::cout << "Cache-Control: " << con->get_request_header("Cache-Control") << std::endl;
const std::vector<std::string> & subp_requests = con->get_requested_subprotocols();
std::vector<std::string>::const_iterator it;
for (it = subp_requests.begin(); it != subp_requests.end(); ++it) {
std::cout << "Requested: " << *it << std::endl;
}
if (subp_requests.size() > 0) {
con->select_subprotocol(subp_requests[0]);
}
return true;
}
开发者ID:CloudXNS,项目名称:LDNS-Selector-Windows,代码行数:18,代码来源:subprotocol_server.cpp
示例14: connection
/// Constructor
connection(
server& parent,
tcp::endpoint const& ep,
tcp::socket&& sock)
: log_(parent.log_)
, ep_(ep)
, ws_(std::move(sock))
, timer_(ws_.get_io_service(), (clock_type::time_point::max)())
, strand_(ws_.get_io_service())
, id_([]
{
static std::atomic<std::size_t> n{0};
return ++n;
}())
{
// Invoke the callback for new connections if set.
// This allows the settings on the websocket stream
// to be adjusted. For example to turn compression
// on or off or adjust the read and write buffer sizes.
//
if(parent.mod_)
parent.mod_(ws_);
}
开发者ID:vinniefalco,项目名称:Beast,代码行数:24,代码来源:websocket_server_async.cpp
示例15: _init_sql_tables
static void
_init_sql_tables (world *w, server &srv)
{
soci::session sql (srv.sql_pool ());
// block history table
sql.once <<
"CREATE TABLE IF NOT EXISTS `block_history_" << w->get_name () << "` ("
"`x` INT, `y` INT, `z` INT, " // pos
"`old_id` SMALLINT UNSIGNED, `old_meta` TINYINT UNSIGNED, `old_ex` TINYINT UNSIGNED, " // old value
"`new_id` SMALLINT UNSIGNED, `new_meta` TINYINT UNSIGNED, `new_ex` TINYINT UNSIGNED, " // new value
"`pid` INTEGER UNSIGNED, `time` BIGINT UNSIGNED)";
{
// create index
int c;
sql << "SELECT Count(1) IndexIsThere FROM INFORMATION_SCHEMA.STATISTICS "
"WHERE table_schema=DATABASE() AND table_name='block_history_" << w->get_name ()
<< "' AND index_name='bh_index_" << w->get_name () << "'", soci::into (c);
if (c == 0)
sql.once <<
"CREATE INDEX `bh_index_" << w->get_name () << "` ON `block_history_"
<< w->get_name () << "` (`x`, `y`, `z`)";
}
}
开发者ID:projectapex,项目名称:hCraft,代码行数:24,代码来源:world.cpp
示例16: handle_request
void handle_request( const fc::http::request& r, const fc::http::server::response& s )
{
//ilog( "handle request ${r}", ("r",r.path) );
s.add_header( "Connection", "close" );
try {
auto pos = r.path.find( "/", 1 );
auto first_dir = r.path.substr(1,pos);
//ilog( "command: ${command}", ("command",first_dir) );
if( first_dir == "pending" )
{
s.set_status( fc::http::reply::OK );
auto pending_json = fc::json::to_string( _pending );
s.set_length( pending_json.size() );
s.write( pending_json.c_str(), pending_json.size() );
}
else if( first_dir == "update_record" )
{
FC_ASSERT( r.body.size() );
std::string str(r.body.data(),r.body.size());
auto rec = fc::json::from_string( str ).as<signed_name_record>();
_self->update_record( rec );
s.set_status( fc::http::reply::RecordCreated );
s.set_length( 12 );
s.write( "Record Created", 12 );
}
else if( first_dir == "fetch_by_name/" )
{
auto name = r.path.substr( pos+1, std::string::npos );
auto record = _self->fetch_record( name );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( record );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else if( first_dir == "fetch_by_key/" )
{
auto key = r.path.substr( pos+1, std::string::npos );
auto record = _self->fetch_record_by_key( key );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( record );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else if( first_dir == "store_key/" )
{
auto name = r.path.substr( pos+1, std::string::npos );
std::string str(r.body.data(),r.body.size());
auto rec = fc::json::from_string( str ).as<stored_key>();
_self->store_key( name, rec );
s.set_status( fc::http::reply::RecordCreated );
s.set_length( 12 );
s.write( "Record Created", 12 );
}
else if( first_dir == "fetch_key/" )
{
auto user_name = r.path.substr( pos+1, std::string::npos );
auto key_data = _self->fetch_key( user_name );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( key_data );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else if( first_dir == "fetch_block/" )
{
auto block_num = r.path.substr( pos+1, std::string::npos );
auto blk = _self->fetch_block( fc::to_uint64( block_num ) );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( blk );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else
{
auto dotpos = r.path.find( ".." );
FC_ASSERT( dotpos == std::string::npos );
auto filename = _data_dir / r.path.substr(1,std::string::npos);
if( fc::exists( filename ) )
{
FC_ASSERT( !fc::is_directory( filename ) );
auto file_size = fc::file_size( filename );
FC_ASSERT( file_size != 0 );
fc::file_mapping fm( filename.generic_string().c_str(), fc::read_only );
fc::mapped_region mr( fm, fc::read_only, 0, fc::file_size( filename ) );
s.set_status( fc::http::reply::OK );
s.set_length( file_size );
s.write( (const char*)mr.get_address(), mr.get_size() );
return;
}
s.set_status( fc::http::reply::NotFound );
s.set_length( 9 );
s.write( "Not Found", 9 );
}
//.........这里部分代码省略.........
开发者ID:HackFisher,项目名称:bitshares_snapshot,代码行数:101,代码来源:kid_server.cpp
示例17: main
int main(int argc, char **argv) {
/* Program start */
/*
*
*
*/
int i;
int port = 5000;
char *bind = (char *)"0.0.0.0";
bool daemon = false;
/* Help info */
for(i=0;i<argc;i++) {
if(strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0) {
out("Usage: cframes [options]\n");
out("\t-p, --port PORT\tBind server socket to specified PORT\n");
out("\t\t\tDefault: 5000\n");
out("\t-b, --bind IP\tBind server to specified IP\n");
out("\t\t\tDefault: 0.0.0.0\n");
out("\t-d, --daemon\tForks server process\n");
out("\t-h, --help\tDisplay this help and exit\n");
out("\t-v, --version\tDisplay version information and exit\n");
return 0;
}
}
/* Version info */
for(i=0;i<argc;i++) {
if(strcmp(argv[i],"-v")==0||strcmp(argv[i],"--version")==0) {
out("cframes 1.0.1\n");
return 0;
}
}
/* Program arguments */
for(i=0;i<argc;i++) {
if(strcmp(argv[i],"-p")==0||strcmp(argv[i],"--port")==0) {
port = (int)argv[i+1];
}
if(strcmp(argv[i],"-b")==0||strcmp(argv[i],"--bind")==0) {
bind = (char *)argv[i+1];
}
if(strcmp(argv[i],"-d")==0||strcmp(argv[i],"--daemon")==0) {
daemon = true;
}
}
/* Start the server */
out("Starting cframes server...........");
s.start(port);
out("OK\n");
out("Listening on http://");
out(bind);out(":");out("5000");out("\n\n");
/* Single-threaded forever loop to handle requests -- NOTE: eventually will have a daemon option -d */
for(i=0;i<50;i++) { www(); }
/* Stop the server */
s.stop();
return 0;
}
开发者ID:oeo4b,项目名称:Cframes,代码行数:62,代码来源:main.cpp
示例18: compare_port
int compare_port(const server& other) const {
return get_port() - other.get_port();
}
开发者ID:ghoff,项目名称:accessl,代码行数:3,代码来源:servers.hpp
示例19: on_open
void on_open(connection_hdl hdl) {
holdThreads[hdl]=0;//just an example. Creates a new item for every connection. Gets deleted on close
m_server.send(hdl,"message", websocketpp::frame::opcode::text);
}
开发者ID:phillyfan1138,项目名称:MinimalWS,代码行数:4,代码来源:main.cpp
示例20: run
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.run();
}
开发者ID:phillyfan1138,项目名称:MinimalWS,代码行数:5,代码来源:main.cpp
注:本文中的server类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论