Fixed thread exit problem.

CQTexperiment
vspader 2007-10-14 16:57:32 +00:00
parent 0e6f0a8576
commit 7d53e8586a
1 changed files with 11 additions and 14 deletions

View File

@ -20,14 +20,14 @@
_data = [[NSMutableData alloc] init]; _data = [[NSMutableData alloc] init];
_sem = [[Semaphore alloc] init]; _sem = [[Semaphore alloc] init];
[NSThread detachNewThreadSelector:@selector(makeConnection) toTarget:self withObject:nil]; [NSThread detachNewThreadSelector:@selector(doConnection) toTarget:self withObject:nil];
NSLog(@"Connection opened!"); NSLog(@"Connection opened!");
return YES; return YES;
} }
- (void)makeConnection - (void)doConnection
{ {
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_url]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:_url];
@ -35,14 +35,16 @@
[request release]; [request release];
NSDate* endDate = [NSDate distantFuture]; while (!_connectionFinished)
do
{ {
NSLog(@"IN THREAD"); NSDate *date = [[NSDate alloc] init];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate];
} while (!_connectionFinished); [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:date];
[date release];
}
NSLog(@"Exiting thread"); NSLog(@"Thread exit");
} }
- (NSDictionary *)properties - (NSDictionary *)properties
@ -95,12 +97,11 @@
_connectionFinished = YES; _connectionFinished = YES;
[_sem signal]; [_sem signal];
[NSThread exit];
} }
- (void)close - (void)close
{ {
NSLog(@"CLOSING HTTPSource!");
_connectionFinished = YES; _connectionFinished = YES;
[_connection cancel]; [_connection cancel];
@ -167,14 +168,10 @@
_connectionFinished = YES; _connectionFinished = YES;
[_sem signal]; [_sem signal];
[NSThread exit];
} }
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{ {
NSLog(@"Connection received data.");
[_data appendData:data]; [_data appendData:data];
[_sem signal]; [_sem signal];
} }