Method Stdio.sendfile()
- Method
sendfile
objectsendfile(array(string)headers,Filefrom,intoffset,intlen,array(string)trailers,Fileto)
objectsendfile(array(string)headers,Filefrom,intoffset,intlen,array(string)trailers,Fileto,function(int,mixed... :void)callback,mixed...args)- Description
Sends
headersfollowed bylenbytes starting atoffsetfrom the filefromfollowed bytrailersto the fileto. When completedcallbackwill be called with the total number of bytes sent as the first argument, followed byargs.Any of
headers,fromandtrailersmay be left out by setting them to0.Setting
offsetto-1means send from the current position infrom.Setting
lento-1means 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
callbackto 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
towill be used rather than the default backend. Note that you usually will wantfromto 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