Skip to content

Commit

Permalink
Migrating from unsigned int to NSUInteger for better 64-bit support.
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiehanson committed Apr 20, 2010
1 parent 28b1476 commit 0a0b744
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 49 deletions.
8 changes: 4 additions & 4 deletions HTTPAsyncFileResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (id)initWithFilePath:(NSString *)fpath forConnection:(HTTPConnection *)parent
return nil;
}

NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filePath traverseLink:NO];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];
fileLength = (UInt64)[fileSize unsignedLongLongValue];

Expand Down Expand Up @@ -102,7 +102,7 @@ - (void)setOffset:(UInt64)offset
// It will request data, and won't move forward from that point until it has received the data.
}

- (NSData *)readDataOfLength:(unsigned int)length
- (NSData *)readDataOfLength:(NSUInteger)length
{
if(data == nil)
{
Expand All @@ -111,7 +111,7 @@ - (NSData *)readDataOfLength:(unsigned int)length
NSInvocationOperation *operation;
operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(readDataInBackground:)
object:[NSNumber numberWithUnsignedInt:length]];
object:[NSNumber numberWithUnsignedInteger:length]];

[operationQueue addOperation:operation];
[operation release];
Expand Down Expand Up @@ -153,7 +153,7 @@ - (void)connectionDidClose

- (void)readDataInBackground:(NSNumber *)lengthNumber
{
unsigned int length = [lengthNumber unsignedIntValue];
NSUInteger length = [lengthNumber unsignedIntegerValue];

NSData *readData = [fileHandle readDataOfLength:length];

Expand Down
8 changes: 4 additions & 4 deletions HTTPAuthenticationRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ - (NSString *)quotedSubHeaderFieldValue:(NSString *)param fromHeaderFieldValue:(
return nil;
}

int postStartRangeLocation = startRange.location + startRange.length;
int postStartRangeLength = [header length] - postStartRangeLocation;
NSUInteger postStartRangeLocation = startRange.location + startRange.length;
NSUInteger postStartRangeLength = [header length] - postStartRangeLocation;
NSRange postStartRange = NSMakeRange(postStartRangeLocation, postStartRangeLength);

NSRange endRange = [header rangeOfString:@"\"" options:0 range:postStartRange];
Expand Down Expand Up @@ -178,8 +178,8 @@ - (NSString *)nonquotedSubHeaderFieldValue:(NSString *)param fromHeaderFieldValu
return nil;
}

int postStartRangeLocation = startRange.location + startRange.length;
int postStartRangeLength = [header length] - postStartRangeLocation;
NSUInteger postStartRangeLocation = startRange.location + startRange.length;
NSUInteger postStartRangeLength = [header length] - postStartRangeLocation;
NSRange postStartRange = NSMakeRange(postStartRangeLocation, postStartRangeLength);

NSRange endRange = [header rangeOfString:@"," options:0 range:postStartRange];
Expand Down
64 changes: 34 additions & 30 deletions HTTPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@interface HTTPConnection (PrivateAPI)
- (CFHTTPMessageRef)newUniRangeResponse:(UInt64)contentLength;
- (CFHTTPMessageRef)newMultiRangeResponse:(UInt64)contentLength;
- (NSData *)chunkedTransferSizeLineForLength:(uint)length;
- (NSData *)chunkedTransferSizeLineForLength:(NSUInteger)length;
- (NSData *)chunkedTransferFooter;
@end

Expand Down Expand Up @@ -848,7 +848,7 @@ - (void)replyToHTTPRequest

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

if(isChunked)
{
Expand Down Expand Up @@ -886,13 +886,13 @@ - (void)replyToHTTPRequest

[httpResponse setOffset:range.location];

uint bytesToRead = range.length < READ_CHUNKSIZE ? (uint)range.length : READ_CHUNKSIZE;
NSUInteger bytesToRead = range.length < READ_CHUNKSIZE ? (NSUInteger)range.length : READ_CHUNKSIZE;

NSData *data = [httpResponse readDataOfLength:bytesToRead];

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

long tag = [data length] == range.length ? HTTP_RESPONSE : HTTP_PARTIAL_RANGE_RESPONSE_BODY;
[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:tag];
Expand All @@ -912,13 +912,13 @@ - (void)replyToHTTPRequest

[httpResponse setOffset:range.location];

uint bytesToRead = range.length < READ_CHUNKSIZE ? (uint)range.length : READ_CHUNKSIZE;
NSUInteger bytesToRead = range.length < READ_CHUNKSIZE ? (NSUInteger)range.length : READ_CHUNKSIZE;

NSData *data = [httpResponse readDataOfLength:bytesToRead];

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:HTTP_PARTIAL_RANGES_RESPONSE_BODY];
}
Expand Down Expand Up @@ -991,7 +991,7 @@ - (CFHTTPMessageRef)newMultiRangeResponse:(UInt64)contentLength

UInt64 actualContentLength = 0;

