上一篇分析MessagePumpForUI,参考chromium之message_pump_win之二
MessagePumpForIO,同MessagePumpForUI,也是要实现三个函数
  // MessagePump methods:
virtual void ScheduleWork();
virtual void ScheduleDelayedWork(const Time& delayed_work_time); virtual void DoRunLoop();

先看看典型用法

第一种用法是不需要读取数据到buffer,因此所有的清理工作可以交给message pump

第二种用法是需要读取buffer,需要手动delete IOContext

第三种用法是在第二种的基础上,析构函数等待所有的IO结束

  // Clients interested in receiving OS notifications when asynchronous IO
// operations complete should implement this interface and register themselves
// with the message pump.
//
// Typical use #1:
// // Use only when there are no user's buffers involved on the actual IO,
// // so that all the cleanup can be done by the message pump.
// class MyFile : public IOHandler {
// MyFile() {
// ...
// context_ = new IOContext;
// context_->handler = this;
// message_pump->RegisterIOHandler(file_, this);
// }
// ~MyFile() {
// if (pending_) {
// // By setting the handler to NULL, we're asking for this context
// // to be deleted when received, without calling back to us.
// context_->handler = NULL;
// } else {
// delete context_;
// }
// }
// virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered,
// DWORD error) {
// pending_ = false;
// }
// void DoSomeIo() {
// ...
// // The only buffer required for this operation is the overlapped
// // structure.
// ConnectNamedPipe(file_, &context_->overlapped);
// pending_ = true;
// }
// bool pending_;
// IOContext* context_;
// HANDLE file_;
// };
//
// Typical use #2:
// class MyFile : public IOHandler {
// MyFile() {
// ...
// message_pump->RegisterIOHandler(file_, this);
// }
// // Plus some code to make sure that this destructor is not called
// // while there are pending IO operations.
// ~MyFile() {
// }
// virtual void OnIOCompleted(IOContext* context, DWORD bytes_transfered,
// DWORD error) {
// ...
// delete context;
// }
// void DoSomeIo() {
// ...
// IOContext* context = new IOContext;
// // This is not used for anything. It just prevents the context from
// // being considered "abandoned".
// context->handler = this;
// ReadFile(file_, buffer, num_bytes, &read, &context->overlapped);
// }
// HANDLE file_;
// };
//
// Typical use #3:
// Same as the previous example, except that in order to deal with the
// requirement stated for the destructor, the class calls WaitForIOCompletion
// from the destructor to block until all IO finishes.
// ~MyFile() {
// while(pending_)
// message_pump->WaitForIOCompletion(INFINITE, this);
// }
//

来来来,上代码

1)have_work_ = 1;

2)通知MessagePump 工作

void MessagePumpForIO::ScheduleWork() {
if (InterlockedExchange(&have_work_, ))
return; // Someone else continued the pumping. // Make sure the MessagePump does some work for us.
BOOL ret = PostQueuedCompletionStatus(port_, ,
reinterpret_cast<ULONG_PTR>(this),
reinterpret_cast<OVERLAPPED*>(this));
DCHECK(ret);
} void MessagePumpForIO::ScheduleDelayedWork(const Time& delayed_work_time) {
// We know that we can't be blocked right now since this method can only be
// called on the same thread as Run, so we only need to update our record of
// how long to sleep when we do sleep.
delayed_work_time_ = delayed_work_time;
}

最后一个

void MessagePumpForIO::DoRunLoop() {
for (;;) {
// If we do any work, we may create more messages etc., and more work may
// possibly be waiting in another task group. When we (for example)
// WaitForIOCompletion(), there is a good chance there are still more
// messages waiting. On the other hand, when any of these methods return
// having done no work, then it is pretty unlikely that calling them
// again quickly will find any work to do. Finally, if they all say they
// had no work, then it is a good time to consider sleeping (waiting) for
// more work. bool more_work_is_plausible = state_->delegate->DoWork();
if (state_->should_quit)
break; more_work_is_plausible |= WaitForIOCompletion(, NULL);
if (state_->should_quit)
break; more_work_is_plausible |=
state_->delegate->DoDelayedWork(&delayed_work_time_);
if (state_->should_quit)
break; if (more_work_is_plausible)
continue; more_work_is_plausible = state_->delegate->DoIdleWork();
if (state_->should_quit)
break; if (more_work_is_plausible)
continue; WaitForWork(); // Wait (sleep) until we have work to do again.
}
}

