Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
進階檔案 I/O
|
105
實作方式
readv()
writev()
的簡單實作方式,可以在用戶空間中以一個簡單的迴圈來完成,它
看起來會像下面這個樣子:
#include <unistd.h>
#include <sys/uio.h>
ssize_t naive_writev (int fd, const struct iovec *iov, int count)
{
ssize_t ret = 0;
int i;
for (i = 0; i < count; i++) {
ssize_t nr;
errno = 0;
nr = write (fd, iov[i].iov_base, iov[i].iov_len);
if (nr ==
1) {
if (errno == EINTR)
continue;
ret =
1;
break;
}
ret += nr;
}
return ret;
}
幸好,這不是 Linux 的實作方式:Linux
readv()
writev()
實作成系統呼叫,並在
內部進行分散∕聚集 I/O。事實上,Linux 核心內部所有 I/O 均採用向量的方式;儘管
read()
write()
被實作成向量 I/O,但是向量中只具有一個區段。
事件輪詢
察覺
poll()
select()
的限制後,Linux 核心 2.6
2
引進了
事件輪詢
event poll
,簡稱
epoll
)措施。儘管比
poll()
select()
還複雜,epoll 不僅解決了這兩個介面的效能問 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812