Method Stdio.sendfile()
- Method
sendfile
object
sendfile(array
(string
)headers
,File
from
,int
offset
,int
len
,array
(string
)trailers
,File
to
)
object
sendfile(array
(string
)headers
,File
from
,int
offset
,int
len
,array
(string
)trailers
,File
to
,function
(int
,mixed
... :void
)callback
,mixed
...args
)- Description
Sends
headers
followed bylen
bytes starting atoffset
from the filefrom
followed bytrailers
to the fileto
. When completedcallback
will be called with the total number of bytes sent as the first argument, followed byargs
.Any of
headers
,from
andtrailers
may be left out by setting them to0
.Setting
offset
to-1
means send from the current position infrom
.Setting
len
to-1
means send untilfrom
's end of file is reached.- Note
The sending is performed asynchronously, and may complete both before and after the function returns.
For
callback
to be called, the backend must be active (iemain()
must have returned-1
, or Pike.DefaultBackend get called in some other way).In some cases, the backend must also be active for any sending to be performed at all.
In Pike 7.4.496, Pike 7.6.120 and Pike 7.7 and later the backend associated with
to
will be used rather than the default backend. Note that you usually will wantfrom
to have the same backend asto
.- Note
The low-level sending may be performed with blocking I/O calls, and thus trigger the process being killed with SIGPIPE when the peer closes the other end. Add a call to signal() to avoid this.
- Bugs
FIXME: Support for timeouts?
- See also