伺服器程式設計——函式splice實現零拷貝使用解釋
splice函式用於在兩個檔案描述符之間移動資料,也是零拷貝操作。
函式原型如下:
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h>
ssize_t splice(int fd_in, loff_t *off_in, int fd_out,
loff_t *off_out, size_t len, unsigned int flags);
splice() moves data between two file descriptors without copying between kernel address space and user address space. It transfers up to len bytes of data from the file descriptor fd_in to the file descriptor fd_out, where one of the descriptors must refer to a pipe.
If fd_in refers to a pipe, then off_in must be NULL. If fd_in does not refer to a pipe and off_in is NULL, then bytes are read from fd_in starting from the current file offset, and the current file offset is adjusted appropriately. If fd_in does not refer to a pipe and off_in is not NULL, then off_in must point to a buffer which specifies the starting offset from which bytes will be read from fd_in; in this case, the current file offset of fd_in is not changed. Analogous statements apply for fd_out and off_out.
The flags argument is a bit mask that is composed by ORing together zero or more of the following values:
SPLICE_F_MOVE Attempt to move pages instead of copying. This is only a hint to the kernel: pages may still be copied if the kernel cannot move the pages from the pipe, or if the pipe buffers don't refer to full pages. The initial implementation
of this flag was buggy: therefore starting in Linux 2.6.21 it is a no-op (but is still permitted in a splice() call); in the future, a correct implementation may be restored.
SPLICE_F_NONBLOCK Do not block on I/O. This makes the splice pipe operations nonblocking, but splice() may nevertheless block because the file descriptors that are spliced to/from may block (unless they have the O_NONBLOCK flag set).
SPLICE_F_MORE More data will be coming in a subsequent splice. This is a helpful hint when the fd_out refers to a socket (see also the description of MSG_MORE in send(2), and the description of TCP_CORK in tcp(7))
SPLICE_F_GIFT Unused for splice(); see vmsplice(2).
相關文章
- 使用splice函式實現0拷貝的回顯伺服器函式伺服器
- linux網路程式設計九:splice函式,高效的零拷貝Linux程式設計函式
- C++拷貝建構函式(深拷貝,淺拷貝)C++函式
- 拷貝建構函式函式
- 實現物件淺拷貝、深拷貝物件
- C++拷貝建構函式詳解C++函式
- C++ 拷貝建構函式詳解C++函式
- 自己寫的unix檔案拷貝指令cp實現函式函式
- C語言實現字串拷貝函式的幾種方法C語言字串函式
- js實現深拷貝和淺拷貝JS
- 淺拷貝與深拷貝的實現
- 零拷貝原理
- C++之Big Three:拷貝構造、拷貝賦值、解構函式探究C++賦值函式
- 深拷貝與淺拷貝的實現(一)
- 拷貝建構函式的作用函式
- 【JS】深拷貝與淺拷貝,實現深拷貝的幾種方法JS
- Java NIO - 零拷貝Java
- [JS系列二]談談深拷貝和淺拷貝,如何實現深拷貝JS
- js實現深拷貝JS
- 拷貝建構函式中的陷阱函式
- 用 splice函式分別實現 push、pop、shift、unshi函式
- 64行程式碼實現零拷貝go的TCP拆包粘包行程GoTCP
- C++中建構函式,拷貝建構函式和賦值函式的詳解C++函式賦值
- jquery之物件拷貝深拷貝淺拷貝案例講解jQuery物件
- 深拷貝和淺拷貝的區別是什麼?實現一個深拷貝
- Java零拷貝一步曲——Linux 中的零拷貝技術JavaLinux
- 拷貝建構函式(比較全的)函式
- 怎麼實現深拷貝
- 實現深拷貝還在用JSON.parse(JSON.stringify(obj))?帶你用JS實現一個完整版深拷貝函式JSONOBJ函式
- 【趣解程式設計】函式程式設計函式
- 淺拷貝與深拷貝程式碼(javascript)JavaScript
- MySQL的零拷貝技術MySql
- 用函式實現模組化程式設計一函式程式設計
- 用函式實現模組化程式設計二函式程式設計
- 用函式實現模組化程式設計三函式程式設計
- C++複製控制:拷貝建構函式C++函式
- js物件實現深淺拷貝!!JS物件
- JavaScript實現淺拷貝的方法JavaScript