- small network optimization to help stabilize frequently called network code

This commit is contained in:
Mark Vejvoda 2010-08-23 15:17:36 +00:00
parent 70817a07d1
commit 19892ff11d
1 changed files with 11 additions and 9 deletions

View File

@ -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;
}