From 7c37d6d01815edd88f9bf04720b0275d6ee296c2 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 11 Feb 2014 20:39:07 +0000 Subject: [PATCH] fixes issues for Linux compilation --- src/socket.cpp | 22 +++++++++++++--------- src/socket.h | 6 ++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/socket.cpp b/src/socket.cpp index eaa53137..095af9f9 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -57,7 +57,7 @@ void CSocket::Init ( const quint16 iPortNumber ) #ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD // preinitialize socket in address (only the port number is missing) - SOCKADDR_IN UdpSocketInAddr; + sockaddr_in UdpSocketInAddr; UdpSocketInAddr.sin_family = AF_INET; UdpSocketInAddr.sin_addr.s_addr = INADDR_ANY; @@ -67,8 +67,8 @@ void CSocket::Init ( const quint16 iPortNumber ) UdpSocketInAddr.sin_port = htons ( iPortNumber + iClientPortIncrement ); bSuccess = ( bind ( UdpSocket , - (SOCKADDR*) &UdpSocketInAddr, - sizeof ( SOCKADDR_IN ) ) == 0 ); + (sockaddr*) &UdpSocketInAddr, + sizeof ( sockaddr_in ) ) == 0 ); iClientPortIncrement++; } @@ -169,7 +169,7 @@ void CSocket::SendPacket ( const CVector& vecbySendBuf, // note that the client uses the socket directly for performance reasons if ( bIsClient ) { - SOCKADDR_IN UdpSocketOutAddr; + sockaddr_in UdpSocketOutAddr; UdpSocketOutAddr.sin_family = AF_INET; UdpSocketOutAddr.sin_port = htons ( HostAddr.iPort ); @@ -179,8 +179,8 @@ void CSocket::SendPacket ( const CVector& vecbySendBuf, (const char*) &( (CVector) vecbySendBuf )[0], iVecSizeOut, 0, - (SOCKADDR*) &UdpSocketOutAddr, - sizeof ( SOCKADDR_IN ) ); + (sockaddr*) &UdpSocketOutAddr, + sizeof ( sockaddr_in ) ); } else { @@ -219,14 +219,18 @@ void CSocket::OnDataReceived() { // read block from network interface and query address of sender #ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD - SOCKADDR_IN SenderAddr; - int SenderAddrSize = sizeof ( SOCKADDR_IN ); + sockaddr_in SenderAddr; +#ifdef _WIN32 + int SenderAddrSize = sizeof ( sockaddr_in ); +#else + socklen_t SenderAddrSize = sizeof ( sockaddr_in ); +#endif const long iNumBytesRead = recvfrom ( UdpSocket, (char*) &vecbyRecBuf[0], MAX_SIZE_BYTES_NETW_BUF, 0, - (SOCKADDR*) &SenderAddr, + (sockaddr*) &SenderAddr, &SenderAddrSize ); #else const int iNumBytesRead = diff --git a/src/socket.h b/src/socket.h index 94bc66a3..c9cde5ba 100755 --- a/src/socket.h +++ b/src/socket.h @@ -35,6 +35,12 @@ #include "global.h" #include "protocol.h" #include "util.h" +#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD +# ifndef _WIN32 +# include +# include +# endif +#endif // The header files channel.h and server.h require to include this header file // so we get a cyclic dependency. To solve this issue, a prototype of the