epoll

Handler消息传递机制分析

时光毁灭记忆、已成空白 提交于 2019-12-06 23:46:01
Handler的用途和用法 写过Android程序的人大概都会遇到ANR(Application Not Responding)。如果程序在一段时间内没有响应,系统就会弹出一个对话框,让用户选择继续等待还是强制关闭应用。为了避免ANR,我们需要把耗时的逻辑放到后台线程里执行。但是后台线程无法更新界面。那么当任务完成后,如何根据结果更新界面呢?Handler就可以承担这个职责。下面的例子展示了Handler的用法: package com.tq.handlerdemo; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private static final int UPDATE_TEXT = 1; private TextView textView; Thread backgroundThread = new Thread(new Runnable() { @Override public void run

Linux 五种IO模型

情到浓时终转凉″ 提交于 2019-12-06 22:32:37
1,什么是IO模型 IO 在计算机中指的就是 Input/Output (输入/输出)。 Input/Output (输入/输出)的内容当然就是 data (数据)了。 那么数据被 Input 到哪, Output 到哪呢? Input (输入)数据到内存中, Output (输出)数据到 IO 设备(磁盘、网络等需要与内存进行数据交互的设备)中; IO 设备与内存直接的数据传输通过 IO 接口,操作系统封装了 IO 接口,我们编程时可以直接使用。 网络IO的本质是socket的读取,socket在linux系统被抽象为流,IO可以理解为对流的操作。 对于一次IO访问(以read举例),数据会先被拷贝到操作系统内核的缓冲区中,然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间。所以说, 当一个read操作发生时,它会经历两个阶段: 等待数据准备 (Waiting for the data to be ready)。 将数据从内核拷贝到进程中 (Copying the data from the kernel to the process)。 对于socket流而言, 第一步:通常涉及等待网络上的数据分组到达,然后被复制到内核的某个缓冲区。 第二步:把数据从内核缓冲区复制到应用进程缓冲区。 网络应用需要处理的无非就是两大类问题, 网络IO,数据计算 。相对于后者,网络IO的延迟

Why do we need to call poll_wait in poll?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 22:24:46
问题 In LDD3, i saw such codes static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal. */ down(&dev->sem); poll_wait(filp, &dev->inq, wait); poll_wait(filp, &dev->outq, wait); if (dev->rp != dev->wp) mask |= POLLIN | POLLRDNORM; /* readable */ if (spacefree(dev)) mask |= POLLOUT | POLLWRNORM; /*

Does OS X not support epoll function?

和自甴很熟 提交于 2019-12-06 22:05:35
问题 I'm learning to use epoll function. But my OS X, Mountain Lion doesn't have a header file, sys/epoll.h. I'd like to use epoll function on OS X. How Can I use epoll function? 回答1: Mac OS X doesn't support epoll, but it does support kqueue which is very similar. 回答2: on Mac OSX use kqueue instead of epoll. Do something like this in your java code. final boolean isMac = System.getProperty("os.name").toLowerCase(Locale.US).contains("mac"); // Configure the server. // See https://netty.io/wiki

Nginx教程(一) Nginx入门教程

*爱你&永不变心* 提交于 2019-12-06 16:34:53
Nginx教程(一) Nginx入门教程 1 Nginx入门教程 Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like协议下发行。由俄罗斯的程序设计师IgorSysoev所开发,供俄国大型的入口网站及 搜索引擎 Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好。 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的Rambler.ru 站点开发的,第一个公开版本 0.1.0 发布于 2004 年 10 月 4 日。其将源代码以类 BSD 许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。 它已经在众多流量很大的俄罗斯网站上使用了很长时间,这些网站包括 Yandex、Mail.Ru、 VKontakte,以及 Rambler。据 Netcraft 统计,在 2012 年 8 月份,世界上最繁忙的网站中有 11.48%使用 Nginx 作为其服务器或者代理服务器。目前互联网主流公司 360、百度、新浪、腾讯、阿里等,目前中国互联网企业 70

openwrt中ubus的具体使用

…衆ロ難τιáo~ 提交于 2019-12-06 08:12:28
转自: http://www.fx114.net/qa-26-169704.aspx#__RefHeading__28_50040687 openwrt ubus的wiki ubus是为了OpenWrt中守护进程和应用程序之间通讯开发的,类似桌面的DBus,设计理念上与DBus基本保持一致,区别是简化的API和简练的模型,以适应embeddedrouter的特殊环境。与DBus一样也是使用socket实现。 核心部分是ubusd守护进程,它提供了其他守护进程将自己注册以及发送消息的接口。因为这个,接口通过使用Unixsocket来实现,并使用TLV(type-length-value)消息,ubus内部使用Blob_buf,Blob_attr等结构来表示。 ubus有两种调用,一个是method调用,一个是notification,其中method包括等待函数返回和不用等待返回,notification是广播和DBus的signal类似。ubus使用是先建立连接,然后把连接加入epollset中。下面是它的一些调用API。 uloop_init(); 创建epoll句柄,最多监听32个fd ubus_connect(); 创建ubus连接 ubus_add_uloop(); 把创建的ubus连接注册到epoll中。 ubus_add_object(); 注册对象到的ubus连接。

Could not use os.fork() bind several process to one socket server when using asyncio

假装没事ソ 提交于 2019-12-06 05:23:14
We all know that using asyncio substantially improves the performance of a socket server, and obviously things get even more awesome if we could take advantage of all cores in our cpu (maybe via multiprocessing module or os.fork() etc.) I'm now trying to build a multicore socket server demo, with a asynchronous socket server listening on each core and all binding to one port. Simply by creating a async server and then use os.fork() , let processes work competitively. However the single-core-fine code runs into some trouble when I'm trying to fork. Seems like there's some problem with

One-shot *level*-triggered epoll(): Does EPOLLONESHOT imply EPOLLET?

六月ゝ 毕业季﹏ 提交于 2019-12-06 04:47:19
问题 Is it possible to use epoll in one-shot level -triggered mode? I couldn't find any information on it when I searched; it seems everyone uses edge-triggered mode. 回答1: When the EPOLLONESHOT flag is selected and you have pulled an event for a socket, then the socket won't get removed from epoll as many think but its events get disabled. You can enable them again using epoll_ctl / EPOLL_CTL_MOD . An example case when the EPOLLONESHOT behavior comes handy is when you've read the available data

General explanation of how epoll works?

☆樱花仙子☆ 提交于 2019-12-06 02:41:28
问题 I'm doing a technical write-up on switching from a database-polling (via synchronous stored procedure call) to a message queue (via pub/sub). I'd like to be able to explain how polling a database is vastly different and much heavier than setting up a connection to a AMQP broker and configuring a message handler. Can someone maybe provide an explanation here, or point me to a good high level tutorial on how epoll works when notifying of new data becoming available on a socket? 回答1: I assume by

How to build netty-transport-native-epoll-4.0.32.Final-linux-x86_64.jar?

雨燕双飞 提交于 2019-12-06 02:27:48
I am using native epoll transport in netty and was able to download netty-transport-native-epoll-4.0.32.jar from the repository. However I also need netty-transport-native-epoll-4.0.32.Final-linux-x86_64.jar but not unable to find it anywhere. Please let me know where to download this jar, or how to build it. The file can be found here : http://repo.scub-foundation.org/artifactory/libs-release/io/netty/netty-transport-native-epoll/4.0.32.Final/ The content doesn't seem to be different than from netty-all-4.0.32.Final.jar -> io\netty\channel\epoll\ 来源: https://stackoverflow.com/questions