uint i;
NSUInteger i;
for(i = 0; i < [ranges count]; i++)
{
DDRange range = [[ranges objectAtIndex:i] ddrangeValue];
Expand Down Expand Up @@ -1026,9 +1026,9 @@ - (CFHTTPMessageRef)newMultiRangeResponse:(UInt64)contentLength
* Returns the chunk size line that must precede each chunk of data when using chunked transfer encoding.
* This consists of the size of the data, in hexadecimal, followed by a CRLF.
**/
- (NSData *)chunkedTransferSizeLineForLength:(uint)length
- (NSData *)chunkedTransferSizeLineForLength:(NSUInteger)length
{
return [[NSString stringWithFormat:@"%x\r\n", length] dataUsingEncoding:NSUTF8StringEncoding];
return [[NSString stringWithFormat:@"%lx\r\n", (unsigned long)length] dataUsingEncoding:NSUTF8StringEncoding];
}

/**
Expand All @@ -1051,14 +1051,14 @@ - (NSData *)chunkedTransferFooter
* We keep track of this information in order to keep our memory footprint low while
* working with asynchronous HTTPResponse objects.
**/
- (uint)writeQueueSize
- (NSUInteger)writeQueueSize
{
uint result = 0;
NSUInteger result = 0;

uint i;
NSUInteger i;
for(i = 0; i < [responseDataSizes count]; i++)
{
result += [[responseDataSizes objectAtIndex:i] unsignedIntValue];
result += [[responseDataSizes objectAtIndex:i] unsignedIntegerValue];
}

return result;
Expand Down Expand Up @@ -1086,16 +1086,16 @@ - (void)continueSendingStandardResponseBody
// This provides an easy way for the HTTPResponse object to throttle its data allocation in step with the rate
// at which the socket is able to send it.

uint writeQueueSize = [self writeQueueSize];
NSUInteger writeQueueSize = [self writeQueueSize];

if(writeQueueSize >= READ_CHUNKSIZE) return;

uint available = READ_CHUNKSIZE - writeQueueSize;
NSUInteger available = READ_CHUNKSIZE - writeQueueSize;
NSData *data = [httpResponse readDataOfLength:available];

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

BOOL isChunked = NO;

Expand Down Expand Up @@ -1152,7 +1152,7 @@ - (void)continueSendingSingleRangeResponseBody
// This provides an easy way for the HTTPResponse object to throttle its data allocation in step with the rate
// at which the socket is able to send it.

uint writeQueueSize = [self writeQueueSize];
NSUInteger writeQueueSize = [self writeQueueSize];

if(writeQueueSize >= READ_CHUNKSIZE) return;

Expand All @@ -1164,14 +1164,14 @@ - (void)continueSendingSingleRangeResponseBody

if(bytesLeft > 0)
{
uint available = READ_CHUNKSIZE - writeQueueSize;
uint bytesToRead = bytesLeft < available ? (uint)bytesLeft : available;
NSUInteger available = READ_CHUNKSIZE - writeQueueSize;
NSUInteger bytesToRead = bytesLeft < available ? (NSUInteger)bytesLeft : available;

NSData *data = [httpResponse readDataOfLength:bytesToRead];

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

long tag = [data length] == bytesLeft ? HTTP_RESPONSE : HTTP_PARTIAL_RANGE_RESPONSE_BODY;
[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:tag];
Expand Down Expand Up @@ -1201,7 +1201,7 @@ - (void)continueSendingMultiRangeResponseBody
// This provides an easy way for the HTTPResponse object to throttle its data allocation in step with the rate
// at which the socket is able to send it.

uint writeQueueSize = [self writeQueueSize];
NSUInteger writeQueueSize = [self writeQueueSize];

if(writeQueueSize >= READ_CHUNKSIZE) return;

Expand All @@ -1213,14 +1213,14 @@ - (void)continueSendingMultiRangeResponseBody

if(bytesLeft > 0)
{
uint available = READ_CHUNKSIZE - writeQueueSize;
uint bytesToRead = bytesLeft < available ? (uint)bytesLeft : available;
NSUInteger available = READ_CHUNKSIZE - writeQueueSize;
NSUInteger bytesToRead = bytesLeft < available ? (NSUInteger)bytesLeft : available;

NSData *data = [httpResponse readDataOfLength:bytesToRead];

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:HTTP_PARTIAL_RANGES_RESPONSE_BODY];
}
Expand All @@ -1238,14 +1238,14 @@ - (void)continueSendingMultiRangeResponseBody

[httpResponse setOffset:range.location];

uint available = READ_CHUNKSIZE - writeQueueSize;
uint bytesToRead = range.length < available ? (uint)range.length : available;
NSUInteger available = READ_CHUNKSIZE - writeQueueSize;
NSUInteger bytesToRead = range.length < available ? (NSUInteger)range.length : available;

NSData *data = [httpResponse readDataOfLength:bytesToRead];

if([data length] > 0)
{
[responseDataSizes addObject:[NSNumber numberWithUnsignedInt:[data length]]];
[responseDataSizes addObject:[NSNumber numberWithUnsignedInteger:[data length]]];

[asyncSocket writeData:data withTimeout:WRITE_BODY_TIMEOUT tag:HTTP_PARTIAL_RANGES_RESPONSE_BODY];
}
Expand Down Expand Up @@ -1575,7 +1575,7 @@ - (NSData *)preprocessErrorResponse:(CFHTTPMessageRef)response;
//
// CFHTTPMessageSetBody(response, (CFDataRef)msgData);
//
// NSString *contentLengthStr = [NSString stringWithFormat:@"%u", (uint)[msgData length]];
// NSString *contentLengthStr = [NSString stringWithFormat:@"%lu", (unsigned long)[msgData length]];
// CFHTTPMessageSetHeaderFieldValue(response, CFSTR("Content-Length"), (CFStringRef)contentLengthStr);
// }

Expand Down Expand Up @@ -1772,7 +1772,11 @@ - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData*)data withTag:(long)tag
[self prepareForBodyWithSize:requestContentLength];

// Start reading the request body
uint bytesToRead = requestContentLength < POST_CHUNKSIZE ? (uint)requestContentLength : POST_CHUNKSIZE;
NSUInteger bytesToRead;
if(requestContentLength < POST_CHUNKSIZE)
bytesToRead = (NSUInteger)requestContentLength;
else
bytesToRead = POST_CHUNKSIZE;

[asyncSocket readDataToLength:bytesToRead withTimeout:READ_TIMEOUT tag:HTTP_REQUEST_BODY];
}
Expand All @@ -1795,7 +1799,7 @@ - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData*)data withTag:(long)tag
// We're not done reading the post body yet...
UInt64 bytesLeft = requestContentLength - requestContentLengthReceived;

