mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
fixups for run loop handling
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39989 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
788c9aa7e2
commit
ab5285aaab
4 changed files with 55 additions and 16 deletions
|
@ -114,7 +114,8 @@ int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSRunLoop *rl = [NSRunLoop currentRunLoop];
|
NSRunLoop *rl = [NSRunLoop currentRunLoop];
|
||||||
NSData *answer;
|
NSData *answer = nil;
|
||||||
|
NSDate *end;
|
||||||
|
|
||||||
// first test, file to memory copy
|
// first test, file to memory copy
|
||||||
NSString *path = @"memandfile.m";
|
NSString *path = @"memandfile.m";
|
||||||
|
@ -128,7 +129,13 @@ int main()
|
||||||
[input open];
|
[input open];
|
||||||
[output open];
|
[output open];
|
||||||
defaultOutput = output;
|
defaultOutput = output;
|
||||||
[rl runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
|
end = [NSDate dateWithTimeIntervalSinceNow: 1.0];
|
||||||
|
while (NO == [goldData isEqualToData: answer]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
answer = [output propertyForKey: NSStreamDataWrittenToMemoryStreamKey];
|
||||||
|
}
|
||||||
|
|
||||||
answer = [output propertyForKey: NSStreamDataWrittenToMemoryStreamKey];
|
answer = [output propertyForKey: NSStreamDataWrittenToMemoryStreamKey];
|
||||||
PASS([goldData isEqualToData: answer], "file to memory copy ok");
|
PASS([goldData isEqualToData: answer], "file to memory copy ok");
|
||||||
|
@ -144,9 +151,17 @@ int main()
|
||||||
[input2 open];
|
[input2 open];
|
||||||
[output2 open];
|
[output2 open];
|
||||||
defaultInput = input2;
|
defaultInput = input2;
|
||||||
[rl runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
|
|
||||||
|
|
||||||
NSData *answer2 = [NSData dataWithContentsOfFile: pathO];
|
end = [NSDate dateWithTimeIntervalSinceNow: 1.0];
|
||||||
|
NSData *answer2 = nil;
|
||||||
|
while (NO == [goldData isEqualToData: answer2]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
answer2 = [NSData dataWithContentsOfFile: pathO];
|
||||||
|
}
|
||||||
|
|
||||||
|
answer2 = [NSData dataWithContentsOfFile: pathO];
|
||||||
PASS([goldData isEqualToData: answer2], "memory to file copy ok");
|
PASS([goldData isEqualToData: answer2], "memory to file copy ok");
|
||||||
|
|
||||||
[[NSFileManager defaultManager] removeFileAtPath: pathO handler: nil];
|
[[NSFileManager defaultManager] removeFileAtPath: pathO handler: nil];
|
||||||
|
|
|
@ -50,7 +50,8 @@ static NSMutableData *testData;
|
||||||
}
|
}
|
||||||
case NSStreamEventErrorOccurred:
|
case NSStreamEventErrorOccurred:
|
||||||
{
|
{
|
||||||
NSAssert1(1, @"Error! code is %d", [[theStream streamError] code]);
|
NSAssert1(1, @"Error! code is %ld",
|
||||||
|
(long int)[[theStream streamError] code]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -66,6 +67,7 @@ int main()
|
||||||
NSRunLoop *rl = [NSRunLoop currentRunLoop];
|
NSRunLoop *rl = [NSRunLoop currentRunLoop];
|
||||||
Listener *li = [[Listener new] autorelease];
|
Listener *li = [[Listener new] autorelease];
|
||||||
NSString *path = @"pipe.m";
|
NSString *path = @"pipe.m";
|
||||||
|
NSDate *end;
|
||||||
|
|
||||||
[NSStream pipeWithInputStream:&defaultInput outputStream:&defaultOutput];
|
[NSStream pipeWithInputStream:&defaultInput outputStream:&defaultOutput];
|
||||||
goldData = [NSData dataWithContentsOfFile:path];
|
goldData = [NSData dataWithContentsOfFile:path];
|
||||||
|
@ -76,8 +78,12 @@ int main()
|
||||||
[defaultOutput scheduleInRunLoop:rl forMode:NSDefaultRunLoopMode];
|
[defaultOutput scheduleInRunLoop:rl forMode:NSDefaultRunLoopMode];
|
||||||
[defaultInput open];
|
[defaultInput open];
|
||||||
[defaultOutput open];
|
[defaultOutput open];
|
||||||
[rl run];
|
end = [NSDate dateWithTimeIntervalSinceNow: 0.5];
|
||||||
|
while (NO == [goldData isEqualToData:testData]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
}
|
||||||
PASS([goldData isEqualToData:testData], "Local pipe");
|
PASS([goldData isEqualToData:testData], "Local pipe");
|
||||||
[arp release];
|
[arp release];
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -28,7 +28,7 @@ static BOOL done = NO;
|
||||||
static uint8_t buffer[4096];
|
static uint8_t buffer[4096];
|
||||||
static BOOL doneWrite = NO;
|
static BOOL doneWrite = NO;
|
||||||
int readSize;
|
int readSize;
|
||||||
NSLog(@"Got %d on %p", streamEvent, theStream);
|
NSLog(@"Got %ld on %p", (long int)streamEvent, theStream);
|
||||||
switch (streamEvent)
|
switch (streamEvent)
|
||||||
{
|
{
|
||||||
case NSStreamEventOpenCompleted:
|
case NSStreamEventOpenCompleted:
|
||||||
|
@ -98,7 +98,8 @@ NSLog(@"%@", [defaultInput streamError]);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
NSAssert1(1, @"Error! code is %d", [[theStream streamError] code]);
|
NSAssert1(1, @"Error! code is %ld",
|
||||||
|
(long int)[[theStream streamError] code]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,10 @@ eventString(NSStream *stream, NSStreamEvent event)
|
||||||
case NSStreamEventHasBytesAvailable: return @"bytes available";
|
case NSStreamEventHasBytesAvailable: return @"bytes available";
|
||||||
case NSStreamEventEndEncountered: return @"end encountered";
|
case NSStreamEventEndEncountered: return @"end encountered";
|
||||||
case NSStreamEventErrorOccurred:
|
case NSStreamEventErrorOccurred:
|
||||||
return [NSString stringWithFormat: @"error %d (%@)",
|
return [NSString stringWithFormat: @"error %ld (%@)",
|
||||||
[[stream streamError] code], [stream streamError]];
|
(long int)[[stream streamError] code], [stream streamError]];
|
||||||
default: return [NSString stringWithFormat: @"unknown event %d", event];
|
default:
|
||||||
|
return [NSString stringWithFormat: @"unknown event %ld", (long int)event];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +332,11 @@ int main()
|
||||||
[clientOutput open];
|
[clientOutput open];
|
||||||
|
|
||||||
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
||||||
[rl runUntilDate: end];
|
while (NO == [goldData isEqualToData: testData]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
}
|
||||||
PASS([goldData isEqualToData: testData], "Local tcp");
|
PASS([goldData isEqualToData: testData], "Local tcp");
|
||||||
if ([end timeIntervalSinceNow] < 0.0)
|
if ([end timeIntervalSinceNow] < 0.0)
|
||||||
NSLog(@"%@ timed out.\n", prefix);
|
NSLog(@"%@ timed out.\n", prefix);
|
||||||
|
@ -369,7 +374,11 @@ int main()
|
||||||
[clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
|
[clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
|
||||||
|
|
||||||
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
||||||
[rl runUntilDate: end];
|
while (NO == [goldData isEqualToData: testData]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
}
|
||||||
PASS([goldData isEqualToData: testData], "Local tcp (blocking open)");
|
PASS([goldData isEqualToData: testData], "Local tcp (blocking open)");
|
||||||
if ([end timeIntervalSinceNow] < 0.0)
|
if ([end timeIntervalSinceNow] < 0.0)
|
||||||
NSLog(@"%@ timed out.\n", prefix);
|
NSLog(@"%@ timed out.\n", prefix);
|
||||||
|
@ -405,7 +414,11 @@ int main()
|
||||||
[clientOutput open];
|
[clientOutput open];
|
||||||
|
|
||||||
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
||||||
[rl runUntilDate: end];
|
while (NO == [goldData isEqualToData: testData]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
}
|
||||||
PASS([goldData isEqualToData: testData], "Local socket");
|
PASS([goldData isEqualToData: testData], "Local socket");
|
||||||
if ([end timeIntervalSinceNow] < 0.0)
|
if ([end timeIntervalSinceNow] < 0.0)
|
||||||
NSLog(@"%@ timed out.\n", prefix);
|
NSLog(@"%@ timed out.\n", prefix);
|
||||||
|
@ -444,7 +457,11 @@ int main()
|
||||||
[clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
|
[clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
|
||||||
|
|
||||||
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
end = [NSDate dateWithTimeIntervalSinceNow: 5];
|
||||||
[rl runUntilDate: end];
|
while (NO == [goldData isEqualToData: testData]
|
||||||
|
&& [end timeIntervalSinceNow] > 0.0)
|
||||||
|
{
|
||||||
|
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
|
||||||
|
}
|
||||||
PASS([goldData isEqualToData: testData], "Local socket (blocking open)");
|
PASS([goldData isEqualToData: testData], "Local socket (blocking open)");
|
||||||
if ([end timeIntervalSinceNow] < 0.0)
|
if ([end timeIntervalSinceNow] < 0.0)
|
||||||
NSLog(@"%@ timed out.\n", prefix);
|
NSLog(@"%@ timed out.\n", prefix);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue