当前位置: 首页>>代码示例>>C++>>正文


C++ server类代码示例

本文整理汇总了C++中server的典型用法代码示例。如果您正苦于以下问题:C++ server类的具体用法?C++ server怎么用?C++ server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的server类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。