上一篇分析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. C# CRC16算法实现【转】

    /// <summary> /// CRC校验 /// </summary> public class CRC { #region CRC16 public static by ...

  2. _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明

    原文:http://www.cnblogs.com/lidabo/archive/2012/07/10/2584706.html _itoa 功能:把一整数转换为字符串 用法:char * _itoa ...

  3. kafka leader平衡策略

    1.1个partition的默认leader是replicas中的第一个replica 2.kafka controller会启动一个定时的check线程,kafka默认是5min周期,mafka是3 ...

  4. 【Leetcode】【Medium】Binary Tree Zigzag Level Order Traversal

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  5. .net 面向对象程序设计深入](1)UML

    1.UML简介 Unified Modeling Language (UML)又称统一建模语言或标准建模语言. 简单说就是以图形方式表现模型,根据不同模型进行分类,在UML 2.0中有13种图,以下是 ...

  6. AutoHotkey调用VBA实现批量精确筛选数据透视表某字段内容。

    如上图,想在数据透视表中只显示红色区域的内容,手动勾选就比较繁琐. 实现思路: 先复制红色的内容. 鼠标停留在数据透视表[型号]列的任意数据上(通过该单元格可以获取数据透视表和字段) 由于数据透视表的 ...

  7. NFS-heartbeat-drbd模拟NFS高可用

    NFS介绍: NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NFS ...

  8. mysql多实例mysqld_multi方式

    mysql多实例应用,亲测直接执行脚本可使用,可快速部署多实例环境 #!/bin/bash set -e #定义mysql_multi多实例数据的配置,如需增加,在后面函数对应地方需要增加 mydir ...

  9. BIND简易教程(3):DNSSec配置

    目录:BIND简易教程(1):安装及基本配置BIND简易教程(2):BIND视图配置BIND简易教程(3):DNSSec配置 (本篇) DNSSec,有个半英半中的名字叫DNS安全扩展.说的好听一点, ...

  10. 【转】九步学习python装饰器

    本篇日志来自:http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html 纯转,只字未改.只是为了学习一下装饰器.其实现在也是没有太看明白 ...