From 336573b11434dfced7f3052f1a7308db13c12c01 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 13 Oct 2007 16:36:17 +0000 Subject: [PATCH] Fix Windows and GCC compile errors. This was SVN commit r5412. --- source/network/NetLog.cpp | 28 +++++++++++++++++++++------- source/network/SocketBase.cpp | 10 +++++----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/source/network/NetLog.cpp b/source/network/NetLog.cpp index faafd83903..49b66ca18f 100644 --- a/source/network/NetLog.cpp +++ b/source/network/NetLog.cpp @@ -994,17 +994,24 @@ void CNetLogger::GetStringDateTime( CStr &str ) { char buffer[ 128 ] = { 0 }; time_t tm; - struct tm now; + struct tm *now; +#if OS_WIN // Set timezone _tzset(); // Get time and convert to tm structure time( &tm ); - localtime_s( &now, &tm ); - + struct tm nowBuf; + localtime_s( &nowBuf, &tm ); + now = &nowBuf; +#else + time ( &tm ); + now = localtime( &tm ); +#endif + // Build custom time string - strftime( buffer, 128, "%Y-%m-%d %H:%M:%S", &now ); + strftime( buffer, 128, "%Y-%m-%d %H:%M:%S", now ); str = buffer; } @@ -1017,17 +1024,24 @@ void CNetLogger::GetStringTime( CStr& str ) { char buffer[ 128 ] = { 0 }; time_t tm; - struct tm now; + struct tm *now; +#if OS_WIN // Set timezone _tzset(); // Get time and convert to tm structure time( &tm ); - localtime_s( &now, &tm ); + struct tm nowBuf; + localtime_s( &nowBuf, &tm ); + now = &nowBuf; +#else + time ( &tm ); + now = localtime( &tm ); +#endif // Build custom time string - strftime( buffer, 128, "%H%M%S", &now ); + strftime( buffer, 128, "%H%M%S", now ); str = buffer; } diff --git a/source/network/SocketBase.cpp b/source/network/SocketBase.cpp index ec0886b904..736b136b84 100644 --- a/source/network/SocketBase.cpp +++ b/source/network/SocketBase.cpp @@ -126,7 +126,7 @@ PS_RESULT CSocketAddress::Resolve(const char *name, int port, CSocketAddress &ad CStr CSocketAddress::GetString() const { char convBuf[NI_MAXHOST]; - int res=getnameinfo((struct sockaddr *)&m_Union, sizeof(struct sockaddr), + int res=getnameinfo((struct sockaddr *)&m_Union, sizeof(struct sockaddr_in), convBuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (res == 0) return CStr(convBuf); @@ -420,7 +420,7 @@ PS_RESULT CSocketBase::Write(void *buf, uint len, uint *bytesWritten) PS_RESULT CSocketBase::Connect(const CSocketAddress &addr) { - int res = connect(m_pInternal->m_fd, (struct sockaddr *)(&addr.m_Union), sizeof(struct sockaddr)); + int res = connect(m_pInternal->m_fd, (struct sockaddr *)(&addr.m_Union), sizeof(struct sockaddr_in)); NET_LOG3("connect returned %d [%d]", res, m_NonBlocking); if (res != 0) @@ -455,7 +455,7 @@ PS_RESULT CSocketBase::Bind(const CSocketAddress &address) SetOpMask(READ); - res=bind(m_pInternal->m_fd, (struct sockaddr *)&address, sizeof(struct sockaddr)); + res=bind(m_pInternal->m_fd, (struct sockaddr *)&address, sizeof(struct sockaddr_in)); if (res == -1) { PS_RESULT ret=PS_FAIL; @@ -559,7 +559,7 @@ bool CSocketBase::ConnectError(CSocketBase *pSocket) { pSocket->m_State=SS_UNCONNECTED; PS_RESULT connErr=GetPS_RESULT(errno); - NET_LOG("Connect error: %s [%d:%s]", connErr, errno, strerror(errno)); + NET_LOG4("Connect error: %s [%d:%s]", connErr, errno, strerror(errno)); pSocket->m_Error=connErr; return true; } @@ -624,7 +624,7 @@ void CSocketBase::SocketReadable(CSocketBase *pSock) // success, nRead != 0 means alive stream socket if (res == -1 && errno != EINVAL) { - NET_LOG("RunWaitLoop:ioctl: Connection broken [%d:%s]", errno, strerror(errno)); + NET_LOG3("RunWaitLoop:ioctl: Connection broken [%d:%s]", errno, strerror(errno)); // Don't use API function - we both hold a lock and // it is unnecessary to SendWaitLoopUpdate at this // stage