From a8168fd02ac3797f37d47459f768899cf35c4738 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 4 Jun 2008 21:39:16 -0400 Subject: [PATCH] When calling -[SocketWrapper remoteHost], we don't want to continually query the hostname * Source/SocketWrapper.h: Adding a hostname ivar * Source/SocketWrapper.m: (remoteHost): Just return the hostname ivar (connect:): Query the hostname and store it in the hostname ivar --- Source/SocketWrapper.h | 1 + Source/SocketWrapper.m | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/SocketWrapper.h b/Source/SocketWrapper.h index 1501393..2877df8 100644 --- a/Source/SocketWrapper.h +++ b/Source/SocketWrapper.h @@ -24,6 +24,7 @@ int port; int sock; + NSString *hostname; id delegate; } diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index f0dfb89..7092e19 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -71,17 +71,7 @@ */ - (NSString *)remoteHost { - struct sockaddr_in addr; - socklen_t addrLength; - - if (getpeername(sock, (struct sockaddr *)&addr, &addrLength) < 0) - { - [self error:@"Could not get remote hostname."]; - } - - char *name = inet_ntoa(addr.sin_addr); - - return [NSString stringWithUTF8String:name]; + return hostname; } /** @@ -147,6 +137,15 @@ // we're done listening now that we have a connection close(socketOpen); + struct sockaddr_in addr; + socklen_t addrLength; + if (getpeername(sock, (struct sockaddr *)&addr, &addrLength) < 0) + { + [self error:@"Could not get remote hostname."]; + } + char *name = inet_ntoa(addr.sin_addr); + hostname = [NSString stringWithUTF8String:name]; + [connection performSelectorOnMainThread:@selector(socketDidAccept:) withObject:nil waitUntilDone:NO]; } -- 2.43.5