From 19892ff11ded5d30e94112bbe580ab863d15b5d8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 23 Aug 2010 15:17:36 +0000 Subject: [PATCH] - small network optimization to help stabilize frequently called network code --- .../sources/platform/posix/socket.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index a9028380..60c08447 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -1228,15 +1228,17 @@ bool Socket::isConnected() { } string Socket::getHostName() { - const int strSize= 257; - char hostname[strSize]=""; - int result = gethostname(hostname, strSize); - string host = ""; - if(result == 0) { - host = (hostname[0] != '\0' ? hostname : ""); - } - else { - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] result = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,result,getLastSocketErrorText()); + static string host = ""; + if(host == "") { + const int strSize= 257; + char hostname[strSize]=""; + int result = gethostname(hostname, strSize); + if(result == 0) { + host = (hostname[0] != '\0' ? hostname : ""); + } + else { + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] result = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,result,getLastSocketErrorText()); + } } return host; }