当前位置:网站首页>网络IO总结文
网络IO总结文
2022-07-27 08:38:00 【芒骁】
IO
I/O前言——五种IO通信模型
多路复用IO模型
I/O多路复用模型 select
I/O多路复用模型 poll
I/O多路复用 epoll
Linux实现
Linux I/O 多路复用 epoll
BIO
BIO示例
BIO实现

1. 执行ServerSocket构造函数
2. BIO ServerSocket.accept()等待客户端请求
BIO ServerSocket.accept()等待客户端请求
BIO组件
ServerSocket
Socket
SocksSocketetImpl
windows平台组件
PlainSocketImpl
DualStackPlainSocketImpl
DualStackPlainSocketImpl 本地方法的各种封装
InetSocketAddress
InetSocketAddress 封装套接字信息(IP+端口)
NIO
NIO总结文——一篇读懂NIO整个流程
NIO示例
NIO服务端工作过程

1. NIO服务端准备工作
2. this.selector.select()查找到来的感兴趣事件
3. 感兴趣的事件到来
组件
SelectorProvider
SelectorProviderImpl
Selector
Channel
SocketChannelImpl
SelectionKey
NIO组件 Selector之 SelectionKey 、 SelectionKeyImpl
Pipe
Net
NIO客户端(粗略)
NIO 客户端创建Channel
NIO 客户端发起连接
思考
从BIO到NIO、再到Netty
知识点的梳理
NIO
线程关系
在上文NIO示例中,仅仅只有一个main线程并没有创建额外线程,也就是说Selector、Channel处理在同一个线程,通过Selector实现轮询的NIO有如下特点:
- 单线程处理多通道通信
- select方法阻塞(使得处理Channel中的事件通过同步实现)
这种经典NIO方式和BIO相比最大的意义在于将面向连接处理改变为面向事件处理。
Selector、Channel处理在同一个线程这样做依然是具有优化空间的,也就是在Selector的基础上加入多线程处理,此时的多线程处理和BIO的多线程处理已经意义不同,对于额外线程的使用会更有效。
Channel的意义
在BIO实现中,流和Socket直接连接,你可以理解为:
一个水龙头的一方是水源(客户端),另一方是一个人(服务端),这个人要喝水,但是没有器皿,所以只能一直在水龙头下等待未知的水源输送,即使这会没有水,人还是要等待,因为必须要保证能够接收水源。
BIO就是这样的,BIO可以实现非阻塞,但是BIO最大的问题在于流直接与Socket通信。
我们之前分析NIO是块编程,其实就是BIO的基础上加入缓存实现
拓展
NIO Buffer
TODO
边栏推荐
- Realization of background channel group management function
- 4275. Dijkstra sequence
- Do a reptile project by yourself
- 众昂矿业:新能源行业快速发展,氟化工产品势头强劲
- [NPUCTF2020]ReadlezPHP 1
- 691. 立方体IV
- Block, there is a gap between the block elements in the row
- JS advanced knowledge - function
- Explain cache consistency and memory barrier
- 4279. 笛卡尔树
猜你喜欢

Realization of backstage brand management function

Solution to the program design of the sequence structure of one book (Chapter 1)

Initial summary of flask framework creation project

Using ecological power, opengauss breaks through the performance bottleneck

海关总署:这类产品暂停进口

Flink1.15 source code reading Flink clients client execution process (reading is boring)

Element display mode: block level, inline, inline block, nesting specification, display mode conversion

Login to homepage function implementation

Fluent rendering mechanism - GPU thread rendering

Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
随机推荐
Day6 --- Sqlalchemy advanced
It's better to be full than delicious; It's better to be drunk than drunk
How to merge multiple columns in an excel table into one column
3311. Longest arithmetic
JS检测客户端软件是否安装
[geek challenge 2019] finalsql 1
百人参与,openGauss开源社区这群人都在讨论什么?
Installation and use of beef XSS
ROS2安装时出现Connection failed [IP: 91.189.91.39 80]
Set set
[uni app advanced practice] take you hand-in-hand to learn the development of a purely practical complex project 1/100
Do a reptile project by yourself
“寻源到结算“与“采购到付款“两者有什么不同或相似之处?
I drew a Gu ailing with characters!
Alibaba cloud international receipt message introduction and configuration process
Binglog backup data
Sliding conflict of view
Flask request data acquisition and response
4274. 后缀表达式
说透缓存一致性与内存屏障