![]() |
IOS Streaming Browser 1.0
An IOS streaming browser to stream the display to others or to a projector
|
#import <HTTPAsyncFileResponse.h>
Public Member Functions | |
(id) | - initWithFilePath:forConnection: |
(NSString *) | - filePath |
Protected Attributes | |
HTTPConnection * | connection |
NSString * | filePath |
UInt64 | fileLength |
UInt64 | fileOffset |
UInt64 | readOffset |
BOOL | aborted |
NSData * | data |
int | fileFD |
void * | readBuffer |
NSUInteger | readBufferSize |
NSUInteger | readBufferOffset |
NSUInteger | readRequestLength |
dispatch_queue_t | readQueue |
dispatch_source_t | readSource |
BOOL | readSourceSuspended |
This is an asynchronous version of HTTPFileResponse. It reads data from the given file asynchronously via GCD.
It may be overriden to allow custom post-processing of the data that has been read from the file. An example of this is the HTTPDynamicFileResponse class.
Architecure overview:
HTTPConnection will invoke our readDataOfLength: method to fetch data. We will return nil, and then proceed to read the data via our readSource on our readQueue. Once the requested amount of data has been read, we then pause our readSource, and inform the connection of the available data.
While our read is in progress, we don't have to worry about the connection calling any other methods, except the connectionDidClose method, which would be invoked if the remote end closed the socket connection. To safely handle this, we do a synchronous dispatch on the readQueue, and nilify the connection as well as cancel our readSource.
In order to minimize resource consumption during a HEAD request, we don't open the file until we have to (until the connection starts requesting data).
Definition at line 15 of file HTTPAsyncFileResponse.h.
- (NSString *) filePath |
returns filePath as an NSString
- (id) initWithFilePath: | (NSString *) | fpath | |
forConnection: | (HTTPConnection *) | parent | |
Initialize the HTTPAsyncFileResponse with a file path and HTTPConnection param NSString param HTTPConnection returns id
Definition at line 37 of file HTTPAsyncFileResponse.m.
:(NSString *)fpath forConnection:(HTTPConnection *)parent { if ((self = [super init])) { connection = parent; // Parents retain children, children do NOT retain parents // Copy the passed-in file path variable into the local instance variable filePath = [fpath copy]; // Check that the file path variable is not nil if (filePath == nil) { // If the file path variable is nil, then decrement this instances reference count and return nil [self release]; return nil; } // Creates a dictionary object with the file attributes for the specified file path NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL]; // Check that there are file attributes if (fileAttributes == nil) { [self release]; return nil; } // Gets the length of the file fileLength = (UInt64)[[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue]; // Set the file offset to the beginning of the file (i.e. zero) fileOffset = 0; aborted = NO; // We don't bother opening the file here. // If this is a HEAD request we only need to know the fileLength. fileFD = NULL_FD; } return self; }
- (BOOL) aborted [protected] |
whether the file response is aborted
Definition at line 47 of file HTTPAsyncFileResponse.h.
- (HTTPConnection*) connection [protected] |
Definition at line 22 of file HTTPAsyncFileResponse.h.
the data from the file
Definition at line 53 of file HTTPAsyncFileResponse.h.
- (int) fileFD [protected] |
the file descriptior (i.e. file handle)
Definition at line 59 of file HTTPAsyncFileResponse.h.
- (UInt64) fileLength [protected] |
the file length
Definition at line 32 of file HTTPAsyncFileResponse.h.
- (UInt64) fileOffset [protected] |
File offset as pertains to data given to connection
Definition at line 37 of file HTTPAsyncFileResponse.h.
- (NSString *) filePath [protected] |
the file path
Gets the file path returns NSString
Definition at line 27 of file HTTPAsyncFileResponse.h.
- (void*) readBuffer [protected] |
The read buffer. This is for holding the data read from a file, and waiting to be sent to the host
Definition at line 65 of file HTTPAsyncFileResponse.h.
- (NSUInteger) readBufferOffset [protected] |
Offset within readBuffer where the end of existing data is
Definition at line 75 of file HTTPAsyncFileResponse.h.
- (NSUInteger) readBufferSize [protected] |
Malloc'd size of readBuffer
Definition at line 70 of file HTTPAsyncFileResponse.h.
- (UInt64) readOffset [protected] |
File offset as pertains to data read from file (but maybe not returned to connection)
Definition at line 42 of file HTTPAsyncFileResponse.h.
- (dispatch_queue_t) readQueue [protected] |
The read queue
Definition at line 85 of file HTTPAsyncFileResponse.h.
- (NSUInteger) readRequestLength [protected] |
The read request length.
Definition at line 80 of file HTTPAsyncFileResponse.h.
- (dispatch_source_t) readSource [protected] |
The read source
Definition at line 90 of file HTTPAsyncFileResponse.h.
- (BOOL) readSourceSuspended [protected] |
Whether read source is suspended
Definition at line 95 of file HTTPAsyncFileResponse.h.