From 195e1f19b06095f39a4fb0da46dfab2ec5b10e9a Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 13 Jan 2011 12:36:14 +0100 Subject: Implement file:sendfile Allow Erlang code to use sendfile() where available by wrapping it as file:sendfile/4 and file:sendfile/2. sendfile(2) - Linux man page: "sendfile() copies data between one file descriptor and another. Because this copying is done within the kernel, sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data to and from user space." --- lib/kernel/doc/src/file.xml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/kernel/doc/src/file.xml') diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index 7db20e6343..78bf0aff45 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -1573,6 +1573,28 @@ otherwise {error, Reason}.

+ + + send a file to a socket + +

Sends Bytes in from the file + referenced by IoDevice beginning at Offset to + Socket. + Returns {ok, BytesSent} if successful, + otherwise {error, Reason}.

+

Available on Linux, FreeBSD, DragonflyBSD, Solaris, Darwin and Windows

+
+
+ + + send a file to a socket + +

Sends the file Filename to Socket. + Returns {ok, BytesSent} if successful, + otherwise {error, Reason}.

+

Available on Linux, FreeBSD, DragonflyBSD, Solaris, Darwin and Windows

+
+
Write to a file -- cgit v1.2.3 From 758fab8895755b22ce02f0a6026d4d286c8a9c5a Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Sun, 27 Nov 2011 17:30:06 +0100 Subject: Expand sendfile documentation --- lib/kernel/doc/src/file.xml | 66 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) (limited to 'lib/kernel/doc/src/file.xml') diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index 78bf0aff45..7fcc354176 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -149,6 +149,9 @@ + + + @@ -1574,25 +1577,70 @@ - + send a file to a socket -

Sends Bytes in from the file - referenced by IoDevice beginning at Offset to - Socket. +

Sends the file Filename to Socket. Returns {ok, BytesSent} if successful, otherwise {error, Reason}.

-

Available on Linux, FreeBSD, DragonflyBSD, Solaris, Darwin and Windows

- + send a file to a socket -

Sends the file Filename to Socket. +

Sends Bytes from the file + referenced by RawFile beginning at Offset to + Socket. Returns {ok, BytesSent} if successful, - otherwise {error, Reason}.

-

Available on Linux, FreeBSD, DragonflyBSD, Solaris, Darwin and Windows

+ otherwise {error, Reason}. If Bytes is set to + 0 all data after the given Offset is sent.

+

The file used must be opened using the raw flag, and the process + calling sendfile must be the controlling process of the socket. + See gen_tcp:controlling_process/2

+

If the OS used does not support sendfile, an Erlang fallback + using file:read and gen_tcp:send is used.

+

The option list can contain the following options: + + headers + A list containing data which is to be sent before + the file is sent. If headers is used, Bytes specifies + the total bytes in the header and/or file to be sent. If + Bytes is set to 0, the all headers, the file and + possible trailers will be sent. + trailers + A list containing data which is to be after before + the file is sent. All the trailers will be sent after the + file is sent, no matter what Bytes is set to. + chunk_size + The chunk size used by the erlang fallback to send + data. If using the fallback, this should be set to a value + which comfortably fits in the systems memory. Default is 20 MB. + sf_nodiskio + This flag causes any sendfile() call which would + block on disk I/O to instead return EBUSY. Busy servers may bene- + fit by transferring requests that would block to a separate I/O + worker thread. + sf_mnowait + Do not wait for some kernel resource to become avail- + able, in particular, mbuf and sf_buf. The flag does not make the + sendfile() syscall truly non-blocking, since other resources are + still allocated in a blocking fashion. + sf_sync + sendfile sleeps until the network stack no longer refer- + ences the VM pages of the file, making subsequent modifications to + it safe. Please note that this is not a guarantee that the data + has actually been sent. + +

+

On operating systems with thread support, it is recommended to use + async threads. See the command line flag + +A in erl(1). If it is not + possible to use async threads for sendfile, it is recommended to use + a relatively small value for the send buffer on the socket. Otherwise + the Erlang VM might loose some of its soft realtime guarantees. + Which size to use depends on the OS/hardware and the requirements + of the application.

-- cgit v1.2.3 From 1bbf8cee44b8836d66d289cc0b5b314ed83de821 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Tue, 29 Nov 2011 11:05:37 +0100 Subject: Remove header/trailer support Since the API for headers/trailers seem to be very awkward to work with when using non-blocking io the feature is dropped for now. See unix_efile.c for more details. --- lib/kernel/doc/src/file.xml | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'lib/kernel/doc/src/file.xml') diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index 7fcc354176..c6a1f25dd9 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -1602,35 +1602,10 @@ using file:read and gen_tcp:send is used.

The option list can contain the following options: - headers - A list containing data which is to be sent before - the file is sent. If headers is used, Bytes specifies - the total bytes in the header and/or file to be sent. If - Bytes is set to 0, the all headers, the file and - possible trailers will be sent. - trailers - A list containing data which is to be after before - the file is sent. All the trailers will be sent after the - file is sent, no matter what Bytes is set to. chunk_size The chunk size used by the erlang fallback to send data. If using the fallback, this should be set to a value which comfortably fits in the systems memory. Default is 20 MB. - sf_nodiskio - This flag causes any sendfile() call which would - block on disk I/O to instead return EBUSY. Busy servers may bene- - fit by transferring requests that would block to a separate I/O - worker thread. - sf_mnowait - Do not wait for some kernel resource to become avail- - able, in particular, mbuf and sf_buf. The flag does not make the - sendfile() syscall truly non-blocking, since other resources are - still allocated in a blocking fashion. - sf_sync - sendfile sleeps until the network stack no longer refer- - ences the VM pages of the file, making subsequent modifications to - it safe. Please note that this is not a guarantee that the data - has actually been sent.

On operating systems with thread support, it is recommended to use -- cgit v1.2.3