fixup wait for connection

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39987 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2016-07-12 16:25:49 +00:00
parent 4b9f685eb9
commit bd106b0bd0

View file

@ -55,11 +55,15 @@ NSLog(@"%@", notif);
int main() int main()
{ {
NSAutoreleasePool *arp = [NSAutoreleasePool new]; NSAutoreleasePool *arp = [NSAutoreleasePool new];
Handler *h; Handler *h;
NSFileHandle *sFH, *cFH; NSFileHandle *sFH;
NSData *wData = [@"Socket Test" dataUsingEncoding:NSASCIIStringEncoding]; NSFileHandle *cFH;
NSData *rData; NSData *wData;
NSData *rData;
NSDate *limit;
wData = [@"Socket Test" dataUsingEncoding:NSASCIIStringEncoding];
/* Note that the above data should be short enough to fit into the /* Note that the above data should be short enough to fit into the
socket send buffer otherwise we risk being blocked in this single socket send buffer otherwise we risk being blocked in this single
threaded process. */ threaded process. */
@ -74,7 +78,6 @@ int main()
[sFH acceptConnectionInBackgroundAndNotify]; [sFH acceptConnectionInBackgroundAndNotify];
cFH = [NSFileHandle fileHandleAsClientAtAddress: @"127.0.0.1" cFH = [NSFileHandle fileHandleAsClientAtAddress: @"127.0.0.1"
service: GST_PORT service: GST_PORT
protocol: @"tcp"]; protocol: @"tcp"];
@ -82,7 +85,12 @@ int main()
"NSFileHandle understands +fileHandleAsClientAtAddress:"); "NSFileHandle understands +fileHandleAsClientAtAddress:");
[cFH writeData: wData]; [cFH writeData: wData];
[[NSRunLoop currentRunLoop] run]; limit = [NSDate dateWithTimeIntervalSinceNow: 2.0];
while (nil == rFH && [limit timeIntervalSinceNow] > 0.0)
{
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: limit];
}
PASS(rFH != nil, "NSFileHandle connection was made"); PASS(rFH != nil, "NSFileHandle connection was made");
rData = [rFH availableData]; rData = [rFH availableData];