• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Error

            C++博客 首頁 新隨筆 聯系 聚合 管理
              217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks
            // learn_boost_asio.cpp : 定義控制臺應用程序的入口點。
            //
            #include "stdafx.h"
            #include <iostream>
            #include <algorithm>
            #include <memory>
            #include <boost/asio.hpp>
            #include <boost/timer.hpp>
            #include <boost/lambda/lambda.hpp>
            #include <boost/function.hpp>
            #include <boost/bind.hpp>
            namespace asio = boost::asio;
            namespace posix_time = boost::posix_time ;
            // 1.同步定時器使用
            void LeanrHowToUseSynchronouslyTimer()
            {
            asio::io_service io;
            asio::deadline_timer deadLineTimer(io, posix_time::seconds(3));
            boost::timer timerTestDeadLineTimer;
            timerTestDeadLineTimer.restart();
            deadLineTimer.wait();
            double dTime = timerTestDeadLineTimer.elapsed();
            std::cout << dTime << std::endl;
            }
            ////////~
            // 2.異步定時器使用
            class CSomeObject
            {
            public:
            CSomeObject(asio::io_service& ioService) :
               m_deadLineTimer(ioService)
            {
            }
            public:
            void Test()
            {
            m_deadLineTimer.expires_from_now(boost::posix_time::seconds(3));
            m_timerTestDeadTimer.restart();
            m_deadLineTimer.async_wait(
            boost::bind(&CSomeObject::TimerHandler, this, asio::placeholders::error));
            }
            public:
            void TimerHandler(const boost::system::error_code&)
            {
            double dTime = m_timerTestDeadTimer.elapsed();
            std::cout << "time passed: " << dTime << std::endl;
            }
            private:
            boost::timer m_timerTestDeadTimer;
            asio::deadline_timer m_deadLineTimer;
            };
            void LearnHowToUseAsynchronouslyTimer()
            {
            asio::io_service ioService;
            CSomeObject obj(ioService);
            obj.Test();
            asio::io_service::work* pWork = new asio::io_service::work(ioService);
            std::auto_ptr<asio::io_service::work> spWork(pWork);
            ioService.run();
            //spWork.reset(); // Allow run() to exit. 
            }
            //////////////////////////////////////////
            int _tmain(int argc, _TCHAR* argv[])
            {
            LearnHowToUseAsynchronouslyTimer();
            return 0;
            }
            posted on 2013-03-08 18:04 Enic 閱讀(797) 評論(0)  編輯 收藏 引用 所屬分類: boost::asio
            青青久久精品国产免费看| 浪潮AV色综合久久天堂| 久久亚洲国产欧洲精品一| 91精品无码久久久久久五月天| 精品久久久久久中文字幕| 国产精品内射久久久久欢欢 | 久久久无码精品亚洲日韩按摩 | 久久丝袜精品中文字幕| 亚洲午夜久久久久久久久电影网 | 亚洲乱码中文字幕久久孕妇黑人| 99久久久国产精品免费无卡顿| 久久中文娱乐网| 亚洲中文久久精品无码ww16| 99久久精品免费看国产免费| 国产精品99久久久久久宅男小说| 国产精品久久久久久久| 亚洲国产精品狼友中文久久久| www久久久天天com| 精品国产乱码久久久久软件| 99久久精品免费看国产一区二区三区| 日产精品久久久久久久| 一本大道加勒比久久综合| 久久精品天天中文字幕人妻| 久久久久久久综合日本| 99久久无色码中文字幕| 久久精品国产亚洲AV久| 久久夜色撩人精品国产小说| 亚洲欧美精品伊人久久| 久久人人爽人人爽人人AV| 日本WV一本一道久久香蕉| 欧美亚洲另类久久综合婷婷| 久久综合久久综合久久| 72种姿势欧美久久久久大黄蕉| 亚洲欧美日韩中文久久| 久久婷婷五月综合成人D啪| 理论片午午伦夜理片久久| 久久精品女人天堂AV麻| 久久无码精品一区二区三区| 国产精品欧美久久久久天天影视| 97精品伊人久久久大香线蕉| 色偷偷888欧美精品久久久|