mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-22 14:13:44 +00:00
Update Socket.md
重新绘制 I/O 模型的配图,更新非阻塞 I/O 和 select 示例的描述。
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="380" viewBox="0 0 760 380">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">异步 I/O</text>
|
||||
<rect x="120" y="46" width="160" height="30" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="200" y="65.5" class="c sub b">应用进程</text>
|
||||
<rect x="460" y="46" width="160" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="540" y="65.5" class="c sub b">内核</text>
|
||||
<line x1="200" y1="78" x2="200" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<line x1="540" y1="78" x2="540" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<rect x="554" y="96" width="26" height="94" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="590" y="139" class="sub b" style="fill:#444">① 等待数据</text>
|
||||
<text x="590" y="155" class="sub">例如等对方发来 hello</text>
|
||||
<rect x="554" y="244" width="26" height="46" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="590" y="270" class="sub b" style="fill:#444">② 复制到用户缓冲区</text>
|
||||
<text x="554" y="214" class="sub">数据到达</text>
|
||||
<line x1="200" y1="100" x2="540" y2="100" class="arrow "/>
|
||||
<text x="370" y="95" class="c sub mono" style="fill:#444">aio_read(fd, buf, 1024)</text>
|
||||
<line x1="540" y1="114" x2="200" y2="114" class="arrow dash"/>
|
||||
<text x="370" y="109" class="c sub" style="fill:#444">立即返回</text>
|
||||
<rect x="193" y="118" width="14" height="172" rx="3" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="186" y="208" class="sub ok e">继续执行其它代码</text>
|
||||
<line x1="540" y1="290" x2="200" y2="290" class="arrow dash"/>
|
||||
<text x="370" y="285" class="c sub" style="fill:#444">完成通知:buf 中已经是 hello</text>
|
||||
<text x="30" y="356" class="sub">两个阶段都由内核完成,进程收到通知时数据已经在自己的缓冲区中。Linux 上实际的异步 I/O 多用 io_uring。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,53 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="380" viewBox="0 0 760 380">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">阻塞式 I/O</text>
|
||||
<rect x="120" y="46" width="160" height="30" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="200" y="65.5" class="c sub b">应用进程</text>
|
||||
<rect x="460" y="46" width="160" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="540" y="65.5" class="c sub b">内核</text>
|
||||
<line x1="200" y1="78" x2="200" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<line x1="540" y1="78" x2="540" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<rect x="554" y="96" width="26" height="94" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="590" y="139" class="sub b" style="fill:#444">① 等待数据</text>
|
||||
<text x="590" y="155" class="sub">例如等对方发来 hello</text>
|
||||
<rect x="554" y="244" width="26" height="46" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="590" y="270" class="sub b" style="fill:#444">② 复制到用户缓冲区</text>
|
||||
<text x="554" y="214" class="sub">数据到达</text>
|
||||
<line x1="200" y1="100" x2="540" y2="100" class="arrow "/>
|
||||
<text x="370" y="95" class="c sub mono" style="fill:#444">recvfrom(fd, buf, 1024)</text>
|
||||
<rect x="193" y="102" width="14" height="188" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="186" y="200" class="sub note e">两个阶段都阻塞</text>
|
||||
<line x1="540" y1="290" x2="200" y2="290" class="arrow dash"/>
|
||||
<text x="370" y="285" class="c sub" style="fill:#444">返回 5(读到 hello)</text>
|
||||
<text x="30" y="356" class="sub">本机测试:对方 300 ms 后才发送,recv 阻塞 0.31 秒后返回。等待期间线程不占用 CPU,但也不能做别的事。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
@@ -0,0 +1,66 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="330" viewBox="0 0 760 330">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">五种 I/O 模型的比较</text>
|
||||
<text x="108" y="129" class="sub b e" style="fill:#444">① 等待数据</text>
|
||||
<text x="108" y="224" class="sub b e" style="fill:#444">② 复制数据</text>
|
||||
<line x1="110" y1="180" x2="720" y2="180" stroke="#DDD" stroke-dasharray="4 4"/>
|
||||
<text x="180" y="58" class="c b" style="fill:#444">阻塞式</text>
|
||||
<rect x="172.0" y="76" width="16" height="98" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="194" y="129" class="sub">阻塞</text>
|
||||
<rect x="172.0" y="186" width="16" height="68" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="194" y="224" class="sub">阻塞</text>
|
||||
<text x="300" y="58" class="c b" style="fill:#444">非阻塞式</text>
|
||||
<rect x="292.0" y="76" width="16" height="98" rx="3" fill="#FFFFFF" stroke="#D99A94" stroke-dasharray="4 3"/>
|
||||
<text x="314" y="129" class="sub">反复轮询</text>
|
||||
<rect x="292.0" y="186" width="16" height="68" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="314" y="224" class="sub">阻塞</text>
|
||||
<text x="420" y="58" class="c b" style="fill:#444">I/O 复用</text>
|
||||
<rect x="412.0" y="76" width="16" height="98" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="434" y="129" class="sub">阻塞在 select</text>
|
||||
<rect x="412.0" y="186" width="16" height="68" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="434" y="224" class="sub">阻塞</text>
|
||||
<text x="540" y="58" class="c b" style="fill:#444">信号驱动</text>
|
||||
<rect x="532.0" y="76" width="16" height="98" rx="3" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="554" y="129" class="sub">不阻塞</text>
|
||||
<rect x="532.0" y="186" width="16" height="68" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="554" y="224" class="sub">阻塞</text>
|
||||
<text x="660" y="58" class="c b" style="fill:#444">异步</text>
|
||||
<rect x="652.0" y="76" width="16" height="98" rx="3" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="674" y="129" class="sub">不阻塞</text>
|
||||
<rect x="652.0" y="186" width="16" height="68" rx="3" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="674" y="224" class="sub">不阻塞</text>
|
||||
<path d="M126,272 q0,8 8,8 H592 q8,0 8,-8" class="line"/>
|
||||
<text x="360" y="296" class="c sub">同步 I/O:第二阶段由进程自己 recvfrom,都会阻塞</text>
|
||||
<text x="660" y="296" class="c sub">异步 I/O</text>
|
||||
<text x="30" y="320" class="sub">红色表示进程阻塞,浅青色表示进程可以做别的事。前四种的区别只在第一阶段。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,59 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="380" viewBox="0 0 760 380">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">I/O 复用</text>
|
||||
<rect x="120" y="46" width="160" height="30" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="200" y="65.5" class="c sub b">应用进程</text>
|
||||
<rect x="460" y="46" width="160" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="540" y="65.5" class="c sub b">内核</text>
|
||||
<line x1="200" y1="78" x2="200" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<line x1="540" y1="78" x2="540" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<rect x="554" y="96" width="26" height="94" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="590" y="139" class="sub b" style="fill:#444">① 等待数据</text>
|
||||
<text x="590" y="155" class="sub">例如等对方发来 hello</text>
|
||||
<rect x="554" y="244" width="26" height="46" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="590" y="270" class="sub b" style="fill:#444">② 复制到用户缓冲区</text>
|
||||
<text x="554" y="214" class="sub">数据到达</text>
|
||||
<line x1="200" y1="100" x2="540" y2="100" class="arrow "/>
|
||||
<text x="370" y="95" class="c sub mono" style="fill:#444">select([fd1, fd2, …])</text>
|
||||
<rect x="193" y="102" width="14" height="88" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="186" y="150" class="sub note e">阻塞在 select</text>
|
||||
<line x1="540" y1="190" x2="200" y2="190" class="arrow dash"/>
|
||||
<text x="370" y="185" class="c sub" style="fill:#444">fd1 可读</text>
|
||||
<line x1="200" y1="244" x2="540" y2="244" class="arrow "/>
|
||||
<text x="370" y="239" class="c sub mono" style="fill:#444">recvfrom(fd1)</text>
|
||||
<rect x="193" y="246" width="14" height="44" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="186" y="272" class="sub note e">复制时阻塞</text>
|
||||
<line x1="540" y1="290" x2="200" y2="290" class="arrow dash"/>
|
||||
<text x="370" y="285" class="c sub" style="fill:#444">返回 5</text>
|
||||
<text x="30" y="356" class="sub">和阻塞式 I/O 一样要等,但一次可以等很多个连接,任何一个就绪就返回,一个线程就能处理大量连接。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
@@ -0,0 +1,63 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="380" viewBox="0 0 760 380">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">非阻塞式 I/O</text>
|
||||
<rect x="120" y="46" width="160" height="30" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="200" y="65.5" class="c sub b">应用进程</text>
|
||||
<rect x="460" y="46" width="160" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="540" y="65.5" class="c sub b">内核</text>
|
||||
<line x1="200" y1="78" x2="200" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<line x1="540" y1="78" x2="540" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<rect x="554" y="96" width="26" height="94" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="590" y="139" class="sub b" style="fill:#444">① 等待数据</text>
|
||||
<text x="590" y="155" class="sub">例如等对方发来 hello</text>
|
||||
<rect x="554" y="244" width="26" height="46" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="590" y="270" class="sub b" style="fill:#444">② 复制到用户缓冲区</text>
|
||||
<text x="554" y="214" class="sub">数据到达</text>
|
||||
<line x1="200" y1="96" x2="540" y2="96" class="arrow "/>
|
||||
<text x="370" y="91" class="c sub mono" style="fill:#444">recvfrom</text>
|
||||
<line x1="540" y1="110" x2="200" y2="110" class="arrow dash"/>
|
||||
<text x="370" y="124" class="c sub" style="fill:#444">EAGAIN(没有数据)</text>
|
||||
<line x1="200" y1="150" x2="540" y2="150" class="arrow "/>
|
||||
<text x="370" y="145" class="c sub mono" style="fill:#444">recvfrom</text>
|
||||
<line x1="540" y1="164" x2="200" y2="164" class="arrow dash"/>
|
||||
<text x="370" y="178" class="c sub" style="fill:#444">EAGAIN ……共 6 次</text>
|
||||
<line x1="200" y1="206" x2="540" y2="206" class="arrow "/>
|
||||
<text x="370" y="201" class="c sub mono" style="fill:#444">recvfrom</text>
|
||||
<rect x="193" y="100" width="14" height="100" rx="3" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="186" y="154" class="sub ok e">轮询</text>
|
||||
<rect x="193" y="208" width="14" height="82" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="186" y="253" class="sub note e">复制时阻塞</text>
|
||||
<line x1="540" y1="290" x2="200" y2="290" class="arrow dash"/>
|
||||
<text x="370" y="285" class="c sub" style="fill:#444">返回 5</text>
|
||||
<text x="30" y="356" class="sub">本机测试:每 50 ms 调用一次 recv,前 6 次返回 EAGAIN(没有数据),第 7 次读到 hello。轮询本身要消耗 CPU。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,61 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="380" viewBox="0 0 760 380">
|
||||
<style>
|
||||
text { font-family: "PingFang SC", "Microsoft YaHei", Helvetica, Arial, sans-serif; fill: #3F3F3F; font-size: 12px; }
|
||||
.title { font-weight: bold; font-size: 15px; fill: #333; text-anchor: middle; }
|
||||
.b { font-weight: bold; }
|
||||
.c { text-anchor: middle; }
|
||||
.e { text-anchor: end; }
|
||||
.sub { font-size: 11px; fill: #6E6E6E; }
|
||||
.note { fill: #C0605A; }
|
||||
.ok { fill: #6A9F68; }
|
||||
.mono { font-family: Menlo, Consolas, monospace; }
|
||||
.arrow { stroke: #555; stroke-width: 1.1; fill: none; marker-end: url(#a); }
|
||||
.red { stroke: #C0605A; marker-end: url(#r); }
|
||||
.green { stroke: #6A9F68; marker-end: url(#g); }
|
||||
.dash { stroke-dasharray: 5 4; }
|
||||
.line { stroke: #555; stroke-width: 1.1; fill: none; }
|
||||
.frame { fill: none; stroke: #999; stroke-width: 1; stroke-dasharray: 4 3; }
|
||||
.shadow { fill: #DADADA; }
|
||||
</style>
|
||||
<defs>
|
||||
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#555"/>
|
||||
</marker>
|
||||
<marker id="r" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#C0605A"/>
|
||||
</marker>
|
||||
<marker id="g" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
||||
<path d="M1,1.5 L9.5,5 L1,8.5 z" fill="#6A9F68"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="#FFFFFF"/>
|
||||
|
||||
<text x="380" y="28" class="title">信号驱动 I/O</text>
|
||||
<rect x="120" y="46" width="160" height="30" rx="6" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="200" y="65.5" class="c sub b">应用进程</text>
|
||||
<rect x="460" y="46" width="160" height="30" rx="6" fill="#C6E4FB" stroke="#7FB2D6"/>
|
||||
<text x="540" y="65.5" class="c sub b">内核</text>
|
||||
<line x1="200" y1="78" x2="200" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<line x1="540" y1="78" x2="540" y2="330" stroke="#BBB" stroke-dasharray="4 4"/>
|
||||
<rect x="554" y="96" width="26" height="94" rx="3" fill="#EAE9E7" stroke="#BFBEBA" stroke-width="1"/>
|
||||
<text x="590" y="139" class="sub b" style="fill:#444">① 等待数据</text>
|
||||
<text x="590" y="155" class="sub">例如等对方发来 hello</text>
|
||||
<rect x="554" y="244" width="26" height="46" rx="3" fill="#E6E3FA" stroke="#B8B0DE" stroke-width="1"/>
|
||||
<text x="590" y="270" class="sub b" style="fill:#444">② 复制到用户缓冲区</text>
|
||||
<text x="554" y="214" class="sub">数据到达</text>
|
||||
<line x1="200" y1="100" x2="540" y2="100" class="arrow "/>
|
||||
<text x="370" y="95" class="c sub mono" style="fill:#444">sigaction(SIGIO, handler)</text>
|
||||
<line x1="540" y1="114" x2="200" y2="114" class="arrow dash"/>
|
||||
<text x="370" y="109" class="c sub" style="fill:#444">立即返回</text>
|
||||
<rect x="193" y="118" width="14" height="72" rx="3" fill="#C6ECE9" stroke="#7DBCB7"/>
|
||||
<text x="186" y="158" class="sub ok e">继续执行其它代码</text>
|
||||
<line x1="540" y1="190" x2="200" y2="190" class="arrow dash"/>
|
||||
<text x="370" y="185" class="c sub mono" style="fill:#444">SIGIO 信号</text>
|
||||
<line x1="200" y1="244" x2="540" y2="244" class="arrow "/>
|
||||
<text x="370" y="239" class="c sub mono" style="fill:#444">在处理函数中 recvfrom</text>
|
||||
<rect x="193" y="246" width="14" height="44" rx="3" fill="#F3C6C2" stroke="#D99A94"/>
|
||||
<text x="186" y="272" class="sub note e">复制时阻塞</text>
|
||||
<line x1="540" y1="290" x2="200" y2="290" class="arrow dash"/>
|
||||
<text x="370" y="285" class="c sub" style="fill:#444">返回 5</text>
|
||||
<text x="30" y="356" class="sub">等待阶段不阻塞,数据到达时内核发信号通知“可以读了”,读取仍由进程自己完成。</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.7 KiB |
Reference in New Issue
Block a user