Skip to content

Commit

Permalink
Merge branch 'updaate-ipv6-support' of github.com:gnustep/libs-base i…
Browse files Browse the repository at this point in the history
…nto updaate-ipv6-support
  • Loading branch information
gcasa committed Nov 3, 2023
2 parents 0e3e1ab + 21c5556 commit 9bcaf27
Showing 1 changed file with 105 additions and 11 deletions.
116 changes: 105 additions & 11 deletions Tests/base/NSStream/socket_cs.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,23 @@ - (void)stream: (NSStream *)theStream handleEvent: (NSStreamEvent)streamEvent
int main()
{
CREATE_AUTORELEASE_POOL(arp);
NSRunLoop *rl = [NSRunLoop currentRunLoop];
NSHost *host = [NSHost hostWithAddress: @"127.0.0.1"];
ServerListener *sli;
ClientListener *cli;
NSString *path = @"socket_cs.m";
NSString *socketPath = @"test-socket";
NSDate *end;

[[NSFileManager defaultManager] removeFileAtPath: socketPath handler: nil];
NSRunLoop *rl = [NSRunLoop currentRunLoop];
NSHost *host;
ServerListener *sli;
ClientListener *cli;
NSString *path = @"socket_cs.m";
NSString *socketPath = @"test-socket";
NSDate *end;

host = [NSHost hostWithAddress: @"127.0.0.1"];
NSLog(@"sending and receiving on %@: %@", host, [host address]);
goldData = [NSData dataWithContentsOfFile: path];
testData = [NSMutableData dataWithCapacity: 4096];

{
CREATE_AUTORELEASE_POOL(inner);

prefix = @"Test1";
prefix = @"Test1IPV4";
[testData setLength: 0];
sli = AUTORELEASE([ServerListener new]);
cli = AUTORELEASE([ClientListener new]);
Expand Down Expand Up @@ -351,7 +351,7 @@ int main()
{
CREATE_AUTORELEASE_POOL(inner);

prefix = @"Test2";
prefix = @"Test2IPV4";
[testData setLength: 0];
sli = AUTORELEASE([ServerListener new]);
cli = AUTORELEASE([ClientListener new]);
Expand All @@ -360,6 +360,53 @@ int main()
[serverStream setDelegate: sli];
[serverStream open];
[serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[NSStream getStreamsToHost: host
port: 1234
inputStream: &clientInput
outputStream: &clientOutput];
NSLog(@"%@ Client input stream is %@", prefix, clientInput);
NSLog(@"%@ Client output stream is %@", prefix, clientOutput);
[clientInput setDelegate: cli];
[clientOutput setDelegate: cli];
[clientInput open];
[clientOutput open];
[clientInput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];

end = [NSDate dateWithTimeIntervalSinceNow: 5];
while (NO == [goldData isEqualToData: testData]
&& [end timeIntervalSinceNow] > 0.0)
{
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
}
PASS([goldData isEqualToData: testData], "Local tcp (blocking open)");
if ([end timeIntervalSinceNow] < 0.0)
NSLog(@"%@ timed out.\n", prefix);

[clientInput setDelegate: nil];
[clientOutput setDelegate: nil];
DESTROY(serverInput);
DESTROY(serverOutput);
RELEASE(inner);
}

host = [NSHost hostWithAddress: @"::1"];
NSLog(@"sending and receiving on %@: %@", host, [host address]);
goldData = [NSData dataWithContentsOfFile: path];
testData = [NSMutableData dataWithCapacity: 4096];

{
CREATE_AUTORELEASE_POOL(inner);

prefix = @"Test1IPV6";
[testData setLength: 0];
sli = AUTORELEASE([ServerListener new]);
cli = AUTORELEASE([ClientListener new]);
serverStream
= [GSServerStream serverStreamToAddr: [host address] port: 1234];
[serverStream setDelegate: sli];
[serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[serverStream open];
[NSStream getStreamsToHost: host
port: 1234
inputStream: &clientInput
Expand All @@ -368,6 +415,48 @@ int main()
NSLog(@"%@ Client output stream is %p", prefix, clientOutput);
[clientInput setDelegate: cli];
[clientOutput setDelegate: cli];
[clientInput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[clientOutput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[clientInput open];
[clientOutput open];

end = [NSDate dateWithTimeIntervalSinceNow: 5];
while (NO == [goldData isEqualToData: testData]
&& [end timeIntervalSinceNow] > 0.0)
{
[rl runMode: NSDefaultRunLoopMode beforeDate: end];
}
PASS([goldData isEqualToData: testData], "Local tcp");
if ([end timeIntervalSinceNow] < 0.0)
NSLog(@"%@ timed out.\n", prefix);

[clientInput setDelegate: nil];
[clientOutput setDelegate: nil];
DESTROY(serverInput);
DESTROY(serverOutput);
RELEASE(inner);
}

{
CREATE_AUTORELEASE_POOL(inner);

prefix = @"Test2IPV6";
[testData setLength: 0];
sli = AUTORELEASE([ServerListener new]);
cli = AUTORELEASE([ClientListener new]);
serverStream
= [GSServerStream serverStreamToAddr: [host address] port: 1234];
[serverStream setDelegate: sli];
[serverStream open];
[serverStream scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
[NSStream getStreamsToHost: host
port: 1234
inputStream: &clientInput
outputStream: &clientOutput];
NSLog(@"%@ Client input stream is %@", prefix, clientInput);
NSLog(@"%@ Client output stream is %@", prefix, clientOutput);
[clientInput setDelegate: cli];
[clientOutput setDelegate: cli];
[clientInput open];
[clientOutput open];
[clientInput scheduleInRunLoop: rl forMode: NSDefaultRunLoopMode];
Expand All @@ -390,6 +479,11 @@ int main()
RELEASE(inner);
}

[[NSFileManager defaultManager] removeFileAtPath: socketPath handler: nil];
NSLog(@"sending and receiving on %@", socketPath);
goldData = [NSData dataWithContentsOfFile: path];
testData = [NSMutableData dataWithCapacity: 4096];

{
CREATE_AUTORELEASE_POOL(inner);

Expand Down

0 comments on commit 9bcaf27

Please sign in to comment.