uint bytesToRead = bytesLeft < POST_CHUNKSIZE ? (uint)bytesLeft : POST_CHUNKSIZE;
NSUInteger bytesToRead = bytesLeft < POST_CHUNKSIZE ? (NSUInteger)bytesLeft : POST_CHUNKSIZE;

[asyncSocket readDataToLength:bytesToRead withTimeout:READ_TIMEOUT tag:HTTP_REQUEST_BODY];
}
Expand Down
4 changes: 2 additions & 2 deletions HTTPResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- (UInt64)offset;
- (void)setOffset:(UInt64)offset;

- (NSData *)readDataOfLength:(unsigned int)length;
- (NSData *)readDataOfLength:(NSUInteger)length;

// Should only return YES after the HTTPConnection has read all available data.
- (BOOL)isDone;
Expand Down Expand Up @@ -69,7 +69,7 @@

@interface HTTPDataResponse : NSObject <HTTPResponse>
{
unsigned offset;
NSUInteger offset;
NSData *data;
}

Expand Down
10 changes: 5 additions & 5 deletions HTTPResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ - (id)initWithFilePath:(NSString *)filePathParam
return nil;
}

NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filePath traverseLink:NO];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSNumber *fileSize = [fileAttributes objectForKey:NSFileSize];
fileLength = (UInt64)[fileSize unsignedLongLongValue];
}
Expand Down Expand Up @@ -46,7 +46,7 @@ - (void)setOffset:(UInt64)offset
[fileHandle seekToFileOffset:offset];
}

- (NSData *)readDataOfLength:(unsigned int)length
- (NSData *)readDataOfLength:(NSUInteger)length
{
return [fileHandle readDataOfLength:length];
}
Expand Down Expand Up @@ -100,10 +100,10 @@ - (void)setOffset:(UInt64)offsetParam
offset = (unsigned)offsetParam;
}

- (NSData *)readDataOfLength:(unsigned int)lengthParameter
- (NSData *)readDataOfLength:(NSUInteger)lengthParameter
{
unsigned int remaining = [data length] - offset;
unsigned int length = lengthParameter < remaining ? lengthParameter : remaining;
NSUInteger remaining = [data length] - offset;
NSUInteger length = lengthParameter < remaining ? lengthParameter : remaining;

void *bytes = (void *)([data bytes] + offset);

Expand Down
10 changes: 8 additions & 2 deletions HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

@class AsyncSocket;

#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5
#define IMPLEMENTED_PROTOCOLS
#else
#define IMPLEMENTED_PROTOCOLS <NSNetServiceDelegate>
#endif

@interface HTTPServer : NSObject

@interface HTTPServer : NSObject IMPLEMENTED_PROTOCOLS
{
// Underlying asynchronous TCP/IP socket
AsyncSocket *asyncSocket;
Expand Down Expand Up @@ -54,6 +60,6 @@
- (BOOL)start:(NSError **)errPtr;
- (BOOL)stop;

- (uint)numberOfHTTPConnections;
- (NSUInteger)numberOfHTTPConnections;

@end
4 changes: 2 additions & 2 deletions HTTPServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ - (BOOL)stop
/**
* Returns the number of clients that are currently connected to the server.
**/
- (uint)numberOfHTTPConnections
- (NSUInteger)numberOfHTTPConnections
{
uint result = 0;
NSUInteger result = 0;

@synchronized(connections)
{
Expand Down

0 comments on commit 0a0b744

Please sign in to comment.