IOS Streaming Browser 1.0
An IOS streaming browser to stream the display to others or to a projector

/Users/willrubel/IOS-Streaming-Browser/IOS-Streaming-Browser/HTTPAsyncFileResponse.h

Go to the documentation of this file.
00001 #import <Foundation/Foundation.h>
00002 #import "HTTPResponse.h"
00003 
00004 @class HTTPConnection;
00005 
00006 /**
00007  * This is an asynchronous version of HTTPFileResponse.
00008  * It reads data from the given file asynchronously via GCD.
00009  * 
00010  * It may be overriden to allow custom post-processing of the data that has been read from the file.
00011  * An example of this is the HTTPDynamicFileResponse class.
00012 **/
00013 
00014 // Implements HTTPResponse protocol
00015 @interface HTTPAsyncFileResponse : NSObject <HTTPResponse>
00016 {       
00017     
00018     /**
00019      
00020     **/
00021         HTTPConnection *connection;
00022         
00023     /**
00024       the file path
00025     **/
00026         NSString *filePath; 
00027     
00028     /**
00029       the file length
00030     **/
00031         UInt64 fileLength;  
00032     
00033     /**
00034       File offset as pertains to data given to connection
00035     **/
00036         UInt64 fileOffset;  
00037     
00038     /**
00039       File offset as pertains to data read from file (but maybe not returned to connection)
00040     **/
00041         UInt64 readOffset;  
00042         
00043     /**
00044       whether the file response is aborted
00045     **/
00046         BOOL aborted;  
00047         
00048     
00049     /**
00050       the data from the file
00051     **/
00052         NSData *data;  
00053         
00054     
00055     /**
00056       the file descriptior (i.e. file handle)
00057     **/
00058         int fileFD; 
00059     
00060     
00061     /**
00062         The read buffer.  This is for holding the data read from a file, and waiting to be sent to the host
00063     **/
00064         void *readBuffer; 
00065     
00066     /**
00067         Malloc'd size of readBuffer
00068     **/
00069         NSUInteger readBufferSize;     
00070     
00071     /**
00072       Offset within readBuffer where the end of existing data is
00073     **/
00074         NSUInteger readBufferOffset;   
00075     
00076     /**
00077         The read request length.  
00078     **/
00079         NSUInteger readRequestLength; 
00080     
00081     /**
00082         The read queue
00083     **/
00084         dispatch_queue_t readQueue;  
00085     
00086     /**
00087         The read source
00088     **/
00089         dispatch_source_t readSource; 
00090     
00091     /**
00092         Whether read source is suspended
00093     **/
00094         BOOL readSourceSuspended;  
00095 }
00096 
00097 /**
00098         Initialize the HTTPAsyncFileResponse with a file path and HTTPConnection
00099         param NSString
00100         param HTTPConnection
00101         returns id
00102 **/
00103 - (id)initWithFilePath:(NSString *)filePath forConnection:(HTTPConnection *)connection;
00104 
00105 /**
00106     returns filePath as an NSString
00107 **/
00108 - (NSString *)filePath;
00109 
00110 @end
00111 
00112 /**
00113  * Explanation of Variables (excluding those that are obvious)
00114  * 
00115  * fileOffset
00116  *   This is the number of bytes that have been returned to the connection via the readDataOfLength method.
00117  *   If 1KB of data has been read from the file, but none of that data has yet been returned to the connection,
00118  *   then the fileOffset variable remains at zero.
00119  *   This variable is used in the calculation of the isDone method.
00120  *   Only after all data has been returned to the connection are we actually done.
00121  * 
00122  * readOffset
00123  *   Represents the offset of the file descriptor.
00124  *   In other words, the file position indidcator for our read stream.
00125  *   It might be easy to think of it as the total number of bytes that have been read from the file.
00126  *   However, this isn't entirely accurate, as the setOffset: method may have caused us to
00127  *   jump ahead in the file (lseek).
00128  * 
00129  * readBuffer
00130  *   Malloc'd buffer to hold data read from the file.
00131  * 
00132  * readBufferSize
00133  *   Total allocation size of malloc'd buffer.
00134  * 
00135  * readBufferOffset
00136  *   Represents the position in the readBuffer where we should store new bytes.
00137  * 
00138  * readRequestLength
00139  *   The total number of bytes that were requested from the connection.
00140  *   It's OK if we return a lesser number of bytes to the connection.
00141  *   It's NOT OK if we return a greater number of bytes to the connection.
00142  *   Doing so would disrupt proper support for range requests.
00143  *   If, however, the response is chunked then we don't need to worry about this.
00144  *   Chunked responses inheritly don't support range requests.
00145 **/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines