Tubetrue01 / articles

0 stars 0 forks source link

C 迷你系列(六)select 与 stdio 混用所带来的问题 | Tubetrue01 #2

Open Tubetrue01 opened 3 years ago

Tubetrue01 commented 3 years ago

https://tubetrue01.github.io/articles/2021/08/09/c_mini/C-%E8%BF%B7%E4%BD%A0%E7%B3%BB%E5%88%97(%E5%85%AD)select-%E4%B8%8E-stdio-%E6%B7%B7%E7%94%A8%E6%89%80%E5%B8%A6%E6%9D%A5%E7%9A%84%E9%97%AE%E9%A2%98/

引言 在 《UNIX 网络编程》一书 135 页的末尾提到关于 select 与 stdio 相关函数混用的问题。这里我把它单独拿出来,以一个简单的例子说明一下。避免之后的使用中出现类似的问题。 问题根源两者的缓冲区: 系统 I/O 在内核空间中存在缓冲,而在用户空间没有; stdio 系列函数除了在内核空间中有缓存,在用户空间也有缓冲; 缓冲区类型: 全缓冲(大部分缓冲都是这类型) 行