chromium之message_pump_win之三的更多相关文章

  1. chromium之message_pump_win之二

    接下来分析 MessagePumpForUI上一篇分析MessagePumpWin,可以参考chromium之message_pump_win之一 根据对MessagePumpWin的分析,Messa ...

  2. chromium之message_pump_win之一

    写了22篇博文,终于到这里了———— MessagePumpWin!!! MessagePumpWin这个类还是挺复杂的,可以分成好几部分.接下来分块分析 从介绍看,MessagePumpWin 是M ...

  3. chromium之MessageLoop浅析

    对chromium的MessageLoop非常感兴趣,接下来会详细分析Windows平台的具体实现. 代码版本:chromium-4.0.210.0_p26329 先看一下依赖的文件 message_ ...

  4. 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新

    本系列将从以下三个方面对Tinker进行源码解析: Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Android热更新开源项目Tinker源码解析系列之二:资源文件热更新 A ...

  5. QT5利用chromium内核与HTML页面交互

    在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...

  6. 最好的.NET开源免费ZIP库DotNetZip(.NET组件介绍之三)

    在项目开发中,除了对数据的展示更多的就是对文件的相关操作,例如文件的创建和删除,以及文件的压缩和解压.文件压缩的好处有很多,主要就是在文件传输的方面,文件压缩的好处就不需要赘述,因为无论是开发者,还是 ...

  7. MVC5 网站开发之三 数据存储层功能实现

    数据存储层在项目Ninesky.DataLibrary中实现,整个项目只有一个类Repository.   目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 ...

  8. Google之Chromium浏览器源码学习——base公共通用库(一)

    Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...

  9. 如何在windows上编译Chromium (CEF3) 并加入MP3支持(二)

    时隔一年,再次编译cef3,独一无二的目的仍为加入mp3支持.新版本的编译环境和注意事项都已经发生了变化,于是再记录一下. 一.编译版本 cef版本号格式为X.YYYY.A.gHHHHHHH X为主版 ...

随机推荐

  1. arcgis 地理国情建库软件已完成

    arcgis 地理国情软件已完成: 1.创建1:25000(或则其他比例尺)国家2000坐标系接合表 2.按照地理国情普查数据库标准,创建标准数据库 3.外业调查工作底图制作 4.矢量和影像数据批量裁 ...

  2. C++程序员必需的修养

    原文:http://www.cnblogs.com/ctoroad/archive/2006/03/24/357423.html 我总结了在用C/C++语言(主要是C语言)进行程序写作上的三十二个“修 ...

  3. makefile 通配符了解% $@ $^ $<

    把目录下所有文件都编译的命令. 1 all:$(subst .c,.o,$(wildcard *.c)) 2 3 %.o:%.c 4 gcc -o $@ $< 下面是几个特舒符号的意思: $@: ...

  4. C++异常安全

    转自:http://www.cnblogs.com/zgfLawliet/p/3417308.html   异常安全的代码是指,满足两个条件 1异常中立性 : 是指当你的代码(包括你调用的代码)引发异 ...

  5. 论组织资源 #F315

    论组织资源 #F315 2016-02-29 yevon_ou 水库论坛 论组织资源  #F315 首先,让我们看一段长微博. 转:五毛大战美分,基层民猪那破事... 就是小区业委会的事,根据业委会相 ...

  6. web项目开发流程

    对于一个web项目,在实际编码之前,有一些通用的步骤来planning a website: 0.Defining the project (predr0->dr0) 对于外部项目,客户一般会发 ...

  7. SVNKit学习——wiki+简介(二)

    这篇文章是参考SVNKit官网在wiki的文档,做了个人的理解~ 首先抛出一个疑问,Subversion是做什么的,SVNKit又是用来干什么的? 相信一般工作过的同学都用过或了解过svn,不了解的同 ...

  8. 使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏

    使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏 A UIScreenEdgePanGestureRecognizer looks for panning (dra ...

  9. linux下 signal信号机制的透彻分析与各种实例讲解

    转自:http://blog.sina.com.cn/s/blog_636a55070101vs2d.html 转自:http://blog.csdn.net/tiany524/article/det ...

  10. MVC 接收参数时会自动解码

    MVC在接收传递过来的参数时,会自动对参数进行解码,无需手动解码 例: public ActionResult SendMsg2(string name) { return Content(name) ...