- bugifx for static cached hostname, moved to higher scope to avoid sometimes random crashes

This commit is contained in:
SoftCoder
2015-12-31 16:48:55 -08:00
parent a399f8d1a5
commit 57f0b44ad3
2 changed files with 6 additions and 4 deletions

View File

@@ -152,6 +152,8 @@ protected:
bool isSocketBlocking; bool isSocketBlocking;
time_t lastSocketError; time_t lastSocketError;
static string host_name;
public: public:
Socket(PLATFORM_SOCKET sock); Socket(PLATFORM_SOCKET sock);
Socket(); Socket();

View File

@@ -68,6 +68,7 @@ namespace Shared{ namespace Platform{
bool Socket::disableNagle = false; bool Socket::disableNagle = false;
int Socket::DEFAULT_SOCKET_SENDBUF_SIZE = -1; int Socket::DEFAULT_SOCKET_SENDBUF_SIZE = -1;
int Socket::DEFAULT_SOCKET_RECVBUF_SIZE = -1; int Socket::DEFAULT_SOCKET_RECVBUF_SIZE = -1;
string Socket::host_name = "";
int Socket::broadcast_portno = 61357; int Socket::broadcast_portno = 61357;
int ServerSocket::ftpServerPort = 61358; int ServerSocket::ftpServerPort = 61358;
@@ -1827,19 +1828,18 @@ bool Socket::isConnected() {
} }
string Socket::getHostName() { string Socket::getHostName() {
static string host = ""; if(Socket::host_name == "") {
if(host == "") {
const int strSize= 257; const int strSize= 257;
char hostname[strSize]=""; char hostname[strSize]="";
int result = gethostname(hostname, strSize); int result = gethostname(hostname, strSize);
if(result == 0) { if(result == 0) {
host = (hostname[0] != '\0' ? hostname : ""); Socket::host_name = (hostname[0] != '\0' ? hostname : "");
} }
else { else {
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] result = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,result,getLastSocketErrorText()); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] result = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,result,getLastSocketErrorText());
} }
} }
return host; return Socket::host_name;
} }
string Socket::getIp() { string Socket::getIp() {